Fix forced allocation of common (-d) during -r links.
authorCary Coutant <ccoutant@gmail.com>
Mon, 19 Dec 2016 18:37:23 +0000 (10:37 -0800)
committerCary Coutant <ccoutant@gmail.com>
Mon, 19 Dec 2016 18:37:34 +0000 (10:37 -0800)
If the .bss section has other data in it besides common allocations,
gold was subtracting the wrong section start address from the symbol
value.

gold/
PR gold/20976
* symtab.cc (Symbol_table::sized_write_globals): Use address of
output section, not input section.
* testsuite/Makefile.am (pr20976): New test case.
* testsuite/Makefile.in: Regenerate.
* testsuite/pr20976.c: New source file.

gold/ChangeLog
gold/symtab.cc
gold/testsuite/Makefile.am
gold/testsuite/Makefile.in
gold/testsuite/pr20976.c [new file with mode: 0644]

index b40f7b8e20a5ffb7e9236930f73747a2ffbdeb59..a9ead08170dbced87bfdc75d661f9df643f03f6f 100644 (file)
@@ -1,3 +1,12 @@
+2016-12-19  Cary Coutant  <ccoutant@gmail.com>
+
+       PR gold/20976
+       * symtab.cc (Symbol_table::sized_write_globals): Use address of
+       output section, not input section.
+       * testsuite/Makefile.am (pr20976): New test case.
+       * testsuite/Makefile.in: Regenerate.
+       * testsuite/pr20976.c: New source file.
+
 2016-12-13  Cary Coutant  <ccoutant@gmail.com>
 
        PR gold/20749
index c872f47d38638540278e1dcc05caee1195d88f5d..6865190f880d3e4ce027c6b025d281ab5402788a 100644 (file)
@@ -3111,7 +3111,11 @@ Symbol_table::sized_write_globals(const Stringpool* sympool,
            // In object files symbol values are section
            // relative.
            if (parameters->options().relocatable())
-             sym_value -= od->address();
+             {
+               Output_section* os = od->output_section();
+               gold_assert(os != NULL);
+               sym_value -= os->address();
+             }
          }
          break;
 
index 4d0aaa1cb9b96490af4dc7f2dc00152573c642ca..ab743c714712d2dd3096bb5d0c1fae348931dbde 100644 (file)
@@ -2923,6 +2923,13 @@ defsym_test: defsym_test.o gcctestdir/ld
 defsym_test.o: defsym_test.c
        $(COMPILE) -c -o $@ $<
 
+# Test that the -d option (force common allocation) works correctly.
+check_PROGRAMS += pr20976
+pr20976: pr20976-d.o gcctestdir/ld
+       $(LINK) -Bgcctestdir/ pr20976-d.o
+pr20976-d.o: pr20976.o gcctestdir/ld
+       gcctestdir/ld -r -d -o $@ pr20976.o
+
 # End-to-end incremental linking tests.
 # Incremental linking is currently supported only on the x86_64 target.
 
index a70322c639f6a1c6aaad114ae001c43f7e7dd6ca..5de841adb9b0351a859fe9ed86e2f180cf3d9e94 100644 (file)
@@ -718,11 +718,13 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
 # Test that __ehdr_start is defined correctly when used with a linker script.
 
 # Test that __ehdr_start is not overridden when supplied by the user.
+
+# Test that the -d option (force common allocation) works correctly.
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am__append_71 = start_lib_test \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_1 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_2 \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_3 \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_5
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_5 pr20976
 
 # Test that --gdb-index functions correctly without gcc-generated pubnames.
 
@@ -1191,7 +1193,8 @@ libgoldtest_a_OBJECTS = $(am_libgoldtest_a_OBJECTS)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_1$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_2$(EXEEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_3$(EXEEXT) \
-@GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_5$(EXEEXT)
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ ehdr_start_test_5$(EXEEXT) \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ pr20976$(EXEEXT)
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@am__EXEEXT_40 = incremental_test_2$(EXEEXT) \
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_test_3$(EXEEXT) \
 @DEFAULT_TARGET_X86_64_TRUE@@GCC_TRUE@@NATIVE_LINKER_TRUE@     incremental_test_4$(EXEEXT) \
@@ -1917,6 +1920,13 @@ pr20308d_test_LINK = $(CCLD) $(pr20308d_test_CFLAGS) $(CFLAGS) \
 pr20308e_test_OBJECTS = $(am_pr20308e_test_OBJECTS)
 pr20308e_test_LINK = $(CCLD) $(pr20308e_test_CFLAGS) $(CFLAGS) \
        $(pr20308e_test_LDFLAGS) $(LDFLAGS) -o $@
+pr20976_SOURCES = pr20976.c
+pr20976_OBJECTS = pr20976.$(OBJEXT)
+pr20976_LDADD = $(LDADD)
+pr20976_DEPENDENCIES = libgoldtest.a ../libgold.a \
+       ../../libiberty/libiberty.a $(am__DEPENDENCIES_1) \
+       $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
+       $(am__DEPENDENCIES_1)
 @GCC_TRUE@@NATIVE_LINKER_TRUE@am_protected_1_OBJECTS =  \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_main_1.$(OBJEXT) \
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ protected_main_2.$(OBJEXT) \
@@ -2381,7 +2391,7 @@ SOURCES = $(libgoldtest_a_SOURCES) basic_pic_test.c basic_pie_test.c \
        $(pr20216c_test_SOURCES) $(pr20216d_test_SOURCES) \
        $(pr20216e_test_SOURCES) $(pr20308a_test_SOURCES) \
        $(pr20308b_test_SOURCES) $(pr20308c_test_SOURCES) \
-       $(pr20308d_test_SOURCES) $(pr20308e_test_SOURCES) \
+       $(pr20308d_test_SOURCES) $(pr20308e_test_SOURCES) pr20976.c \
        $(protected_1_SOURCES) $(protected_2_SOURCES) \
        $(relro_now_test_SOURCES) $(relro_script_test_SOURCES) \
        $(relro_strip_test_SOURCES) $(relro_test_SOURCES) \
@@ -4050,6 +4060,12 @@ pr20308d_test$(EXEEXT): $(pr20308d_test_OBJECTS) $(pr20308d_test_DEPENDENCIES) $
 pr20308e_test$(EXEEXT): $(pr20308e_test_OBJECTS) $(pr20308e_test_DEPENDENCIES) $(EXTRA_pr20308e_test_DEPENDENCIES) 
        @rm -f pr20308e_test$(EXEEXT)
        $(pr20308e_test_LINK) $(pr20308e_test_OBJECTS) $(pr20308e_test_LDADD) $(LIBS)
+@GCC_FALSE@pr20976$(EXEEXT): $(pr20976_OBJECTS) $(pr20976_DEPENDENCIES) $(EXTRA_pr20976_DEPENDENCIES) 
+@GCC_FALSE@    @rm -f pr20976$(EXEEXT)
+@GCC_FALSE@    $(LINK) $(pr20976_OBJECTS) $(pr20976_LDADD) $(LIBS)
+@NATIVE_LINKER_FALSE@pr20976$(EXEEXT): $(pr20976_OBJECTS) $(pr20976_DEPENDENCIES) $(EXTRA_pr20976_DEPENDENCIES) 
+@NATIVE_LINKER_FALSE@  @rm -f pr20976$(EXEEXT)
+@NATIVE_LINKER_FALSE@  $(LINK) $(pr20976_OBJECTS) $(pr20976_LDADD) $(LIBS)
 protected_1$(EXEEXT): $(protected_1_OBJECTS) $(protected_1_DEPENDENCIES) $(EXTRA_protected_1_DEPENDENCIES) 
        @rm -f protected_1$(EXEEXT)
        $(protected_1_LINK) $(protected_1_OBJECTS) $(protected_1_LDADD) $(LIBS)
@@ -4409,6 +4425,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pr20308d_test-pr20308_def.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pr20308d_test-pr20308_main.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pr20308e_test-pr20308_main.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pr20976.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_3.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_1.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/protected_main_2.Po@am__quote@
@@ -5583,6 +5600,8 @@ ehdr_start_test_3.log: ehdr_start_test_3$(EXEEXT)
        @p='ehdr_start_test_3$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 ehdr_start_test_5.log: ehdr_start_test_5$(EXEEXT)
        @p='ehdr_start_test_5$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+pr20976.log: pr20976$(EXEEXT)
+       @p='pr20976$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 incremental_test_2.log: incremental_test_2$(EXEEXT)
        @p='incremental_test_2$(EXEEXT)'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
 incremental_test_3.log: incremental_test_3$(EXEEXT)
@@ -7138,6 +7157,10 @@ uninstall-am:
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,--defsym=bar=foo defsym_test.o
 @GCC_TRUE@@NATIVE_LINKER_TRUE@defsym_test.o: defsym_test.c
 @GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -c -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@pr20976: pr20976-d.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ pr20976-d.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@pr20976-d.o: pr20976.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ gcctestdir/ld -r -d -o $@ pr20976.o
 
 # End-to-end incremental linking tests.
 # Incremental linking is currently supported only on the x86_64 target.
diff --git a/gold/testsuite/pr20976.c b/gold/testsuite/pr20976.c
new file mode 100644 (file)
index 0000000..353e749
--- /dev/null
@@ -0,0 +1,34 @@
+/* pr20976.c -- test forced common allocation
+
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   Written by Cary Coutant <ccoutant@gmail.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 test checks that forced common allocation (-d) with -r
+   produces the correct result when the .bss section contains
+   other allocated data besides common symbols. */
+
+int a = 0;
+int b;
+
+int main(void)
+{
+  a = 1;
+  return b;
+}
This page took 0.050824 seconds and 4 git commands to generate.