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: Permit assignment to dot outside of SECTIONS


The Linux kernel build uses linker scripts with assignments to the dot
symbol outside of the SECTIONS clause in order to implement asserts.
Although an assignment to dot outside of SECTIONS, apparently this was
required in order to use assertions in older versions of the GNU
linker.  The GNU linker essentially treats assignments to dot outside
of SECTIONS as though they occurred within SECTIONS.  I committed this
patch to make gold act the same way.

Ian


2009-10-15  Ian Lance Taylor  <iant@google.com>

	* script.cc (Script_options::add_symbol_assignment): Always add a
	dot assginment to script_sections_.
	* script-sections.cc (Script_sections::add_dot_assignment):
	Initialize if necessary.


Index: script-sections.cc
===================================================================
RCS file: /cvs/src/src/gold/script-sections.cc,v
retrieving revision 1.23
diff -p -u -r1.23 script-sections.cc
--- script-sections.cc	16 Oct 2009 05:00:29 -0000	1.23
+++ script-sections.cc	16 Oct 2009 05:18:40 -0000
@@ -2540,6 +2540,15 @@ Script_sections::add_dot_assignment(Expr
     this->output_section_->add_dot_assignment(val);
   else
     {
+      // The GNU linker permits assignments to . to appears outside of
+      // a SECTIONS clause, and treats it as appearing inside, so
+      // sections_elements_ may be NULL here.
+      if (this->sections_elements_ == NULL)
+	{
+	  this->sections_elements_ = new Sections_elements;
+	  this->saw_sections_clause_ = true;
+	}
+
       Sections_element* p = new Sections_element_dot_assignment(val);
       this->sections_elements_->push_back(p);
     }
Index: script.cc
===================================================================
RCS file: /cvs/src/src/gold/script.cc,v
retrieving revision 1.57
diff -p -u -r1.57 script.cc
--- script.cc	10 Oct 2009 07:39:04 -0000	1.57
+++ script.cc	16 Oct 2009 05:18:41 -0000
@@ -1,6 +1,6 @@
 // script.cc -- handle linker scripts for gold.
 
-// Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
 // Written by Ian Lance Taylor <iant@google.com>.
 
 // This file is part of gold.
@@ -1070,10 +1070,11 @@ Script_options::add_symbol_assignment(co
     {
       if (provide || hidden)
 	gold_error(_("invalid use of PROVIDE for dot symbol"));
-      if (!this->script_sections_.in_sections_clause())
-	gold_error(_("invalid assignment to dot outside of SECTIONS"));
-      else
-	this->script_sections_.add_dot_assignment(value);
+
+      // The GNU linker permits assignments to dot outside of SECTIONS
+      // clauses and treats them as occurring inside, so we don't
+      // check in_sections_clause here.
+      this->script_sections_.add_dot_assignment(value);
     }
 }
 

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