[lld] b483ce1 - [ELF][ARM] Fix unneeded thunk for branches to hidden undefined weak
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 14 23:58:19 PDT 2022
Author: Fangrui Song
Date: 2022-04-14T23:58:13-07:00
New Revision: b483ce12281e31311efacf0047f95767517dcde9
URL: https://github.com/llvm/llvm-project/commit/b483ce12281e31311efacf0047f95767517dcde9
DIFF: https://github.com/llvm/llvm-project/commit/b483ce12281e31311efacf0047f95767517dcde9.diff
LOG: [ELF][ARM] Fix unneeded thunk for branches to hidden undefined weak
Similar to D123750 for AArch64.
Added:
Modified:
lld/ELF/Arch/ARM.cpp
lld/test/ELF/arm-undefined-weak.s
Removed:
################################################################################
diff --git a/lld/ELF/Arch/ARM.cpp b/lld/ELF/Arch/ARM.cpp
index 6e2932f101663..425c45884330f 100644
--- a/lld/ELF/Arch/ARM.cpp
+++ b/lld/ELF/Arch/ARM.cpp
@@ -294,9 +294,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 8e4ccff7b6c42..e508291816975 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: <bl_undefweak2>
+// CHECK-NEXT: bl {{.*}} <bl_undefweak2+0x4>
More information about the llvm-commits
mailing list