Unsupported relocation emitted by LLVM


I'm trying to compile bare-metal relocatable binaries for Thumb using
the RWPI/ROPI relocation models in the recently released version 4. The
code is coming out great from clang as well as Rust (anecdotally, so far
it behaves nicer overall than GCC's -msingle-pic-base in my minimal

However, I'm unable to link this code since both GNU LD and LLD are
missing support for the ARM relocation type R_ARM_SBREL32 (relocation
type 9 in
Documentation – Arm Developer)
which is emitted by LLVM for the RWPI relocation model.

I believe the relevant function in LLD is here:

I'm attaching a very simple file, `test.c`, which simply dereferences a
global volatile int in `_start`. Compiling it without RWPI relocations
works as expected:

$ clang --target=thumbv7-eabi -fropi -o test.o -c test.c
$ ld.lld -o test test.o

However, compiling with RWPI turned on errors with `unrecognized reloc
9` from LLD:

$ clang --target=thumbv7-eabi -fropi -frwpi -o test.o -c test.c
$ ld.lld -o test test.o
ld.lld: error: test.c:(function _start): unrecognized reloc 9

and a similar error from GNU LD:

$ clang --target=thumbv7-eabi -fropi -frwpi -o test.o -c test.c
$ ld.lld -o test test.o
test.o: In function `_start':
test.c:(.text+0x28): dangerous relocation: unsupported relocation

As far as I can tell, the linker doesn't _actually_ need to do anything
for this relocation, either. I'm not sure if that might mean there is
away to work around this in the interim.


test.c (100 Bytes)