Skip to content

runtime: support panic recovery on Xtensa - #5653

Open
jakebailey wants to merge 3 commits into
tinygo-org:devfrom
jakebailey:esp32-native-panic-unwind
Open

runtime: support panic recovery on Xtensa #5653
jakebailey wants to merge 3 commits into
tinygo-org:devfrom
jakebailey:esp32-native-panic-unwind

Conversation

@jakebailey

Copy link
Copy Markdown
Member

Now that picolibc is updated, we can now provide the right stuff to it to support native setjmp/longjmp unwinding on xtensa.

UART initialization runs before the scheduler has a current task.
Once.Do uses defer, which requires a current task when panic recovery
is enabled.

Use an interrupt-protected flag for this unicore initialization path
instead.
@soypat

soypat commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Hmm the sizediff CI job output is cut off- and I'm seeing no comment :s

Use picolibc setjmp and longjmp to save and restore the complete
Xtensa register-window state at TinyGo panic checkpoints.

Provide the target configuration and window spill helper required by
picolibc. Increment its cache version because Xtensa archives now
include another source file.
@jakebailey
jakebailey force-pushed the esp32-native-panic-unwind branch from a4c6319 to 5b3b715 Compare September 4, 2026 18:10
@jakebailey

Copy link
Copy Markdown
Member Author

Size difference with the dev branch:

Binary size difference
 flash                          ram
 before   after   diff          before   after   diff
  19684   19684      0   0.00%    7052    7052      0   0.00% tinygo build -size short -o ./build/test.hex -target=feather-rp2040 ./examples/adafruit4650
  63228   63228      0   0.00%    6788    6788      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adt7410/main.go
  10024   10024      0   0.00%    5348    5348      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/adxl345/main.go
  14628   14628      0   0.00%    7396    7396      0   0.00% tinygo build -size short -o ./build/test.hex -target=pybadge ./examples/amg88xx
  10184   10184      0   0.00%    5348    5348      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/main.go
  12592   12592      0   0.00%    7172    7172      0   0.00% tinygo build -size short -o ./build/test.hex -target=nano-33-ble ./examples/apds9960/proximity/main.go
  11136   11136      0   0.00%    5360    5360      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/apa102/itsybitsy-m0/main.go
   7588    7588      0   0.00%    2312    2312      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/at24cx/main.go
   9272    9272      0   0.00%    5340    5340      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bh1750/main.go
   8660    8660      0   0.00%    5340    5340      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/blinkm/main.go
  71408   71408      0   0.00%    3656    3656      0   0.00% tinygo build -size short -o ./build/test.hex -target=pinetime     ./examples/bma42x/main.go
  67120   67120      0   0.00%    6804    6804      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmi160/main.go
  28944   28944      0   0.00%    5380    5380      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp180/main.go
  65720   65720      0   0.00%    6828    6828      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/bmp280/main.go
  13080   13080      0   0.00%    5412    5412      0   0.00% tinygo build -size short -o ./build/test.hex -target=trinket-m0 ./examples/bmp388/main.go
  24024   24024      0   0.00%    6220    6220      0   0.00% tinygo build -size short -o ./build/test.hex -target=metro-rp2350 ./examples/bno08x/i2c/main.go
   8008    8008      0   0.00%    3344    3344      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/sram/main.go
  22116   22116      0   0.00%    3548    3548      0   0.00% tinygo build -size short -o ./build/test.hex -target=bluepill ./examples/ds1307/time/main.go
  30556   30556      0   0.00%    5576    5576      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/alarms/main.go
  44492   44492      0   0.00%    5576    5576      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/ds3231/basic/main.go
   4592    4592      0   0.00%    2272    2272      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/easystepper/main.go
  71884   71884      0   0.00%    7588    7588      0   0.00% tinygo build -size short -o ./build/test.hex -target=itsybitsy-m0 ./examples/flash/console/spi
  67996   67996      0   0.00%    9628    9628      0   0.00% tinygo build -size short -o ./build/test.hex -target=pyportal ./examples/flash/console/qspi
   7128    7128      0   0.00%    2276    2276      0   0.00% tinygo build -size short -o ./build/test.hex -target=microbit ./examples/gc9a01/main.go
 694064  694064      0   0.00%  131564  131564      0   0.00%

Hm, are there no xtensa size tests?

@soypat

soypat commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

No xtensa size tests, but I imagine the diff can't be THAT big... famous last words

edit: (would you mind adding one for esp32c3?)

@jakebailey

Copy link
Copy Markdown
Member Author

It turns out that the sizediff job's toolchain lacks xtensa support entirely; I think I can fix it, though perhaps I should make another PR for that and get it in first.

@soypat

soypat commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

That'd be pretty cool. If you do please tag me in that PR, I'm very interested in seeing what that job entails

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants