llvm-project/lld/test/ELF/hexagon-thunks.s
Brian Cain ba228181c2
[lld][Hexagon] Fix out-of-range PLT branch thunks (#186545)
Linking large Hexagon binaries (e.g. ASan runtime with >8 MiB of text)
fails with R_HEX_B22_PCREL / R_HEX_PLT_B22_PCREL relocation overflow on
calls to PLT entries, even though the thunk infrastructure exists and
needsThunks is set.

needsThunk() always used s.getVA() to compute the branch destination,
even for PLT calls where the actual destination is the PLT entry. This
meant the distance check used the wrong address and failed to create
thunks when the PLT entry was out of B22_PCREL range.

Fix by using s.getPltVA() when expr == R_PLT_PC. Also override
getThunkSectionSpacing() so ThunkSections are pre-created at appropriate
intervals for large binaries.
2026-03-30 14:06:47 -05:00

52 lines
1.5 KiB
ArmAsm

# REQUIRES: hexagon
# RUN: rm -rf %t && split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %t/a.s -o %t/a.o
# RUN: ld.lld -T %t/lds %t/a.o -o %t/a
# RUN: llvm-objdump -d --no-show-raw-insn %t/a 2>&1 | \
# RUN: FileCheck --check-prefixes=CHECK-NONPIC,CHECK %s
# RUN: llvm-mc -filetype=obj \
# RUN: -triple=hexagon-unknown-elf %t/a.s -o %t/a.o
# RUN: ld.lld -T %t/lds --pie %t/a.o -o %t/a
# RUN: llvm-objdump -d --no-show-raw-insn %t/a 2>&1 | \
# RUN: FileCheck --check-prefixes=CHECK-PIC,CHECK %s
#--- a.s
.section .text_low, "ax", %progbits
.globl main
.type main, @function
main:
call myfn
jumpr r31
.size main, .-main
.section .text_high, "ax", %progbits
.globl myfn
.type myfn, @function
myfn:
jumpr r31
.size myfn, .-myfn
# CHECK: Disassembly of section .text_low:
# CHECK: <main>:
# CHECK-NEXT: 200b4: { call 0x200bc <__hexagon_thunk_myfn_from_.text.thunk> }
# CHECK-NEXT: { jumpr r31 }
# CHECK: <__hexagon_thunk_myfn_from_.text.thunk>:
# CHECK-NONPIC-NEXT: 200bc: { immext(#0x1000000)
# CHECK-NONPIC-NEXT: jump 0x10200bc <myfn> }
# CHECK-PIC-NEXT: 200bc: { immext(#0x1000000)
# CHECK-PIC-NEXT: r14 = add(pc,##0x1000000) }
# CHECK-PIC-NEXT: { jumpr r14 }
# CHECK: Disassembly of section .text_high:
# CHECK: <myfn>:
# CHECK-NEXT: 10200bc: { jumpr r31 }
#--- lds
SECTIONS {
.text_low 0x200b4: { *(.text_low) }
.text_high 0x10200bc : { *(.text_high) }
}