summaryrefslogtreecommitdiff
path: root/gold/layout.cc
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@gmail.com>2018-04-02 16:12:10 -0700
committerCary Coutant <ccoutant@gmail.com>2018-04-02 19:07:04 -0700
commitbce5a025d2ed7eda2c5bbb85bd9b33333ca5d556 (patch)
tree92912c522de8e45805825292a4a94e50f753584c /gold/layout.cc
parent8849a5e9edda5f00d727490c7bb8be3c616742ae (diff)
downloadbinutils-gdb-bce5a025d2ed7eda2c5bbb85bd9b33333ca5d556.tar.gz
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/layout.cc')
-rw-r--r--gold/layout.cc48
1 files changed, 23 insertions, 25 deletions
diff --git a/gold/layout.cc b/gold/layout.cc
index f5fe805ea78..2eb7b7c8429 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -1153,15 +1153,14 @@ template<int size, bool big_endian>
Output_section*
Layout::layout(Sized_relobj_file<size, big_endian>* object, unsigned int shndx,
const char* name, const elfcpp::Shdr<size, big_endian>& shdr,
- unsigned int reloc_shndx, unsigned int, off_t* off)
+ unsigned int sh_type, unsigned int reloc_shndx,
+ unsigned int, off_t* off)
{
*off = 0;
if (!this->include_section(object, name, shdr))
return NULL;
- elfcpp::Elf_Word sh_type = shdr.get_sh_type();
-
// In a relocatable link a grouped section must not be combined with
// any other sections.
Output_section* os;
@@ -1315,7 +1314,7 @@ Layout::insert_section_segment_map(Const_section_id secn,
template<int size, bool big_endian>
Output_section*
-Layout::layout_reloc(Sized_relobj_file<size, big_endian>* object,
+Layout::layout_reloc(Sized_relobj_file<size, big_endian>*,
unsigned int,
const elfcpp::Shdr<size, big_endian>& shdr,
Output_section* data_section,
@@ -1335,24 +1334,19 @@ Layout::layout_reloc(Sized_relobj_file<size, big_endian>* object,
gold_unreachable();
name += data_section->name();
- // In a relocatable link relocs for a grouped section must not be
- // combined with other reloc sections.
- Output_section* os;
- if (!parameters->options().relocatable()
- || (data_section->flags() & elfcpp::SHF_GROUP) == 0)
- os = this->choose_output_section(object, name.c_str(), sh_type,
- shdr.get_sh_flags(), false,
- ORDER_INVALID, false, true, false);
- else
+ // If the output data section already has a reloc section, use that;
+ // otherwise, make a new one.
+ Output_section* os = data_section->reloc_section();
+ if (os == NULL)
{
const char* n = this->namepool_.add(name.c_str(), true, NULL);
os = this->make_output_section(n, sh_type, shdr.get_sh_flags(),
ORDER_INVALID, false);
+ os->set_should_link_to_symtab();
+ os->set_info_section(data_section);
+ data_section->set_reloc_section(os);
}
- os->set_should_link_to_symtab();
- os->set_info_section(data_section);
-
Output_section_data* posd;
if (sh_type == elfcpp::SHT_REL)
{
@@ -1442,8 +1436,11 @@ Layout::layout_eh_frame(Sized_relobj_file<size, big_endian>* object,
unsigned int reloc_shndx, unsigned int reloc_type,
off_t* off)
{
+ const unsigned int unwind_section_type =
+ parameters->target().unwind_section_type();
+
gold_assert(shdr.get_sh_type() == elfcpp::SHT_PROGBITS
- || shdr.get_sh_type() == elfcpp::SHT_X86_64_UNWIND);
+ || shdr.get_sh_type() == unwind_section_type);
gold_assert((shdr.get_sh_flags() & elfcpp::SHF_ALLOC) != 0);
Output_section* os = this->make_eh_frame_section(object);
@@ -1530,10 +1527,11 @@ Layout::finalize_eh_frame_section()
Output_section*
Layout::make_eh_frame_section(const Relobj* object)
{
- // FIXME: On x86_64, this could use SHT_X86_64_UNWIND rather than
- // SHT_PROGBITS.
+ const unsigned int unwind_section_type =
+ parameters->target().unwind_section_type();
+
Output_section* os = this->choose_output_section(object, ".eh_frame",
- elfcpp::SHT_PROGBITS,
+ unwind_section_type,
elfcpp::SHF_ALLOC, false,
ORDER_EHFRAME, false, false,
false);
@@ -1551,7 +1549,7 @@ Layout::make_eh_frame_section(const Relobj* object)
{
Output_section* hdr_os =
this->choose_output_section(NULL, ".eh_frame_hdr",
- elfcpp::SHT_PROGBITS,
+ unwind_section_type,
elfcpp::SHF_ALLOC, false,
ORDER_EHFRAME, false, false,
false);
@@ -5915,7 +5913,7 @@ Layout::layout<32, false>(Sized_relobj_file<32, false>* object,
unsigned int shndx,
const char* name,
const elfcpp::Shdr<32, false>& shdr,
- unsigned int, unsigned int, off_t*);
+ unsigned int, unsigned int, unsigned int, off_t*);
#endif
#ifdef HAVE_TARGET_32_BIG
@@ -5925,7 +5923,7 @@ Layout::layout<32, true>(Sized_relobj_file<32, true>* object,
unsigned int shndx,
const char* name,
const elfcpp::Shdr<32, true>& shdr,
- unsigned int, unsigned int, off_t*);
+ unsigned int, unsigned int, unsigned int, off_t*);
#endif
#ifdef HAVE_TARGET_64_LITTLE
@@ -5935,7 +5933,7 @@ Layout::layout<64, false>(Sized_relobj_file<64, false>* object,
unsigned int shndx,
const char* name,
const elfcpp::Shdr<64, false>& shdr,
- unsigned int, unsigned int, off_t*);
+ unsigned int, unsigned int, unsigned int, off_t*);
#endif
#ifdef HAVE_TARGET_64_BIG
@@ -5945,7 +5943,7 @@ Layout::layout<64, true>(Sized_relobj_file<64, true>* object,
unsigned int shndx,
const char* name,
const elfcpp::Shdr<64, true>& shdr,
- unsigned int, unsigned int, off_t*);
+ unsigned int, unsigned int, unsigned int, off_t*);
#endif
#ifdef HAVE_TARGET_32_LITTLE