2026-04-23
Stack Overflow: View Question
Tags: linker, arm, embedded, cortex-m, position-independent-code
Score: 4 | Views: 187
The asker is building a custom operating system for the RP2040 (ARM Cortex-M0+) and compiling with position-independent code flags. After returning to the project following a multi-year hiatus, the toolchain now emits a linker error: dangerous relocation: unsupported relocation (R_ARM_SBREL32). The code compiled fine before; nothing in the source changed. This is a toolchain regression or behavioral change surfacing a latent issue.
This question is interesting for several reasons:
r9). GCC emits this when compiling with -msingle-pic-base or when the RWPI (Read-Write Position Independence) model is active. Newer GCC/Binutils versions may have changed how they emit or resolve these relocations for Thumb-only targets, which explains why the same flags broke after a toolchain update.The path toward a solution involves a few steps:
-fpic, -fpie, -msingle-pic-base, -mpic-register=r9, and -frwpi all influence which relocation types GCC emits. The asker should determine exactly which PIC model they need for their OS and use only that.arm-none-eabi-objdump -r stat.o will reveal exactly which relocations the compiler is emitting. Comparing this output between the old and new toolchain versions pinpoints what changed.-fpic with a proper linker script) or manually managing position independence through a custom loader may be more robust than RWPI, which has always had patchy support on Thumb-only targets.A key gotcha: even if you suppress this specific error, mixing RWPI and GOT-based relocations in the same binary can produce silently broken code. Every object file in the link must agree on the PIC model. Another edge case is that -msingle-pic-base assumes r9 is reserved and never clobbered, but some C library implementations or RTOS context-switch code may not preserve it.
