[llvm-branch-commits] [lld] 5f66e72 - [ELF][ARM] Fix unneeded thunk for branches to hidden undefined weak

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri May 20 04:08:29 PDT 2022


Author: Fangrui Song
Date: 2022-05-20T04:08:06-07:00
New Revision: 5f66e721ec1d099cf2370235ce122cf47c287308

URL: https://github.com/llvm/llvm-project/commit/5f66e721ec1d099cf2370235ce122cf47c287308
DIFF: https://github.com/llvm/llvm-project/commit/5f66e721ec1d099cf2370235ce122cf47c287308.diff

LOG: [ELF][ARM] Fix unneeded thunk for branches to hidden undefined weak

Similar to D123750 for AArch64.

(cherry picked from commit b483ce12281e31311efacf0047f95767517dcde9)

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 b7c2eb74757cf..b6b32f0500a4d 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 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-branch-commits mailing list