summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2022-04-14 23:58:13 -0700
committerTom Stellard <tstellar@redhat.com>2022-05-20 04:08:06 -0700
commit5f66e721ec1d099cf2370235ce122cf47c287308 (patch)
treef129a5c7746247e9f7aa9ed2c46b16b0a715d9e6
parent3bfae7816bdb5b09930f073f1eb99f72015d9f78 (diff)
downloadllvm-5f66e721ec1d099cf2370235ce122cf47c287308.tar.gz
[ELF][ARM] Fix unneeded thunk for branches to hidden undefined weak
Similar to D123750 for AArch64. (cherry picked from commit b483ce12281e31311efacf0047f95767517dcde9)
-rw-r--r--lld/ELF/Arch/ARM.cpp8
-rw-r--r--lld/test/ELF/arm-undefined-weak.s8
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: <bl_undefweak2>
+// CHECK-NEXT: bl {{.*}} <bl_undefweak2+0x4>