From 5bea4ddc7d50c262ad1b85f101f960eb6a9dc98d Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 25 Mar 2015 16:15:02 -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. 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/elflink.c | 7 +++++++ ld/testsuite/ld-x86-64/pr18160.d | 3 +++ 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 + 5 files changed, 35 insertions(+) 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/elflink.c b/bfd/elflink.c index 9ccad8c..855d120 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -12162,6 +12162,13 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info) if (bfd_get_flavour (sub) != bfd_target_elf_flavour) continue; + if (!(*bed->relocs_compatible) (sub->xvec, abfd->xvec)) + { + (*_bfd_error_handler)(_("Warning: skip gc-sections: incompatible relocation in `%B'"), + sub); + continue; + } + for (o = sub->sections; o != NULL; o = o->next) { /* When any section in a section group is kept, we keep all diff --git a/ld/testsuite/ld-x86-64/pr18160.d b/ld/testsuite/ld-x86-64/pr18160.d new file mode 100644 index 0000000..13af30c --- /dev/null +++ b/ld/testsuite/ld-x86-64/pr18160.d @@ -0,0 +1,3 @@ +#as: --64 +#ld: --gc-sections -melf_x86_64 -T pr18160.t +#warning: .* skip gc-sections: incompatible relocation in `tmpdir/dump0.o' diff --git a/ld/testsuite/ld-x86-64/pr18160.s b/ld/testsuite/ld-x86-64/pr18160.s new file mode 100644 index 0000000..a0331aa --- /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 0000000..d3906e3 --- /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 43427be..7bceb7f 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.1.0