diff --git a/gold/script-sections.cc b/gold/script-sections.cc index bf25391..2bfd993 100644 --- a/gold/script-sections.cc +++ b/gold/script-sections.cc @@ -2223,7 +2223,7 @@ Output_section_definition::finalize_symbols(Symbol_table* symtab, *dot_value = this->output_section_->address(); else { - uint64_t address = *dot_value; + uint64_t address = this->evaluated_address_; if (this->address_ != NULL) { address = this->address_->eval_with_dot(symtab, layout, true, diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 1575aa3..127fac4 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -2997,6 +2997,17 @@ script_test_10: $(srcdir)/script_test_10.t script_test_10.o gcctestdir/ld script_test_10.stdout: script_test_10 $(TEST_READELF) -SW script_test_10 > $@ +# Test 'dot' value inside an empty section which is placed after an orphan section. +check_SCRIPTS += script_test_18.sh +check_DATA += script_test_18.stdout +MOSTLYCLEANFILES += script_test_18 +script_test_18.o: script_test_18.s + $(TEST_AS) -o $@ $< +script_test_18: $(srcdir)/script_test_18.t script_test_18.o gcctestdir/ld + gcctestdir/ld -o $@ script_test_18.o -T $(srcdir)/script_test_18.t +script_test_18.stdout: script_test_18 + $(TEST_NM) script_test_18 > $@ + # These tests work with cross linkers only. if DEFAULT_TARGET_I386 diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index a9bea38..8e06ac4 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -771,9 +771,14 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ # These tests work with native and cross linkers. # Test script section order. -@NATIVE_OR_CROSS_LINKER_TRUE@am__append_80 = script_test_10.sh -@NATIVE_OR_CROSS_LINKER_TRUE@am__append_81 = script_test_10.stdout -@NATIVE_OR_CROSS_LINKER_TRUE@am__append_82 = script_test_10 + +# Test 'dot' value inside an empty section which is placed after an orphan section. +@NATIVE_OR_CROSS_LINKER_TRUE@am__append_80 = script_test_10.sh \ +@NATIVE_OR_CROSS_LINKER_TRUE@ script_test_18.sh +@NATIVE_OR_CROSS_LINKER_TRUE@am__append_81 = script_test_10.stdout \ +@NATIVE_OR_CROSS_LINKER_TRUE@ script_test_18.stdout +@NATIVE_OR_CROSS_LINKER_TRUE@am__append_82 = script_test_10 \ +@NATIVE_OR_CROSS_LINKER_TRUE@ script_test_18 # These tests work with cross linkers only. @DEFAULT_TARGET_I386_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@am__append_83 = split_i386.sh @@ -5153,6 +5158,8 @@ defsym_test.sh.log: defsym_test.sh @p='defsym_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) script_test_10.sh.log: script_test_10.sh @p='script_test_10.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) +script_test_18.sh.log: script_test_18.sh + @p='script_test_18.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) split_i386.sh.log: split_i386.sh @p='split_i386.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post) split_x86_64.sh.log: split_x86_64.sh @@ -7159,6 +7166,12 @@ uninstall-am: @NATIVE_OR_CROSS_LINKER_TRUE@ gcctestdir/ld -o $@ script_test_10.o -T $(srcdir)/script_test_10.t @NATIVE_OR_CROSS_LINKER_TRUE@script_test_10.stdout: script_test_10 @NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_READELF) -SW script_test_10 > $@ +@NATIVE_OR_CROSS_LINKER_TRUE@script_test_18.o: script_test_18.s +@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -o $@ $< +@NATIVE_OR_CROSS_LINKER_TRUE@script_test_18: $(srcdir)/script_test_18.t script_test_18.o gcctestdir/ld +@NATIVE_OR_CROSS_LINKER_TRUE@ gcctestdir/ld -o $@ script_test_18.o -T $(srcdir)/script_test_18.t +@NATIVE_OR_CROSS_LINKER_TRUE@script_test_18.stdout: script_test_18 +@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_NM) script_test_18 > $@ @DEFAULT_TARGET_I386_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@split_i386_1.o: split_i386_1.s @DEFAULT_TARGET_I386_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@ $(TEST_AS) -o $@ $< @DEFAULT_TARGET_I386_TRUE@@NATIVE_OR_CROSS_LINKER_TRUE@split_i386_2.o: split_i386_2.s diff --git a/gold/testsuite/script_test_18.s b/gold/testsuite/script_test_18.s new file mode 100644 index 0000000..86f0961 --- /dev/null +++ b/gold/testsuite/script_test_18.s @@ -0,0 +1,4 @@ +.section .data, "aw" +.word 0 +.section .data.2, "aw" +.word 0 diff --git a/gold/testsuite/script_test_18.sh b/gold/testsuite/script_test_18.sh new file mode 100755 index 0000000..f827f7a --- /dev/null +++ b/gold/testsuite/script_test_18.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +# script_test_18.sh -- test "dot" symbol value in an empty section +# which has an orphan section before it. + +# 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_18.stdout" + +read_symbol() +{ + symbol=$1 + var=$2 + 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 + eval $var=`echo $found | awk '{ print $1 }'` +} + +read_symbol "val_dot" "val_dot" +read_symbol "val_addr" "val_addr" + +if test "$val_dot" != "$val_addr"; then + echo "Symbol 'val_dot', which represents the 'dot' value inside an empty section," + echo "and symbol 'val_addr', which is initialized by ADDR() of that section," + echo "are expected to have the same value." + echo "" + echo "Actual output below:" + cat "$file" + exit 1 +fi + diff --git a/gold/testsuite/script_test_18.t b/gold/testsuite/script_test_18.t new file mode 100644 index 0000000..ca196e3 --- /dev/null +++ b/gold/testsuite/script_test_18.t @@ -0,0 +1,6 @@ +SECTIONS +{ + .data : { *(.data) } + .sec2 : { val_dot = .; *(nonexisting) } + val_addr = ADDR(.sec2); +}