Discarding ARM unwinding support from setjmp advice

Message ID AM0P195MB0595426D0BA3C801BE734A65F77BA@AM0P195MB0595.EURP195.PROD.OUTLOOK.COM
State New
Headers
Series Discarding ARM unwinding support from setjmp advice |

Commit Message

Marco Satti March 7, 2026, 3:44 p.m. UTC
  Hi,

I am trying to build a size-optimized baremetal firmware for a microcontroller based on ARM Cortex-M4. 
Upon using the setjmp/longjmp functions, I noticed unwinding support was being linked in where it wasn't previously. 
As unwinding is not used, this amounts to ~4KiB of dead code.

Debugging the issue leads to setjmp.o, where the following symbol is causing unwinding to be linked in:
00000000         *UND*  00000000 __aeabi_unwind_cpp_pr0

Modifying setjmp.S as follows fixes the issue, as the symbol is no longer referenced:


This idea was obtained by inspecting similar files within the same directory, such as memchr.S. 
These files already contain the .cantunwind directive, and do not pull in unwinding support when linked in.

Is this a valid patch to submit, or should other methods be used (eg: via linker script and/or options)?

I am not overly familiar with the directive and implications, so hoping someone can provide advice.

Thanks, Marco.
  

Patch

diff --git a/newlib/libc/machine/arm/setjmp.S b/newlib/libc/machine/arm/setjmp.S
index a53f7918e..1b8329f0b 100644
--- a/newlib/libc/machine/arm/setjmp.S
+++ b/newlib/libc/machine/arm/setjmp.S
@@ -193,6 +193,7 @@  SYM (\name):
 .macro FUNC_END name
        RET
        .cfi_endproc
+       .cantunwind
        .fnend
        SIZE (\name)
 .endm