Skip to content

Commit a77ccc8

Browse files
author
Christophe Lyon
committed
arm: Handle undefweak with ST_BRANCH_UNKNOWN
A previous patch made ld fail early on Thumb-only where branch_type is ST_BRANCH_UNKNOWN. However, this fails erroneously when the target is undefweak: in that case the branch should be replaced by a branch to the next instruction (or nop.w on thumb2). This patch accepts this case and restores the previous behaviour in such cases. This was reported by failures in the GCC testsuite, where we fail to link executables because __deregister_frame_info is undefweak: (__deregister_frame_info): Unknown destination type (ARM/Thumb) in ...crtbegin.o crtbegin.o: in function `__do_global_dtors_aux': crtstuff.c:(.text+0x52): dangerous relocation: unsupported relocation
1 parent 1628e02 commit a77ccc8

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

bfd/elf32-arm.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10512,7 +10512,12 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto,
1051210512
if (using_thumb_only (globals)
1051310513
&& (r_type == R_ARM_THM_CALL
1051410514
|| r_type == R_ARM_THM_JUMP24)
10515-
&& branch_type == ST_BRANCH_UNKNOWN)
10515+
&& branch_type == ST_BRANCH_UNKNOWN
10516+
/* Exception to the rule above: a branch to an undefined weak
10517+
symbol is turned into a jump to the next instruction unless a
10518+
PLT entry will be created (see below). */
10519+
&& !(h && h->root.type == bfd_link_hash_undefweak
10520+
&& plt_offset == (bfd_vma) -1))
1051610521
{
1051710522
if (sym_sec != NULL
1051810523
&& sym_sec->owner != NULL)

ld/testsuite/ld-arm/arm-elf.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,7 @@ run_dump_test "attr-merge-wchar-42-nowarn"
12081208
run_dump_test "attr-merge-wchar-44-nowarn"
12091209
run_dump_test "farcall-section"
12101210
run_dump_test "farcall-missing-type"
1211+
run_dump_test "farcall-missing-type-undefweak"
12111212
run_dump_test "attr-merge-unknown-1"
12121213
run_dump_test "attr-merge-unknown-2"
12131214
run_dump_test "attr-merge-unknown-2r"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.thumb
2+
.cpu cortex-m33
3+
.syntax unified
4+
.global __start
5+
.weak bad
6+
.type __start, function
7+
__start:
8+
push {r4, lr}
9+
bl bad
10+
pop {r4, pc}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#source: farcall-missing-type-main-undefweak.s
2+
#as:
3+
#ld:-T farcall-missing-type.ld
4+
#objdump: -dr
5+
#...
6+
Disassembly of section .text:
7+
8+
.* <__start>:
9+
+[0-9a-f]+: .... .... push {r4, lr}
10+
+[0-9a-f]+: .... .... nop.w
11+
+[0-9a-f]+: .... .... pop {r4, pc}

0 commit comments

Comments
 (0)