binutils-gdb/gold/testsuite/pr23016_1.sh

88 lines
2.1 KiB
Bash
Raw Normal View History

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.
2018-04-03 07:12:10 +08:00
#!/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