[llvm-dev] Fwd: Unsupported relocation emitted by LLVM

Amit Levy via llvm-dev llvm-dev at lists.llvm.org
Wed May 3 07:46:43 PDT 2017


Hi,

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
experiments).

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
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf)
which is emitted by LLVM for the RWPI relocation model.

I believe the relevant function in LLD is here:
https://github.com/llvm-mirror/lld/blob/f78635b8b05285750ef76b56e3b696cb34a0c49b/ELF/Target.cpp#L1856

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.

Thanks!
Amit


-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.c
Type: text/x-csrc
Size: 100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170503/d56c82ff/attachment.c>


More information about the llvm-dev mailing list