llvm-project
llvm-project copied to clipboard
LLD incorrectly handles armeb targets
It seems like ld.lld
will accept armeb input files, but proceeds to handle the relocations in little-endian (?) and silently produces invalid encodings for branches:
$ clang --target=armebv5te-none-eabi -mcpu=arm926ej-s -c start.s
$ ld.lld -Ttext=0 start.o -o start.lld.elf
$ arm-none-eabi-ld -Ttext=0 -EB start.o -o start.gcc.elf
$ arm-none-eabi-objdump -d start.lld.elf start.gcc.elf
start.lld.elf: file format elf32-bigarm
Disassembly of section .text:
00000000 <_start>:
0: e1a00000 nop ; (mov r0, r0)
4: edffffeb ldcl 15, cr15, [pc, #940]! ; 3b8 <bar+0x3a4>
8: eeffffeb cdp 15, 15, cr15, cr15, cr11, {7}
0000000c <foo>:
c: e1a00000 nop ; (mov r0, r0)
10: e12fff1e bx lr
00000014 <bar>:
14: e1a00000 nop ; (mov r0, r0)
18: e12fff1e bx lr
start.gcc.elf: file format elf32-bigarm
Disassembly of section .text:
00000000 <_start>:
0: e1a00000 nop ; (mov r0, r0)
4: eb000000 bl c <foo>
8: eb000001 bl 14 <bar>
0000000c <foo>:
c: e1a00000 nop ; (mov r0, r0)
10: e12fff1e bx lr
00000014 <bar>:
14: e1a00000 nop ; (mov r0, r0)
18: e12fff1e bx lr
This seems similar to the behavior addressed in 7605a9a009b5fa3bdac07e3131c8d82f6d08feb7 for Aarch64 (see https://reviews.llvm.org/D96188)?
@llvm/issue-subscribers-lld-elf
LLD doesn't yet have support for big-endian. We are actually working on support for big-endian for LLD in Arm at the moment. We expect to have some patches to upstream shortly.
When LLD is invoked by the driver the emulation and --be8 are passed which LLD chokes on: ld.lld: error: unknown argument '--be8' ld.lld: error: unknown emulation: armelfb_linux_eabi
Problem seems to be when lld deduces the machine type. In any case my hope is that the forthcoming big endian support can resolve this problem.