This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[PATCH] PR ld/18160: Segmentation Fault in lang_gc_sections when linking elf_x86_64 output
- From: "H.J. Lu" <hjl dot tools at gmail dot com>
- To: binutils at sourceware dot org
- Date: Wed, 25 Mar 2015 16:21:14 -0700
- Subject: [PATCH] PR ld/18160: Segmentation Fault in lang_gc_sections when linking elf_x86_64 output
- Authentication-results: sourceware.org; auth=none
This patch ignores gc-sections if input relocation is incompatible with
output. OK for master?
Thanks.
H.J.
--
bfd/
PR ld/18160
* elflink.c (bfd_elf_gc_sections): Ignore gc-sections 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..4fa5520 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -12414,6 +12414,13 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
asection *sec;
struct elf_reloc_cookie cookie;
+ if (!(*bed->relocs_compatible) (sub->xvec, abfd->xvec))
+ {
+ (*_bfd_error_handler)(_("Warning: incompatible relocation in `%B'. gc-sections option ignored"),
+ sub);
+ return TRUE;
+ }
+
sec = bfd_get_section_by_name (sub, ".eh_frame");
while (sec && init_reloc_cookie_for_section (&cookie, info, sec))
{
diff --git a/ld/testsuite/ld-x86-64/pr18160.d b/ld/testsuite/ld-x86-64/pr18160.d
new file mode 100644
index 0000000..b0f8c5a
--- /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: .* gc-sections option ignored
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