From 1954000798df4fa1571ee51994105b75f31959d1 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 25 Nov 2008 15:53:27 +0000 Subject: [PATCH] bfd: * elf32-arm.c (elf32_arm_final_link_relocate): Do not turn branches to undefine weak symbols into branches to the next instruction if creating PLT entries for those symbols. ld/testsuite: * ld-arm/thumb2-bl-undefweak.d, ld-arm/thumb2-bl-undefweak.s: New. * ld-arm/arm-elf.exp: Run thumb2-bl-undefweak test. --- bfd/ChangeLog | 6 ++++++ bfd/elf32-arm.c | 5 +++-- ld/testsuite/ChangeLog | 5 +++++ ld/testsuite/ld-arm/arm-elf.exp | 1 + ld/testsuite/ld-arm/thumb2-bl-undefweak.d | 9 +++++++++ ld/testsuite/ld-arm/thumb2-bl-undefweak.s | 10 ++++++++++ 6 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-arm/thumb2-bl-undefweak.d create mode 100644 ld/testsuite/ld-arm/thumb2-bl-undefweak.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 8f01ddf13a9..ea1742338c0 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2008-11-25 Joseph Myers + + * elf32-arm.c (elf32_arm_final_link_relocate): Do not turn + branches to undefine weak symbols into branches to the next + instruction if creating PLT entries for those symbols. + 2008-11-25 Nick Clifton * elflink.c (is_reloc_section): New function. Returns true if the diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 5b78dc3dfdd..cd5a9bfc071 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -6360,8 +6360,9 @@ elf32_arm_final_link_relocate (reloc_howto_type * howto, int thumb2 = using_thumb2 (globals); /* A branch to an undefined weak symbol is turned into a jump to - the next instruction. */ - if (h && h->root.type == bfd_link_hash_undefweak) + the next instruction unless a PLT entry will be created. */ + if (h && h->root.type == bfd_link_hash_undefweak + && !(splt != NULL && h->plt.offset != (bfd_vma) -1)) { bfd_put_16 (input_bfd, 0xe000, hit_data); bfd_put_16 (input_bfd, 0xbf00, hit_data + 2); diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index f46a7e134a9..7157245a246 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-11-25 Joseph Myers + + * ld-arm/thumb2-bl-undefweak.d, ld-arm/thumb2-bl-undefweak.s: New. + * ld-arm/arm-elf.exp: Run thumb2-bl-undefweak test. + 2008-11-25 Hans-Peter Nilsson * ld-cris/got7.s, ld-cris/init.s, ld-cris/pic-gc-72.d, diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp index 6075e68d357..665dab19d4a 100644 --- a/ld/testsuite/ld-arm/arm-elf.exp +++ b/ld/testsuite/ld-arm/arm-elf.exp @@ -184,6 +184,7 @@ run_dump_test "group-relocs-alu-bad" run_dump_test "group-relocs-ldr-bad" run_dump_test "group-relocs-ldrs-bad" run_dump_test "group-relocs-ldc-bad" +run_dump_test "thumb2-bl-undefweak" run_dump_test "emit-relocs1" # Exclude non-ARM-EABI targets. diff --git a/ld/testsuite/ld-arm/thumb2-bl-undefweak.d b/ld/testsuite/ld-arm/thumb2-bl-undefweak.d new file mode 100644 index 00000000000..d06f1ab1aac --- /dev/null +++ b/ld/testsuite/ld-arm/thumb2-bl-undefweak.d @@ -0,0 +1,9 @@ +#source: thumb2-bl-undefweak.s +#as: +#ld: -shared +#objdump: -dr +#... +Disassembly of section .text: + +.* : + .*: .... .... blx ... diff --git a/ld/testsuite/ld-arm/thumb2-bl-undefweak.s b/ld/testsuite/ld-arm/thumb2-bl-undefweak.s new file mode 100644 index 00000000000..5e70eead407 --- /dev/null +++ b/ld/testsuite/ld-arm/thumb2-bl-undefweak.s @@ -0,0 +1,10 @@ +@ Test that calls to undefined weak functions resolve to call through +@ the PLT in shared libraries. + + .arch armv7 + .syntax unified + .text + .thumb_func +foo: + bl bar + .weak bar -- 2.30.2