[gold][patch] Fix problem with sections not named in linker script
Cary Coutant
ccoutant@google.com
Wed Feb 25 01:28:00 GMT 2009
The Linux kernel has several functions in the ".text.unlikely"
section, but that section is not covered by the linker script, so gnu
ld puts them into a new output section with the same name. Gold,
however, puts them into a second ".text" section.
The problem is that gold is applying its automatic section renaming --
which is intended to emulate gnu ld's default linker script --
whenever it finds a section that is not described by the SECTIONS
clause of a linker script. The patch below suppresses the renaming in
that case, and adds a test case to cover the problem.
-cary
* layout.cc (Layout::choose_output_section): Don't rename sections
when using a linker script that has a SECTIONS clause.
* Makefile.in: Regenerate.
* testsuite/Makefile.am (script_test_5.sh): New test case.
* testsuite/Makefile.in: Regenerate.
* testsuite/script_test_5.cc: New file.
* testsuite/script_test_5.sh: New file.
* testsuite/script_test_5.t: New file.
Index: Makefile.in
===================================================================
RCS file: /cvs/src/src/gold/Makefile.in,v
retrieving revision 1.61
diff -u -p -r1.61 Makefile.in
--- Makefile.in 28 Jan 2009 02:25:33 -0000 1.61
+++ Makefile.in 25 Feb 2009 01:23:11 -0000
@@ -79,15 +79,14 @@ am__objects_1 = archive.$(OBJEXT) binary
cref.$(OBJEXT) defstd.$(OBJEXT) descriptors.$(OBJEXT) \
dirsearch.$(OBJEXT) dynobj.$(OBJEXT) dwarf_reader.$(OBJEXT) \
ehframe.$(OBJEXT) errors.$(OBJEXT) expression.$(OBJEXT) \
- fileread.$(OBJEXT) gc.$(OBJEXT) \
- gold.$(OBJEXT) gold-threads.$(OBJEXT) \
- layout.$(OBJEXT) mapfile.$(OBJEXT) merge.$(OBJEXT) \
- object.$(OBJEXT) options.$(OBJEXT) output.$(OBJEXT) \
- parameters.$(OBJEXT) plugin.$(OBJEXT) readsyms.$(OBJEXT) \
- reduced_debug_output.$(OBJEXT) reloc.$(OBJEXT) \
- resolve.$(OBJEXT) script-sections.$(OBJEXT) script.$(OBJEXT) \
- stringpool.$(OBJEXT) symtab.$(OBJEXT) target-select.$(OBJEXT) \
- version.$(OBJEXT) workqueue.$(OBJEXT) \
+ fileread.$(OBJEXT) gc.$(OBJEXT) gold.$(OBJEXT) \
+ gold-threads.$(OBJEXT) layout.$(OBJEXT) mapfile.$(OBJEXT) \
+ merge.$(OBJEXT) object.$(OBJEXT) options.$(OBJEXT) \
+ output.$(OBJEXT) parameters.$(OBJEXT) plugin.$(OBJEXT) \
+ readsyms.$(OBJEXT) reduced_debug_output.$(OBJEXT) \
+ reloc.$(OBJEXT) resolve.$(OBJEXT) script-sections.$(OBJEXT) \
+ script.$(OBJEXT) stringpool.$(OBJEXT) symtab.$(OBJEXT) \
+ target-select.$(OBJEXT) version.$(OBJEXT) workqueue.$(OBJEXT) \
workqueue-threads.$(OBJEXT)
am__objects_2 =
am__objects_3 = yyscript.$(OBJEXT)
@@ -549,6 +548,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/errors.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/expression.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fileread.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gc.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gold-threads.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gold.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/i386.Po@am__quote@
Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.116
diff -u -p -r1.116 layout.cc
--- layout.cc 28 Jan 2009 02:25:33 -0000 1.116
+++ layout.cc 25 Feb 2009 01:23:12 -0000
@@ -426,7 +426,9 @@ Layout::choose_output_section(const Relo
// output section.
size_t len = strlen(name);
- if (is_input_section && !parameters->options().relocatable())
+ if (is_input_section
+ && !this->script_options_->saw_sections_clause()
+ && !parameters->options().relocatable())
name = Layout::output_section_name(name, &len);
Stringpool::Key name_key;
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.83
diff -u -p -r1.83 Makefile.am
--- testsuite/Makefile.am 15 Jan 2009 01:29:25 -0000 1.83
+++ testsuite/Makefile.am 25 Feb 2009 01:23:12 -0000
@@ -903,6 +903,14 @@ script_test_4: basic_test.o gcctestdir/l
script_test_4.stdout: script_test_4
$(TEST_READELF) -SlW script_test_4 > script_test_4.stdout
+check_SCRIPTS += script_test_5.sh
+check_DATA += script_test_5.stdout
+MOSTLYCLEANFILES += script_test_5.stdout
+script_test_5: script_test_5.o gcctestdir/ld $(srcdir)/script_test_5.t
+ $(CXXLINK) -Bgcctestdir/ script_test_5.o -T $(srcdir)/script_test_5.t
+script_test_5.stdout: script_test_5
+ $(TEST_READELF) -SW script_test_5 > script_test_5.stdout
+
# Test --dynamic-list, --dynamic-list-data, --dynamic-list-cpp-new,
# and --dynamic-list-cpp-typeinfo
Index: testsuite/Makefile.in
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.in,v
retrieving revision 1.88
diff -u -p -r1.88 Makefile.in
--- testsuite/Makefile.in 15 Jan 2009 01:29:25 -0000 1.88
+++ testsuite/Makefile.in 25 Feb 2009 01:23:12 -0000
@@ -171,7 +171,8 @@ check_PROGRAMS = object_unittest$(EXEEXT
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_test_7.sh ver_test_10.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.sh \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.sh dynamic_list.sh
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_5.sh dynamic_list.sh
# Create the data files that debug_msg.sh analyzes.
@@ -188,6 +189,7 @@ check_PROGRAMS = object_unittest$(EXEEXT
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.stdout \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_5.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list.stdout
@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@am__append_8 = tls_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@@TLS_TRUE@ tls_pic_test \
@@ -234,6 +236,7 @@ check_PROGRAMS = object_unittest$(EXEEXT
@GCC_TRUE@@NATIVE_LINKER_TRUE@ ver_matching_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_3.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4.stdout \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_5.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list.stdout
# Test -o when emitting to a special file (such as something in /dev).
@@ -2467,6 +2470,10 @@ uninstall-am: uninstall-info-am
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ basic_test.o
-T $(srcdir)/script_test_4.t
@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_4.stdout: script_test_4
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -SlW script_test_4 >
script_test_4.stdout
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_5: script_test_5.o
gcctestdir/ld $(srcdir)/script_test_5.t
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/
script_test_5.o -T $(srcdir)/script_test_5.t
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_5.stdout: script_test_5
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -SW script_test_5 >
script_test_5.stdout
@GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list: basic_test.o
gcctestdir/ld $(srcdir)/dynamic_list.t
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ basic_test.o \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ -Wl,--dynamic-list $(srcdir)/dynamic_list.t \
Index: testsuite/script_test_5.cc
===================================================================
RCS file: testsuite/script_test_5.cc
diff -N testsuite/script_test_5.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/script_test_5.cc 25 Feb 2009 01:23:12 -0000
@@ -0,0 +1,45 @@
+// script_test_5.cc -- a test case for gold
+
+// Copyright 2009 Free Software Foundation, Inc.
+// Written by Cary Coutant <ccoutant@google.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.
+
+// This program checks that the default renaming of ".text.xxx"
+// sections does not take place in the presence of a linker script
+// with a SECTIONS clause.
+
+bool
+t1() __attribute__ ((section (".text.foo")));
+
+bool
+t1()
+{
+ return 1;
+}
+
+// Main function. Initialize variables and call test functions.
+
+int
+main()
+{
+ if (t1())
+ return 0;
+ else
+ return 1;
+}
Index: testsuite/script_test_5.sh
===================================================================
RCS file: testsuite/script_test_5.sh
diff -N testsuite/script_test_5.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/script_test_5.sh 25 Feb 2009 01:23:12 -0000
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+# script_test_5.sh -- test linker script with uncovered sections
+
+# Copyright 2009 Free Software Foundation, Inc.
+# Written by Cary Coutant <ccoutant@google.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.
+
+# This file goes with script_test_5.t, which is a linker script with
+# a SECTIONS clause that does not explicitly mention one of the input
+# sections in the test object file. We check to make sure that the
+# correct output section is generated.
+
+check_count()
+{
+ if test "`grep -c "$2" "$1"`" != "$3"
+ then
+ echo "Did not find expected number ($3) of '$2' sections in $1"
+ echo ""
+ echo "Actual output below:"
+ cat "$1"
+ exit 1
+ fi
+}
+
+check_count script_test_5.stdout ".text " 1
+check_count script_test_5.stdout ".text.foo " 1
Index: testsuite/script_test_5.t
===================================================================
RCS file: testsuite/script_test_5.t
diff -N testsuite/script_test_5.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ testsuite/script_test_5.t 25 Feb 2009 01:23:12 -0000
@@ -0,0 +1,40 @@
+/* script_test_5.t -- linker script test 5 for gold
+
+ Copyright 2009 Free Software Foundation, Inc.
+ Written by Cary Coutant <ccoutant@google.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. */
+
+/* We won't try to run this program, just ensure that it links
+ as expected. */
+
+SECTIONS
+{
+ . = 0x10000000;
+
+ /* With luck this will be enough to get the program working. */
+ .interp : { *(.interp) }
+ .text : { *(.text) }
+ . += 0x100000;
+ . = ALIGN(0x100);
+ .dynamic : { *(.dynamic) }
+ .data : { *(.data) }
+ . += 0x100000;
+ . = ALIGN(0x100);
+ .bss : { *(.bss) }
+}
More information about the Binutils
mailing list