good first issue
Repository metrics
- Stars
- (254 stars)
- PR merge metrics
- (PR metrics pending)
Description
When trying to build a static lib for ARM targets involving thumb instructions, like Cortex-M0plus / Cortex-M33, ELD fails providing reason:
/work/obj/bin/ld.eld -m armelf -T link.ld --entry=main -static test.o main.o -o out_eld.elf
Error: applying relocation `51', conditional branch to PLT in THUMB-2 not supported yet
Error: Relocation error when applying relocation `R_ARM_THM_JUMP19' for symbol `plain_entry' referred from test.o[.text.caller] symbol defined in test.o[.text.target]
Reproductible example:
test.S
.arch armv8-m.main
.syntax unified
.thumb
@ section 1: caller
@ my_func is declared with .thumb_func, so its symbol value has LSB=1 (T=1).
@ It performs a conditional branch to plain_entry in a different section.
.section .text.caller, "ax", %progbits
.thumb_func
.global my_func
.type my_func, %function
my_func:
cmp r0, #0
beq plain_entry @ → R_ARM_THM_JUMP19, target T=0
movs r0, #1
bx lr
@section 2: target (plain label)
@ different section, so relocation generated
.section .text.target, "ax", %progbits
.global plain_entry
plain_entry:
movs r0, #0
bx lr
main.c
extern int my_func(int x);
int main(void) {
return my_func(1);
}
link.ld
MEMORY {
FLASH (rx) : ORIGIN = 0x10000000, LENGTH = 2M
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 256K
}
SECTIONS {
.text 0x10000000 : {
*(.text*)
} > FLASH
.data : { *(.data*) } > RAM AT > FLASH
.bss : { *(.bss*) *(COMMON) } > RAM
}
Commands:
clang --target=arm-none-eabi -mcpu=cortex-m0plus -mfloat-abi=soft -c test.S -o test.o
clang --target=arm-none-eabi -mcpu=cortex-m0plus -mfloat-abi=soft -c main.c -o main.o
ld.lld -m armelf -T link.ld --entry=main -static test.o main.o -o out_lld.elf # This does not fail
ld.eld -m armelf -T link.ld --entry=main -static test.o main.o -o out_eld.elf