[lld][Hexagon] Test undefined weak branches (#186613)

Undefined weak branches do not needsThunk().

Add a test case to cover undef weak.
This commit is contained in:
Brian Cain 2026-03-25 09:03:35 -06:00 committed by GitHub
parent 1dc5b0c8f3
commit 51c3f971a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View File

@ -370,7 +370,10 @@ bool Hexagon::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {
bool Hexagon::needsThunk(RelExpr expr, RelType type, const InputFile *file,
uint64_t branchAddr, const Symbol &s,
int64_t a) const {
// Only check branch range for supported branch relocation types
// Undefined weak symbols without PLT entries resolve to address zero.
// Thunks are not needed since the branch target is fixed.
if (s.isUndefined() && !s.isInPlt(ctx))
return false;
switch (type) {
case R_HEX_B22_PCREL:
case R_HEX_PLT_B22_PCREL:

View File

@ -0,0 +1,28 @@
# REQUIRES: hexagon
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o
# RUN: ld.lld %t.o -o %t
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
## Undefined weak branch targets resolve to address zero. Verify that
## no thunks are created and that branches encode without error.
.weak undefined_weak
.globl _start
.type _start, @function
_start:
## Simple call -- single-word packet.
call undefined_weak
## Call in a two-word packet with an ALU op.
{ r0 = #0
call undefined_weak }
jumpr r31
## All branches target address zero.
# CHECK: <_start>:
# CHECK-NEXT: { call 0x0 <undefined_weak> }
# CHECK-NEXT: { call 0x0 <undefined_weak>
# CHECK-NEXT: r0 = #0x0 }
# CHECK-NEXT: { jumpr r31 }
# CHECK-NOT: __hexagon_thunk