When using linker scripts, place linker-generated sections by the output section...
authorCary Coutant <ccoutant@gmail.com>
Tue, 13 Dec 2016 02:51:29 +0000 (18:51 -0800)
committerCary Coutant <ccoutant@gmail.com>
Tue, 13 Dec 2016 02:52:44 +0000 (18:52 -0800)
2016-12-12  Igor Kudrin  <ikudrin@accesssoftek.com>
    Cary Coutant  <ccoutant@gmail.com>

gold/
PR gold/14676
* script-sections.cc (Output_section_definition::output_section_name):
For linker-generated sections, compare with output section name.
* testsuite/Makefile.am (script_test_13): New test.
* testsuite/Makefile.in: Regenerate.
* testsuite/script_test_13.c: New source file.
* testsuite/script_test_13.sh: New script.
* testsuite/script_test_13.t: New linker script.

gold/ChangeLog
gold/script-sections.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/script_test_13.c [new file with mode: 0644]
gold/testsuite/script_test_13.sh [new file with mode: 0755]
gold/testsuite/script_test_13.t [new file with mode: 0644]

index aeec3892664767e9c5667c15d3692a32b31e97cc..e0ce513c58d23db37b990966a0dc4f48d4d13e41 100644 (file)
@@ -1,3 +1,15 @@
+2016-12-12  Igor Kudrin  <ikudrin@accesssoftek.com>
+           Cary Coutant  <ccoutant@gmail.com>
+
+       PR gold/14676
+       * script-sections.cc (Output_section_definition::output_section_name):
+       For linker-generated sections, compare with output section name.
+       * testsuite/Makefile.am (script_test_13): New test.
+       * testsuite/Makefile.in: Regenerate.
+       * testsuite/script_test_13.c: New source file.
+       * testsuite/script_test_13.sh: New script.
+       * testsuite/script_test_13.t: New linker script.
+
 2016-12-12  Cary Coutant  <ccoutant@gmail.com>
 
        * script-sections.cc (Orphan_section_placement::update_last_alloc):
index d970e575263b9c446a637d4dacae81bc58c8bc60..90ec8d4a504d873e10b9165ea3f5c104d57981f9 100644 (file)
@@ -2291,6 +2291,17 @@ Output_section_definition::output_section_name(
     Script_sections::Section_type* psection_type,
     bool* keep)
 {
+  // If the input section is linker-created, just look for a match
+  // on the output section name.
+  if (file_name == NULL && this->name_ != "/DISCARD/")
+    {
+      if (this->name_ != section_name)
+       return NULL;
+      *slot = &this->output_section_;
+      *psection_type = this->section_type();
+      return this->name_.c_str();
+    }
+
   // Ask each element whether it matches NAME.
   for (Output_section_elements::const_iterator p = this->elements_.begin();
        p != this->elements_.end();
index 25db2b8d09547c85df220d7331d7d6d532fcaba3..4d0aaa1cb9b96490af4dc7f2dc00152573c642ca 100644 (file)
@@ -2008,6 +2008,17 @@ script_test_12a.o: script_test_12a.c
 script_test_12b.o: script_test_12b.c
        $(COMPILE) -O0 -c -o $@ $<
 
+# Test for ordering internally created sections with a linker script.
+check_SCRIPTS += script_test_13.sh
+check_DATA += script_test_13.stdout
+MOSTLYCLEANFILES += script_test_13
+script_test_13.o: script_test_13.c
+       $(COMPILE) -O0 -c -fPIC -o $@ $<
+script_test_13: $(srcdir)/script_test_13.t script_test_13.o gcctestdir/ld
+       gcctestdir/ld -shared -o $@ script_test_13.o -T $(srcdir)/script_test_13.t
+script_test_13.stdout: script_test_13
+       $(TEST_READELF) -SW script_test_13 > $@
+
 # Test for SORT_BY_INIT_PRIORITY.
 check_SCRIPTS += script_test_14.sh
 check_DATA += script_test_14.stdout
index 1a535ed7523591080f04a29d887f48700b2dd3f8..a70322c639f6a1c6aaad114ae001c43f7e7dd6ca 100644 (file)
@@ -365,11 +365,11 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_4 script_test_5 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_6 script_test_7 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_8 script_test_9 \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_14 script_test_15a \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_15b script_test_15c \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list dynamic_list.stdout \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ libthin1.a libthin3.a \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ libthinall.a \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_13 script_test_14 \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_15a script_test_15b \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_15c dynamic_list \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list.stdout libthin1.a \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ libthin3.a libthinall.a \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ alt/thin_archive_test_2.o \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ alt/thin_archive_test_4.o \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ alt/libthin2.a alt/libthin4.a
@@ -391,6 +391,8 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 
 # Similar to --detect-odr-violations: check for undefined symbols in .so's
 
+# Test for ordering internally created sections with a linker script.
+
 # Test for SORT_BY_INIT_PRIORITY.
 
 # Test BSS section placement at end of segment.
@@ -417,6 +419,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_7.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_8.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_9.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_13.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_14.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_15a.sh \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_15b.sh \
@@ -469,6 +472,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_7.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_8.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_9.stdout \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_13.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_14.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_15a.stdout \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_15b.stdout \
@@ -5115,6 +5119,8 @@ script_test_8.sh.log: script_test_8.sh
        @p='script_test_8.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 script_test_9.sh.log: script_test_9.sh
        @p='script_test_9.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+script_test_13.sh.log: script_test_13.sh
+       @p='script_test_13.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 script_test_14.sh.log: script_test_14.sh
        @p='script_test_14.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 script_test_15a.sh.log: script_test_15a.sh
@@ -6664,6 +6670,12 @@ uninstall-am:
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -o $@ $<
 @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_12b.o: script_test_12b.c
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_13.o: script_test_13.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -fPIC -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_13: $(srcdir)/script_test_13.t script_test_13.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -shared -o $@ script_test_13.o -T $(srcdir)/script_test_13.t
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_13.stdout: script_test_13
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -SW script_test_13 > $@
 @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_14.o: script_test_14.s
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) -o $@ $<
 @GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_14: $(srcdir)/script_test_14.t script_test_14.o gcctestdir/ld
diff --git a/gold/testsuite/script_test_13.c b/gold/testsuite/script_test_13.c
new file mode 100644 (file)
index 0000000..83e0948
--- /dev/null
@@ -0,0 +1,2 @@
+extern int a;
+int* pa = &a;
diff --git a/gold/testsuite/script_test_13.sh b/gold/testsuite/script_test_13.sh
new file mode 100755 (executable)
index 0000000..fff2772
--- /dev/null
@@ -0,0 +1,41 @@
+#!/bin/sh
+
+# script_test_13.sh -- test that internally created sections obey
+# the order from the linker script.
+
+# Copyright (C) 2016 Free Software Foundation, Inc.
+# Written by Igor Kudrin <ikudrin@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()
+{
+    file=$1
+    pattern=$2
+    match_pattern=`grep -e "$pattern" $file`
+    if test -z "$match_pattern"; then
+        echo "Expected pattern was not found:"
+        echo "    $pattern"
+        echo ""
+        echo "Actual output below:"
+        cat "$file"
+        exit 1
+    fi
+}
+
+check "script_test_13.stdout" "\\.rela\\.dyn[[:space:]]\\+RELA[[:space:]]\\+0\\+10000\\b"
diff --git a/gold/testsuite/script_test_13.t b/gold/testsuite/script_test_13.t
new file mode 100644 (file)
index 0000000..d51e1db
--- /dev/null
@@ -0,0 +1,7 @@
+SECTIONS
+{
+       .text 0 : { *(.text) }
+
+       .rela.dyn 0x10000 : { *(.rela.init) }
+       .rel.dyn 0x10000 : { *(.rela.init) }
+}