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]

gold patch committed: Fix symbol aliasing in linker script


Paul Pluzhnikov found a problem building the Linux kernel with gold.
The Linux linker script has this outside of a SECTIONS clause:
    jiffies_64 = jiffies;
Inside the SECTIONS clause, jiffies is defined in terms of ADDR.  With
GNU ld, jiffies_64 will be set to the final value of jiffies.  With
gold, jiffies_64 was being set to the value of jiffies before it was
set using ADDR.  In other words, jiffies_64 was set to zero, rather
than the value of jiffies.

Fortunately the fix is simple.  I have committed this patch, which
includes a test case.

Ian


2008-07-29  Ian Lance Taylor  <iant@google.com>

	* script.cc (Script_options::finalize_symbols): Finalize SECTIONS
	symbols before other symbols.
	* testsuite/script_test_2.cc (test_addr): Declare.
	(test_addr_alias): Declare.
	(main): Check that test_addr and test_addr_alias have the right
	values. 
	* testsuite/script_test_2.t: Define test_addr_alias and
	test_addr.


Index: script.cc
===================================================================
RCS file: /cvs/src/src/gold/script.cc,v
retrieving revision 1.45
diff -p -u -r1.45 script.cc
--- script.cc	23 Jul 2008 23:44:02 -0000	1.45
+++ script.cc	29 Jul 2008 22:56:26 -0000
@@ -1109,6 +1109,12 @@ Script_options::add_symbols_to_table(Sym
 void
 Script_options::finalize_symbols(Symbol_table* symtab, const Layout* layout)
 {
+  // We finalize the symbols defined in SECTIONS first, because they
+  // are the ones which may have changed.  This way if symbol outside
+  // SECTIONS are defined in terms of symbols inside SECTIONS, they
+  // will get the right value.
+  this->script_sections_.finalize_symbols(symtab, layout);
+
   for (Symbol_assignments::iterator p = this->symbol_assignments_.begin();
        p != this->symbol_assignments_.end();
        ++p)
@@ -1118,8 +1124,6 @@ Script_options::finalize_symbols(Symbol_
        p != this->assertions_.end();
        ++p)
     (*p)->check(symtab, layout);
-
-  this->script_sections_.finalize_symbols(symtab, layout);
 }
 
 // Set section addresses.  We set all the symbols which have absolute
Index: testsuite/script_test_2.cc
===================================================================
RCS file: /cvs/src/src/gold/testsuite/script_test_2.cc,v
retrieving revision 1.3
diff -p -u -r1.3 script_test_2.cc
--- testsuite/script_test_2.cc	11 Apr 2008 20:44:52 -0000	1.3
+++ testsuite/script_test_2.cc	29 Jul 2008 22:56:26 -0000
@@ -35,6 +35,8 @@ extern char end_data[];
 extern char start_fill[];
 extern char end_fill[];
 extern char end_test_area[];
+extern char test_addr[];
+extern char test_addr_alias[];
 
 int
 main(int, char**)
@@ -66,4 +68,7 @@ main(int, char**)
   assert(end_fill == start_fill + 8);
 
   assert(end_test_area == end_fill);
+
+  assert(test_addr == start_test_area_1);
+  assert(test_addr_alias == test_addr);
 }
Index: testsuite/script_test_2.t
===================================================================
RCS file: /cvs/src/src/gold/testsuite/script_test_2.t,v
retrieving revision 1.2
diff -p -u -r1.2 script_test_2.t
--- testsuite/script_test_2.t	12 Feb 2008 00:15:40 -0000	1.2
+++ testsuite/script_test_2.t	29 Jul 2008 22:56:26 -0000
@@ -20,6 +20,8 @@
    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
    MA 02110-1301, USA.  */
 
+test_addr_alias = test_addr;
+
 SECTIONS
 {
   /* With luck this will work everywhere.  */
@@ -62,4 +64,5 @@ SECTIONS
     end_fill = .;
   }
   end_test_area = .;
+  test_addr = ADDR(.gold_test);
 }

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