diff options
author | Cary Coutant <ccoutant@gmail.com> | 2018-04-02 16:12:10 -0700 |
---|---|---|
committer | Cary Coutant <ccoutant@gmail.com> | 2018-04-02 19:07:04 -0700 |
commit | bce5a025d2ed7eda2c5bbb85bd9b33333ca5d556 (patch) | |
tree | 92912c522de8e45805825292a4a94e50f753584c /gold/testsuite | |
parent | 8849a5e9edda5f00d727490c7bb8be3c616742ae (diff) | |
download | gdb-bce5a025d2ed7eda2c5bbb85bd9b33333ca5d556.zip gdb-bce5a025d2ed7eda2c5bbb85bd9b33333ca5d556.tar.gz gdb-bce5a025d2ed7eda2c5bbb85bd9b33333ca5d556.tar.bz2 |
Fix problem where mixed section types can cause internal error during a -r link.
During a -r (or --emit-relocs) link, if two sections had the same name but
different section types, gold would put relocations for both sections into
the same relocation section even though the data sections remained separate.
For .eh_frame sections, when one section is PROGBITS and another is
X86_64_UNWIND, we really should be using the UNWIND section type and
combining the sections anyway. For other sections, we should be
creating one relocation section for each output data section.
gold/
PR gold/23016
* incremental.cc (can_incremental_update): Check for unwind section
type.
* layout.h (Layout::layout): Add sh_type parameter.
* layout.cc (Layout::layout): Likewise.
(Layout::layout_reloc): Create new output reloc section if data
section does not already have one.
(Layout::layout_eh_frame): Check for unwind section type.
(Layout::make_eh_frame_section): Use unwind section type for .eh_frame
and .eh_frame_hdr.
* object.h (Sized_relobj_file::Shdr_write): New typedef.
(Sized_relobj_file::layout_section): Add sh_type parameter.
(Sized_relobj_file::Deferred_layout::Deferred_layout): Add sh_type
parameter.
* object.cc (Sized_relobj_file::check_eh_frame_flags): Check for
unwind section type.
(Sized_relobj_file::layout_section): Add sh_type parameter; pass it
to Layout::layout.
(Sized_relobj_file::do_layout): Make local copy of sh_type.
Force .eh_frame sections to unwind section type.
Pass sh_type to layout_section.
(Sized_relobj_file<size, big_endian>::do_layout_deferred_sections):
Pass sh_type to layout_section.
* output.cc (Output_section::Output_section): Initialize reloc_section_.
* output.h (Output_section::reloc_section): New method.
(Output_section::set_reloc_section): New method.
(Output_section::reloc_section_): New data member.
* target.h (Target::unwind_section_type): New method.
(Target::Target_info::unwind_section_type): New data member.
* aarch64.cc (aarch64_info): Add unwind_section_type.
* arm.cc (arm_info, arm_nacl_info): Likewise.
* i386.cc (i386_info, i386_nacl_info, iamcu_info): Likewise.
* mips.cc (mips_info, mips_nacl_info): Likewise.
* powerpc.cc (powerpc_info): Likewise.
* s390.cc (s390_info): Likewise.
* sparc.cc (sparc_info): Likewise.
* tilegx.cc (tilegx_info): Likewise.
* x86_64.cc (x86_64_info, x86_64_nacl_info): Likewise.
* testsuite/Makefile.am (pr23016_1, pr23016_2): New test cases.
* testsuite/Makefile.in: Regenerate.
* testsuite/testfile.cc: Add unwind_section_type.
* testsuite/pr23016_1.sh: New test script.
* testsuite/pr23016_1a.s: New source file.
* testsuite/pr23016_1b.s: New source file.
* testsuite/pr23016_2.sh: New test script.
* testsuite/pr23016_2a.s: New source file.
* testsuite/pr23016_2b.s: New source file.
Diffstat (limited to 'gold/testsuite')
-rw-r--r-- | gold/testsuite/Makefile.am | 26 | ||||
-rw-r--r-- | gold/testsuite/Makefile.in | 33 | ||||
-rwxr-xr-x | gold/testsuite/pr23016_1.sh | 87 | ||||
-rw-r--r-- | gold/testsuite/pr23016_1a.s | 3 | ||||
-rw-r--r-- | gold/testsuite/pr23016_1b.s | 3 | ||||
-rwxr-xr-x | gold/testsuite/pr23016_2.sh | 57 | ||||
-rw-r--r-- | gold/testsuite/pr23016_2a.s | 3 | ||||
-rw-r--r-- | gold/testsuite/pr23016_2b.s | 3 | ||||
-rw-r--r-- | gold/testsuite/testfile.cc | 1 |
9 files changed, 214 insertions, 2 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index cf0b970..7140df6 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -1211,6 +1211,32 @@ x32_overflow_pc32.err: x32_overflow_pc32.o gcctestdir/ld exit 1; \ fi +check_SCRIPTS += pr23016_1.sh +check_DATA += pr23016_1.stdout pr23016_1r.stdout +pr23016_1.stdout: pr23016_1.o + $(TEST_READELF) -rSW $< >$@ 2>/dev/null +pr23016_1.o: pr23016_1a.o pr23016_1b.o gcctestdir/ld + gcctestdir/ld -r -o $@ pr23016_1a.o pr23016_1b.o +pr23016_1r.stdout: pr23016_1r.o + $(TEST_READELF) -rSW $< >$@ 2>/dev/null +pr23016_1r.o: pr23016_1a.o pr23016_1b.o gcctestdir/ld + gcctestdir/ld -r -o $@ pr23016_1b.o pr23016_1a.o +pr23016_1a.o: pr23016_1a.s + $(TEST_AS) -o $@ $< +pr23016_1b.o: pr23016_1b.s + $(TEST_AS) -o $@ $< + +check_SCRIPTS += pr23016_2.sh +check_DATA += pr23016_2.stdout +pr23016_2.stdout: pr23016_2.o + $(TEST_READELF) -rW $< >$@ 2>/dev/null +pr23016_2.o: pr23016_2a.o pr23016_2b.o gcctestdir/ld + gcctestdir/ld -r -o $@ pr23016_2a.o pr23016_2b.o +pr23016_2a.o: pr23016_2a.s + $(TEST_AS) -o $@ $< +pr23016_2b.o: pr23016_2b.s + $(TEST_AS) -o $@ $< + endif DEFAULT_TARGET_X86_64 if DEFAULT_TARGET_X86_64_OR_X32 diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 3bddc12..48e5b9e 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -252,7 +252,9 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_29 = x86_64_mov_to_lea.sh \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_indirect_call_to_direct.sh \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_overflow_pc32.sh \ -@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_overflow_pc32.sh +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_overflow_pc32.sh \ +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_1.sh \ +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_2.sh @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_30 = x86_64_mov_to_lea1.stdout \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea2.stdout \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea3.stdout \ @@ -270,7 +272,10 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_indirect_call_to_direct1.stdout \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_indirect_jump_to_direct1.stdout \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_overflow_pc32.err \ -@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_overflow_pc32.err +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x32_overflow_pc32.err \ +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_1.stdout \ +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_1r.stdout \ +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr23016_2.stdout @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_31 = x86_64_mov_to_lea1 \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea2 \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ x86_64_mov_to_lea3 \ @@ -5269,6 +5274,10 @@ x86_64_overflow_pc32.sh.log: x86_64_overflow_pc32.sh @p='x86_64_overflow_pc32.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) x32_overflow_pc32.sh.log: x32_overflow_pc32.sh @p='x32_overflow_pc32.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +pr23016_1.sh.log: pr23016_1.sh + @p='pr23016_1.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +pr23016_2.sh.log: pr23016_2.sh + @p='pr23016_2.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) i386_mov_to_lea.sh.log: i386_mov_to_lea.sh @p='i386_mov_to_lea.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) file_in_many_sections_test.sh.log: file_in_many_sections_test.sh @@ -6489,6 +6498,26 @@ uninstall-am: @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ rm -f $@; \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ exit 1; \ @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ fi +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_1.stdout: pr23016_1.o +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -rSW $< >$@ 2>/dev/null +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_1.o: pr23016_1a.o pr23016_1b.o gcctestdir/ld +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -r -o $@ pr23016_1a.o pr23016_1b.o +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_1r.stdout: pr23016_1r.o +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -rSW $< >$@ 2>/dev/null +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_1r.o: pr23016_1a.o pr23016_1b.o gcctestdir/ld +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -r -o $@ pr23016_1b.o pr23016_1a.o +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_1a.o: pr23016_1a.s +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) -o $@ $< +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_1b.o: pr23016_1b.s +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) -o $@ $< +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_2.stdout: pr23016_2.o +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -rW $< >$@ 2>/dev/null +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_2.o: pr23016_2a.o pr23016_2b.o gcctestdir/ld +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -r -o $@ pr23016_2a.o pr23016_2b.o +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_2a.o: pr23016_2a.s +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) -o $@ $< +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr23016_2b.o: pr23016_2b.s +@DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) -o $@ $< @DEFAULT_TARGET_X86_64_OR_X32_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@pr20216a.so: pr20216_gd.o pr20216_ld.o gcctestdir/ld @DEFAULT_TARGET_X86_64_OR_X32_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -shared pr20216_gd.o pr20216_ld.o diff --git a/gold/testsuite/pr23016_1.sh b/gold/testsuite/pr23016_1.sh new file mode 100755 index 0000000..f909a9b --- /dev/null +++ b/gold/testsuite/pr23016_1.sh @@ -0,0 +1,87 @@ +#!/bin/sh + +# pr23016_1.sh -- check that .eh_frame sections and their relocations +# are merged together even when mixing SHT_PROGBITS and SHT_X86_64_UNWIND. + +# Copyright (C) 2018 Free Software Foundation, Inc. +# Written by Cary Coutant <ccoutant@gmail.com>. + +# This file is part of gold. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. + +set -e + +check() { + awk -v "FILE=$1" ' + BEGIN { + progbits = 0; + unwind = 0; + ehframe_rel = 0; + relocx = 0; + relocy = 0; + } + /\.eh_frame *PROGBITS/ { + progbits++; + } + /\.eh_frame *X86_64_UNWIND/ { + unwind++; + } + /^Relocation section .\.rela\.eh_frame/ { + ehframe_rel++; + } + /R_X86_64_64.*x \+ 0/ { + relocx++; + } + /R_X86_64_64.*y \+ 0/ { + relocy++; + } + END { + errs = 0; + if (progbits != 0) + { + printf "%s: There should be no .eh_frame sections of type PROGBITS.\n", FILE; + errs++; + } + if (unwind != 1) + { + printf "%s: There should be exactly one .eh_frame section of type X86_64_UNWIND.\n", FILE; + errs++; + } + if (ehframe_rel != 1) + { + printf "%s: There should be exactly one .rela.eh_frame relocation section.\n", FILE; + errs++; + } + if (relocx != 1) + { + printf "%s: There should be exactly one relocation for x.\n", FILE; + errs++; + } + if (relocy != 1) + { + printf "%s: There should be exactly one relocation for y.\n", FILE; + errs++; + } + exit errs; + } + ' $1 +} + +check pr23016_1.stdout +check pr23016_1r.stdout + +exit 0 diff --git a/gold/testsuite/pr23016_1a.s b/gold/testsuite/pr23016_1a.s new file mode 100644 index 0000000..02de7e7 --- /dev/null +++ b/gold/testsuite/pr23016_1a.s @@ -0,0 +1,3 @@ + .section .eh_frame,"aw",@progbits + .globl x + .quad x diff --git a/gold/testsuite/pr23016_1b.s b/gold/testsuite/pr23016_1b.s new file mode 100644 index 0000000..6f1d888 --- /dev/null +++ b/gold/testsuite/pr23016_1b.s @@ -0,0 +1,3 @@ + .section .eh_frame,"aw",@unwind + .globl y + .quad y diff --git a/gold/testsuite/pr23016_2.sh b/gold/testsuite/pr23016_2.sh new file mode 100755 index 0000000..952188c --- /dev/null +++ b/gold/testsuite/pr23016_2.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +# pr23016_2.sh -- check that relocations get written to separate sections +# when data sections of the same name are not merged. + +# Copyright (C) 2018 Free Software Foundation, Inc. +# Written by Cary Coutant <ccoutant@gmail.com>. + +# This file is part of gold. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, +# MA 02110-1301, USA. + +set -e + +awk ' +BEGIN { + sect = 0; + relocx = 0; + relocy = 0; + } +/^Relocation section .\.relaone/ { + sect += 1; + } +/R_X86_64_64.*x \+ 0/ { + relocx += sect; + } +/R_X86_64_64.*y \+ 0/ { + relocy = sect; + } +END { + if (relocx != 1) + { + printf "Relocation for x should be in first relocation section.\n"; + exit 1; + } + if (relocy != 2) + { + printf "Relocation for y should be in second relocation section.\n"; + exit 1; + } + } +' pr23016_2.stdout + +exit 0 diff --git a/gold/testsuite/pr23016_2a.s b/gold/testsuite/pr23016_2a.s new file mode 100644 index 0000000..383c90d --- /dev/null +++ b/gold/testsuite/pr23016_2a.s @@ -0,0 +1,3 @@ + .section one,"aw",@progbits + .globl x + .quad x diff --git a/gold/testsuite/pr23016_2b.s b/gold/testsuite/pr23016_2b.s new file mode 100644 index 0000000..8de9095 --- /dev/null +++ b/gold/testsuite/pr23016_2b.s @@ -0,0 +1,3 @@ + .section one,"aw",@note + .globl y + .quad y diff --git a/gold/testsuite/testfile.cc b/gold/testsuite/testfile.cc index d79f10d..da83b3b 100644 --- a/gold/testsuite/testfile.cc +++ b/gold/testsuite/testfile.cc @@ -118,6 +118,7 @@ const Target::Target_info Target_test<size, big_endian>::test_target_info = NULL, // attributes_vendor "_start", // entry_symbol_name 32, // hash_entry_size + elfcpp::SHT_PROGBITS, // unwind_section_type }; // The test targets. |