* script-sections.h (class Script_sections): Make

Sections_elements typedef public.
	* script-sections.cc (class Sort_output_sections): Add elements_
	field.  Add constructor which sets it; change all callers.
	(Sort_output_sections::is_before): New function.
	(Sort_output_sections::operator()): Call is_before.
	* configure.ac (NATIVE_OR_CROSS_LINKER): New automake
	conditional.
	* testsuite/script_test_10.sh: New test. Test script section
	order.
	* testsuite/script_test_10.t: Likewise.
	* testsuite/script_test_10.s: Likewise.
	* testsuite/Makefile.am: Wrap the cross linker tests and the
	common tests into NATIVE_OR_CROSS_LINKER.
	(check_SCRIPTS): Add script_test_10.sh.
	(check_DATA): Add script_test_10.stdout.
	(script_test_10.o, script_test_10): New targets.
	(script_test_10.stdout): New target.
	* configure, testsuite/Makefile.in: Regenerate.
This commit is contained in:
Ian Lance Taylor 2010-10-12 19:21:41 +00:00
parent 3cef717918
commit eb3730490e
10 changed files with 574 additions and 352 deletions

View File

@ -1,3 +1,25 @@
2010-10-12 Ian Lance Taylor <iant@google.com>
* script-sections.h (class Script_sections): Make
Sections_elements typedef public.
* script-sections.cc (class Sort_output_sections): Add elements_
field. Add constructor which sets it; change all callers.
(Sort_output_sections::is_before): New function.
(Sort_output_sections::operator()): Call is_before.
* configure.ac (NATIVE_OR_CROSS_LINKER): New automake
conditional.
* testsuite/script_test_10.sh: New test. Test script section
order.
* testsuite/script_test_10.t: Likewise.
* testsuite/script_test_10.s: Likewise.
* testsuite/Makefile.am: Wrap the cross linker tests and the
common tests into NATIVE_OR_CROSS_LINKER.
(check_SCRIPTS): Add script_test_10.sh.
(check_DATA): Add script_test_10.stdout.
(script_test_10.o, script_test_10): New targets.
(script_test_10.stdout): New target.
* configure, testsuite/Makefile.in: Regenerate.
2010-10-12 Viktor Kutuzov <vkutuzov@accesssoftek.com>
* arm.cc (Target_arm::Scan::local): Report the unsupported reloc

17
gold/configure vendored
View File

@ -621,6 +621,8 @@ MCMODEL_MEDIUM_FALSE
MCMODEL_MEDIUM_TRUE
FN_PTRS_IN_SO_WITHOUT_PIC_FALSE
FN_PTRS_IN_SO_WITHOUT_PIC_TRUE
NATIVE_OR_CROSS_LINKER_FALSE
NATIVE_OR_CROSS_LINKER_TRUE
GCC_FALSE
GCC_TRUE
NATIVE_LINKER_FALSE
@ -6085,6 +6087,15 @@ else
fi
if test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias" -o "x$host_alias" = "x$build_alias"; then
NATIVE_OR_CROSS_LINKER_TRUE=
NATIVE_OR_CROSS_LINKER_FALSE='#'
else
NATIVE_OR_CROSS_LINKER_TRUE='#'
NATIVE_OR_CROSS_LINKER_FALSE=
fi
if
case $target_cpu in
i?86) true;;
@ -7223,6 +7234,10 @@ if test -z "${GCC_TRUE}" && test -z "${GCC_FALSE}"; then
as_fn_error "conditional \"GCC\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${NATIVE_OR_CROSS_LINKER_TRUE}" && test -z "${NATIVE_OR_CROSS_LINKER_FALSE}"; then
as_fn_error "conditional \"NATIVE_OR_CROSS_LINKER\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${FN_PTRS_IN_SO_WITHOUT_PIC_TRUE}" && test -z "${FN_PTRS_IN_SO_WITHOUT_PIC_FALSE}"; then
as_fn_error "conditional \"FN_PTRS_IN_SO_WITHOUT_PIC\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
@ -8562,7 +8577,7 @@ $as_echo X"$file" |
case "$ac_file" in */Makefile.in)
# Adjust a relative srcdir.
ac_dir=`echo "$ac_file"|sed 's%/[^/][^/]*$%%'`
ac_dir_suffix=/`echo "$ac_dir"|sed 's%^\./%%'`
ac_dir_suffix="/`echo "$ac_dir"|sed 's%^\./%%'`"
ac_dots=`echo "$ac_dir_suffix"|sed 's%/[^/]*%../%g'`
# In autoconf-2.13 it is called $ac_given_srcdir.
# In autoconf-2.50 it is called $srcdir.

View File

@ -252,6 +252,9 @@ AM_CONDITIONAL(NATIVE_LINKER,
test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias")
AM_CONDITIONAL(GCC, test "$GCC" = yes)
AM_CONDITIONAL(NATIVE_OR_CROSS_LINKER,
test "x$target_alias" = "x" -o "x$host_alias" = "x$target_alias" -o "x$host_alias" = "x$build_alias")
dnl Some architectures do not support taking pointers of functions
dnl defined in shared libraries except in -fPIC mode. We need to
dnl tell the unittest framework if we're compiling for one of those

View File

@ -3552,8 +3552,19 @@ Script_sections::set_section_addresses(Symbol_table* symtab, Layout* layout)
class Sort_output_sections
{
public:
Sort_output_sections(const Script_sections::Sections_elements* elements)
: elements_(elements)
{ }
bool
operator()(const Output_section* os1, const Output_section* os2) const;
private:
bool
is_before(const Output_section* os1, const Output_section* os2) const;
private:
const Script_sections::Sections_elements* elements_;
};
bool
@ -3592,7 +3603,36 @@ Sort_output_sections::operator()(const Output_section* os1,
if (!os1->is_noload() && os2->is_noload())
return true;
// Otherwise we don't care.
// The sections have the same address. Check the section positions
// in accordance with the linker script.
return this->is_before(os1, os2);
}
// Return true if OS1 comes before OS2 in ELEMENTS_. This ensures
// that we keep empty sections in the order in which they appear in a
// linker script.
bool
Sort_output_sections::is_before(const Output_section* os1,
const Output_section* os2) const
{
if (this->elements_ == NULL)
return false;
for (Script_sections::Sections_elements::const_iterator
p = this->elements_->begin();
p != this->elements_->end();
++p)
{
if (os1 == (*p)->get_output_section())
{
for (++p; p != this->elements_->end(); ++p)
if (os2 == (*p)->get_output_section())
return true;
break;
}
}
return false;
}
@ -3666,7 +3706,8 @@ Script_sections::create_segments(Layout* layout, uint64_t dot_alignment)
layout->get_allocated_sections(&sections);
// Sort the sections by address.
std::stable_sort(sections.begin(), sections.end(), Sort_output_sections());
std::stable_sort(sections.begin(), sections.end(),
Sort_output_sections(this->sections_elements_));
this->create_note_and_tls_segments(layout, &sections);

View File

@ -47,13 +47,11 @@ class Orphan_section_placement;
class Script_sections
{
private:
public:
// This is a list, not a vector, because we insert orphan sections
// in the middle.
typedef std::list<Sections_element*> Sections_elements;
public:
// Logical script section types. We map section types returned by the
// parser into these since some section types have the same semantics.
enum Section_type

View File

@ -70,12 +70,14 @@ LDADD = libgoldtest.a ../libgold.a ../../libiberty/libiberty.a $(LIBINTL) \
# The unittests themselves
if NATIVE_OR_CROSS_LINKER
check_PROGRAMS += object_unittest
object_unittest_SOURCES = object_unittest.cc
check_PROGRAMS += binary_unittest
binary_unittest_SOURCES = binary_unittest.cc
endif NATIVE_OR_CROSS_LINKER
# ---------------------------------------------------------------------
# These tests test the output of gold (end-to-end tests). In
@ -1798,7 +1800,21 @@ memory_test.stdout: memory_test
endif GCC
endif NATIVE_LINKER
# These tests work with cross linkers.
# These tests work with native and cross linkers.
if NATIVE_OR_CROSS_LINKER
# Test script section order.
check_SCRIPTS += script_test_10.sh
check_DATA += script_test_10.stdout
script_test_10.o: script_test_10.s
$(TEST_AS) -o $@ $<
script_test_10: $(srcdir)/script_test_10.t script_test_10.o gcctestdir/ld
gcctestdir/ld -o $@ script_test_10.o -T $(srcdir)/script_test_10.t
script_test_10.stdout: script_test_10
$(TEST_READELF) -SW script_test_10 > $@
# These tests work with cross linkers only.
if DEFAULT_TARGET_I386
@ -2131,3 +2147,6 @@ MOSTLYCLEANFILES += arm_cortex_a8_b_cond arm_cortex_a8_b arm_cortex_a8_bl \
arm_cortex_a8_blx arm_cortex_a8_local arm_cortex_a8_local_reloc
endif DEFAULT_TARGET_ARM
endif NATIVE_OR_CROSS_LINKER

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
.section .sec0, "a"
.word 0
.section .sec2, "a"
.word 0x22
.section .sec1, "a"
.word 0x11
.section .secz, "a"
.section .sec3, "a"
.word 0x44

View File

@ -0,0 +1,46 @@
#!/bin/sh
# script_test_10.sh -- test for the section order.
# Copyright 2010 Free Software Foundation, Inc.
# Written by Viktor Kutuzov <vkutuzov@accesssoftek.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.
check()
{
if ! grep -q "$2" "$1"
then
echo "Did not find expected section in $1:"
echo " $2"
echo ""
echo "Actual output below:"
cat "$1"
exit 1
fi
}
check script_test_10.stdout ".*\[ 1\] .text"
check script_test_10.stdout ".*\[ 2\] .sec0"
check script_test_10.stdout ".*\[ 3\] .sec1"
check script_test_10.stdout ".*\[ 4\] .sec2"
check script_test_10.stdout ".*\[ 5\] .secz"
check script_test_10.stdout ".*\[ 6\] .sec3"
check script_test_10.stdout ".*\[ 7\] .data"
check script_test_10.stdout ".*\[ 8\] .bss"

View File

@ -0,0 +1,34 @@
/* script_test_10.t -- test section order for gold.
Copyright 2010 Free Software Foundation, Inc.
Written by Viktor Kutuzov <vkutuzov@accesssoftek.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. */
SECTIONS
{
.text : { *(.text) }
.sec0 : { *(.sec0) }
.sec1 : { *(.sec1) }
.sec2 : { *(.sec2) }
.secz : { *(.secz) }
.sec3 : { *(.sec3) }
.data : { *(.data) }
.bss : { *(.bss) }
}