From 5f66e721ec1d099cf2370235ce122cf47c287308 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 14 Apr 2022 23:58:13 -0700 Subject: [ELF][ARM] Fix unneeded thunk for branches to hidden undefined weak Similar to D123750 for AArch64. (cherry picked from commit b483ce12281e31311efacf0047f95767517dcde9) --- lld/ELF/Arch/ARM.cpp | 8 +++++--- lld/test/ELF/arm-undefined-weak.s | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp index b7c2eb74757c..b6b32f0500a4 100644 --- a/lld/ELF/Arch/ARM.cpp +++ b/lld/ELF/Arch/ARM.cpp @@ -296,9 +296,11 @@ void ARM::addPltSymbols(InputSection &isec, uint64_t off) const { bool ARM::needsThunk(RelExpr expr, RelType type, const InputFile *file, uint64_t branchAddr, const Symbol &s, int64_t a) const { - // If S is an undefined weak symbol and does not have a PLT entry then it - // will be resolved as a branch to the next instruction. - if (s.isUndefWeak() && !s.isInPlt()) + // If s is an undefined weak symbol and does not have a PLT entry then it will + // be resolved as a branch to the next instruction. If it is hidden, its + // binding has been converted to local, so we just check isUndefined() here. A + // undefined non-weak symbol will have been errored. + if (s.isUndefined() && !s.isInPlt()) return false; // A state change from ARM to Thumb and vice versa must go through an // interworking thunk if the relocation type is not R_ARM_CALL or diff --git a/lld/test/ELF/arm-undefined-weak.s b/lld/test/ELF/arm-undefined-weak.s index 8e4ccff7b6c4..e50829181697 100644 --- a/lld/test/ELF/arm-undefined-weak.s +++ b/lld/test/ELF/arm-undefined-weak.s @@ -13,6 +13,9 @@ .weak target .type target, %function + .weak undefweak2 + .hidden undefweak2 + .type undefweak2, %function .text .global _start @@ -30,6 +33,9 @@ _start: /// R_ARM_REL32 .word target - . +bl_undefweak2: + bl undefweak2 + // CHECK: Disassembly of section .text: // CHECK-EMPTY: // CHECK-NEXT: 100100b4 <_start>: @@ -39,3 +45,5 @@ _start: // CHECK-NEXT: 100100c0: movt r0, #0 // CHECK-NEXT: 100100c4: movw r0, #0 // CHECK: 100100c8: 00 00 00 00 .word 0x00000000 +// CHECK-LABEL: +// CHECK-NEXT: bl {{.*}} -- cgit v1.2.1