Skip to content

Commit 5f66e72

Browse files
MaskRaytstellar
authored andcommitted
[ELF][ARM] Fix unneeded thunk for branches to hidden undefined weak
Similar to D123750 for AArch64. (cherry picked from commit b483ce1)
1 parent 3bfae78 commit 5f66e72

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lld/ELF/Arch/ARM.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ void ARM::addPltSymbols(InputSection &isec, uint64_t off) const {
296296
bool ARM::needsThunk(RelExpr expr, RelType type, const InputFile *file,
297297
uint64_t branchAddr, const Symbol &s,
298298
int64_t a) const {
299-
// If S is an undefined weak symbol and does not have a PLT entry then it
300-
// will be resolved as a branch to the next instruction.
301-
if (s.isUndefWeak() && !s.isInPlt())
299+
// If s is an undefined weak symbol and does not have a PLT entry then it will
300+
// be resolved as a branch to the next instruction. If it is hidden, its
301+
// binding has been converted to local, so we just check isUndefined() here. A
302+
// undefined non-weak symbol will have been errored.
303+
if (s.isUndefined() && !s.isInPlt())
302304
return false;
303305
// A state change from ARM to Thumb and vice versa must go through an
304306
// interworking thunk if the relocation type is not R_ARM_CALL or

lld/test/ELF/arm-undefined-weak.s

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
.weak target
1515
.type target, %function
16+
.weak undefweak2
17+
.hidden undefweak2
18+
.type undefweak2, %function
1619

1720
.text
1821
.global _start
@@ -30,6 +33,9 @@ _start:
3033
/// R_ARM_REL32
3134
.word target - .
3235

36+
bl_undefweak2:
37+
bl undefweak2
38+
3339
// CHECK: Disassembly of section .text:
3440
// CHECK-EMPTY:
3541
// CHECK-NEXT: 100100b4 <_start>:
@@ -39,3 +45,5 @@ _start:
3945
// CHECK-NEXT: 100100c0: movt r0, #0
4046
// CHECK-NEXT: 100100c4: movw r0, #0
4147
// CHECK: 100100c8: 00 00 00 00 .word 0x00000000
48+
// CHECK-LABEL: <bl_undefweak2>
49+
// CHECK-NEXT: bl {{.*}} <bl_undefweak2+0x4>

0 commit comments

Comments
 (0)