dangerous relocation: unsupported relocation (R_ARM_SBREL32)

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:

The path toward a solution involves a few steps:

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.

The challenge: A toolchain update silently changed how GCC emits position-independent relocations for Cortex-M0+, breaking a formerly working OS build and exposing the fragility of PIC on Thumb-only ARM targets.

All newsletters