This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PATCH COMMITTED: Fix alignment of copied symbols


I discovered that copied symbols always use the alignment of the first
copied symbol seen.  If later copied symbols require a larger
alignment, that is not reflected in the dynbss section.  This is a bug
in the Output_section::Input_section class when used with an
Output_section_data: it always uses the initial alignment rather than
the final one.

I committed this patch to fix the bug, along with a test case.

Ian


2008-06-17  Ian Lance Taylor  <iant@google.com>

	* output.h (Output_section::Input_section): Initialize p2align_ to
	zero for Output_section_data constructors.
	(Output_section::Input_section::addralign): If not an input
	section, return the alignment of the Output_section_data.
	* testsuite/copy_test.cc: New file.
	* testsuite/copy_test_1.cc: New file.
	* testsuite/copy_test_2.cc: New file.
	* testsuite/Makefile.am (check_PROGRAMS): Add copy_test.
	(copy_test_SOURCES, copy_test_DEPENDENCIES): New variables.
	(copy_test_LDFLAGS, copy_test_LDADD): New variables.
	(copy_test_1_pic.o, copy_test_1.so): New targets.
	(copy_test_2_pic.o, copy_test_2.so): New targets.
	* testsuite/Makefile.in: Rebuild.


Index: output.h
===================================================================
RCS file: /cvs/src/src/gold/output.h,v
retrieving revision 1.72
diff -p -u -r1.72 output.h
--- output.h	21 May 2008 21:37:44 -0000	1.72
+++ output.h	18 Jun 2008 04:31:37 -0000
@@ -2443,8 +2443,7 @@ class Output_section : public Output_dat
 
     // For a non-merge output section.
     Input_section(Output_section_data* posd)
-      : shndx_(OUTPUT_SECTION_CODE),
-	p2align_(ffsll(static_cast<long long>(posd->addralign())))
+      : shndx_(OUTPUT_SECTION_CODE), p2align_(0)
     {
       this->u1_.data_size = 0;
       this->u2_.posd = posd;
@@ -2455,7 +2454,7 @@ class Output_section : public Output_dat
       : shndx_(is_string
 	       ? MERGE_STRING_SECTION_CODE
 	       : MERGE_DATA_SECTION_CODE),
-	p2align_(ffsll(static_cast<long long>(posd->addralign())))
+	p2align_(0)
     {
       this->u1_.entsize = entsize;
       this->u2_.posd = posd;
@@ -2465,6 +2464,8 @@ class Output_section : public Output_dat
     uint64_t
     addralign() const
     {
+      if (!this->is_input_section())
+	return this->u2_.posd->addralign();
       return (this->p2align_ == 0
 	      ? 0
 	      : static_cast<uint64_t>(1) << (this->p2align_ - 1));
Index: testsuite/Makefile.am
===================================================================
RCS file: /cvs/src/src/gold/testsuite/Makefile.am,v
retrieving revision 1.70
diff -p -u -r1.70 Makefile.am
--- testsuite/Makefile.am	20 May 2008 04:00:47 -0000	1.70
+++ testsuite/Makefile.am	18 Jun 2008 04:31:37 -0000
@@ -428,6 +428,20 @@ weak_alias_test_4_pic.o: weak_alias_test
 weak_alias_test_4.so: weak_alias_test_4_pic.o
 	$(CXXLINK) -Bgcctestdir/ -shared weak_alias_test_4_pic.o
 
+check_PROGRAMS += copy_test
+copy_test_SOURCES = copy_test.cc
+copy_test_DEPENDENCIES = gcctestdir/ld copy_test_1.so copy_test_2.so
+copy_test_LDFLAGS = -Bgcctestdir/ -Wl,-R,.
+copy_test_LDADD = copy_test_1.so copy_test_2.so
+copy_test_1_pic.o: copy_test_1.cc
+	$(CXXCOMPILE) -c -fpic -o $@ $<
+copy_test_1.so: gcctestdir/ld copy_test_1_pic.o
+	$(CXXLINK) -Bgcctestdir/ -shared copy_test_1_pic.o
+copy_test_2_pic.o: copy_test_2.cc
+	$(CXXCOMPILE) -c -fpic -o $@ $<
+copy_test_2.so: gcctestdir/ld copy_test_2_pic.o
+	$(CXXLINK) -Bgcctestdir/ -shared copy_test_2_pic.o
+
 if TLS
 
 check_PROGRAMS += tls_test
Index: testsuite/copy_test.cc
===================================================================
RCS file: testsuite/copy_test.cc
diff -N testsuite/copy_test.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/copy_test.cc	18 Jun 2008 04:31:37 -0000
@@ -0,0 +1,43 @@
+// copy_test.cc -- test copy relocs for gold
+
+// Copyright 2008 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@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.
+
+#include <cassert>
+#include <stdint.h>
+
+// Misalign the BSS section.
+static char c;
+
+// From copy_test_1.cc.
+extern char b;
+
+// From copy_test_2.cc.
+extern long long l;
+
+int
+main()
+{
+  assert(c == 0);
+  assert(b == 1);
+  assert(l == 2);
+  assert((reinterpret_cast<uintptr_t>(&l) & 0x7) == 0);
+  return 0;
+}
Index: testsuite/copy_test_1.cc
===================================================================
RCS file: testsuite/copy_test_1.cc
diff -N testsuite/copy_test_1.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/copy_test_1.cc	18 Jun 2008 04:31:37 -0000
@@ -0,0 +1,23 @@
+// copy_test_1.cc -- test copy relocs for gold
+
+// Copyright 2008 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@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.
+
+char b = 1;
Index: testsuite/copy_test_2.cc
===================================================================
RCS file: testsuite/copy_test_2.cc
diff -N testsuite/copy_test_2.cc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/copy_test_2.cc	18 Jun 2008 04:31:37 -0000
@@ -0,0 +1,23 @@
+// copy_test_2.cc -- test copy relocs variables for gold
+
+// Copyright 2008 Free Software Foundation, Inc.
+// Written by Ian Lance Taylor <iant@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.
+
+long long l = 2;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]