diff --git a/gold/script-sections.cc b/gold/script-sections.cc index c42827f..2f3b946 100644 --- a/gold/script-sections.cc +++ b/gold/script-sections.cc @@ -1652,7 +1652,7 @@ Output_section_element_input::set_section_addresses( else { size_t i; - for (i = 0; i < input_pattern_count; ++i) + for (i = 0; i < this->input_section_patterns_.size(); ++i) { const Input_section_pattern& isp(this->input_section_patterns_[i]); diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 01cae9f..65ddffc 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -1859,6 +1859,17 @@ script_test_12a.o: script_test_12a.c script_test_12b.o: script_test_12b.c $(COMPILE) -O0 -c -o $@ $< +# Test that "*(a b)" in input section spec grabs only specified sections. +check_SCRIPTS += script_test_13.sh +check_DATA += script_test_13.stdout +MOSTLYCLEANFILES += script_test_13 +script_test_13.o: script_test_13.s + $(TEST_AS) -o $@ $< +script_test_13: $(srcdir)/script_test_13.t script_test_13.o gcctestdir/ld + gcctestdir/ld -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 --dynamic-list, --dynamic-list-data, --dynamic-list-cpp-new, # and --dynamic-list-cpp-typeinfo diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 3771f79..8a8d0b6 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -340,9 +340,9 @@ 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@ 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 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 @@ -370,6 +370,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 that "*(a b)" in input section spec grabs only specified sections. + # Test --dynamic-list, --dynamic-list-data, --dynamic-list-cpp-new, # and --dynamic-list-cpp-typeinfo @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_36 = debug_msg.sh \ @@ -386,7 +388,9 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_6.sh \ @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 dynamic_list.sh +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_9.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ script_test_13.sh \ +@GCC_TRUE@@NATIVE_LINKER_TRUE@ dynamic_list.sh # Create the data files that debug_msg.sh analyzes. @@ -432,6 +436,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@ dynamic_list.stdout @GCC_FALSE@script_test_1_DEPENDENCIES = @NATIVE_LINKER_FALSE@script_test_1_DEPENDENCIES = @@ -4605,6 +4610,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) dynamic_list.sh.log: dynamic_list.sh @p='dynamic_list.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) plugin_test_1.sh.log: plugin_test_1.sh @@ -6057,6 +6064,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.s +@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_AS) -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 -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@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 \ diff --git a/gold/testsuite/script_test_13.s b/gold/testsuite/script_test_13.s new file mode 100644 index 0000000..330c4f0 --- /dev/null +++ b/gold/testsuite/script_test_13.s @@ -0,0 +1,8 @@ + .section .sec0, "a" + .zero 1 + + .section .sec1, "a" + .zero 2 + + .section .sec2, "a" + .zero 4 diff --git a/gold/testsuite/script_test_13.sh b/gold/testsuite/script_test_13.sh new file mode 100755 index 0000000..4035890 --- /dev/null +++ b/gold/testsuite/script_test_13.sh @@ -0,0 +1,65 @@ +#!/bin/sh + +# script_test_13.sh -- Check that "*(a b)" grabs only specified sections. + +# Copyright (C) 2016 Free Software Foundation, Inc. +# Written by Igor Kudrin . + +# 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. + +file="script_test_13.stdout" + +get_symbol_value() +{ + symbol=$1 + found=`fgrep "$symbol" $file` + if test -z "$found"; then + echo "Symbol \"$symbol\" not found in file $file" + echo "" + echo "Actual output below:" + cat "$file" + exit 1 + fi + echo "0x$(echo "$found" | awk '{ print $2 }' | sed -e 's/^0*\([1-9]\)/\1/;s/^0*$/0/')" +} + +sec_start=$(get_symbol_value _sec_start) +sec_middle=$(get_symbol_value _sec_middle) +sec_end=$(get_symbol_value _sec_end) + +# The difference between symbols "sec_start" and "sec_middle" is expected +# to be equal to 5 because there should be two sections between them: +# ".sec0" (1 byte long) and ".sec2" (4 bytes long). +if test $(($sec_start+5)) -ne $(($sec_middle)); then + echo "\"_sec_middle\" ($sec_middle) is expected to be greater than \"_sec_start\" ($sec_start) by 5" + echo "" + echo "Actual output below:" + cat "$file" + exit 1 +fi + +# It is expected that there is section ".sec1" (2 bytes long) between +# symbols "sec_middle" and "sec_end". +if test $(($sec_middle+2)) -ne $(($sec_end)); then + echo "\"_sec_end\" ($sec_end) is expected to be greater than \"_sec_middle\" ($sec_middle) by 2" + echo "" + echo "Actual output below:" + cat "$file" + exit 1 +fi + diff --git a/gold/testsuite/script_test_13.t b/gold/testsuite/script_test_13.t new file mode 100644 index 0000000..a697137 --- /dev/null +++ b/gold/testsuite/script_test_13.t @@ -0,0 +1,39 @@ +/* script_test_13.t -- linker script test 13 for gold + + Copyright (C) 2016 Free Software Foundation, Inc. + Written by Igor Kudrin . + + 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 test checks that input section descriptions which include more + than one section grab only specified sections. As a result, the + symbols should be assigned with the corresponding values, which + can be checked with the script. */ + +SECTIONS +{ + .sec : + { + _sec_start = .; + *(.sec0 .sec2) + _sec_middle = .; + *(.sec1) + _sec_end = .; + } +} +