From b19a8f8545100a08ee2a64c05631aff6f651faa1 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Thu, 26 Mar 2015 08:22:08 -0700 Subject: [PATCH] Skip gc-sections if relocation is incompatible This patch skips gc-sections if input relocation is incompatible with output. bfd/ PR ld/18160 * elflink.c (elf_gc_sweep): Skip if relocation is incompatible. (bfd_elf_gc_sections): Likewise. ld/testsuite/ PR ld/18160 * ld-x86-64/pr18160.d: New file. * ld-x86-64/pr18160.s: Likewise. * ld-x86-64/pr18160.t: Likewise. * ld-x86-64/x86-64.exp: Run pr18160. --- bfd/ChangeLog | 6 ++++++ bfd/elflink.c | 6 ++++-- ld/testsuite/ChangeLog | 8 ++++++++ ld/testsuite/ld-x86-64/pr18160.d | 14 ++++++++++++++ ld/testsuite/ld-x86-64/pr18160.s | 16 ++++++++++++++++ ld/testsuite/ld-x86-64/pr18160.t | 8 ++++++++ ld/testsuite/ld-x86-64/x86-64.exp | 1 + 7 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 ld/testsuite/ld-x86-64/pr18160.d create mode 100644 ld/testsuite/ld-x86-64/pr18160.s create mode 100644 ld/testsuite/ld-x86-64/pr18160.t diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 014e30d4bdf..ae84f5f99e8 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2015-03-26 H.J. Lu + + PR ld/18160 + * elflink.c (elf_gc_sweep): Skip if relocation is incompatible. + (bfd_elf_gc_sections): Likewise. + 2015-03-25 Marcus Shawcroft * elfnn-aarch64.c (_bfd_aarch64_resize_stubs): Adjust stub section diff --git a/bfd/elflink.c b/bfd/elflink.c index 9ccad8c14cf..748ff1bc349 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -12159,7 +12159,8 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info) { asection *o; - if (bfd_get_flavour (sub) != bfd_target_elf_flavour) + if (bfd_get_flavour (sub) != bfd_target_elf_flavour + || !(*bed->relocs_compatible) (sub->xvec, abfd->xvec)) continue; for (o = sub->sections; o != NULL; o = o->next) @@ -12446,7 +12447,8 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info) { asection *o; - if (bfd_get_flavour (sub) != bfd_target_elf_flavour) + if (bfd_get_flavour (sub) != bfd_target_elf_flavour + || !(*bed->relocs_compatible) (sub->xvec, abfd->xvec)) continue; /* Start at sections marked with SEC_KEEP (ref _bfd_elf_gc_keep). diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index c4ce0661e5c..31e6ffce512 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2015-03-26 H.J. Lu + + PR ld/18160 + * ld-x86-64/pr18160.d: New file. + * ld-x86-64/pr18160.s: Likewise. + * ld-x86-64/pr18160.t: Likewise. + * ld-x86-64/x86-64.exp: Run pr18160. +--- 2015-03-25 Marcus Shawcroft * ld-aarch64/erratum835769.d: Adjust for initial branch over stub diff --git a/ld/testsuite/ld-x86-64/pr18160.d b/ld/testsuite/ld-x86-64/pr18160.d new file mode 100644 index 00000000000..b944bbe376a --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr18160.d @@ -0,0 +1,14 @@ +#as: --64 +#ld: --gc-sections -melf_x86_64 -T pr18160.t +#objdump: -dw + +.*: +file format elf32-i386 + + +Disassembly of section .text: + +0+ : +[ ]*[a-f0-9]+: e9 00 00 00 00 jmp 5 + +0+5 : +[ ]*[a-f0-9]+: c3 ret diff --git a/ld/testsuite/ld-x86-64/pr18160.s b/ld/testsuite/ld-x86-64/pr18160.s new file mode 100644 index 00000000000..a0331aa7933 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr18160.s @@ -0,0 +1,16 @@ + .section .text.start,"ax",@progbits + .globl start + .type start, @function +start: + .cfi_startproc + jmp foo + .cfi_endproc + .size start, .-start + .section .text.foo,"ax",@progbits + .globl foo + .type foo, @function +foo: + .cfi_startproc + ret + .cfi_endproc + .size foo, .-foo diff --git a/ld/testsuite/ld-x86-64/pr18160.t b/ld/testsuite/ld-x86-64/pr18160.t new file mode 100644 index 00000000000..d3906e39444 --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr18160.t @@ -0,0 +1,8 @@ +OUTPUT_FORMAT(elf32-i386) +ENTRY(start) +SECTIONS +{ + .text : { *(.text*) } + .data : { *(.data.*) } + .bss : { *(.bss.*) } +} diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp index 43427be5d78..7bceb7fe908 100644 --- a/ld/testsuite/ld-x86-64/x86-64.exp +++ b/ld/testsuite/ld-x86-64/x86-64.exp @@ -317,6 +317,7 @@ run_dump_test "mov1c" run_dump_test "mov1d" run_dump_test "pr17935-1" run_dump_test "pr17935-2" +run_dump_test "pr18160" # Must be native with the C compiler if { [isnative] && [which $CC] != 0 } { -- 2.30.2