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: Don't try to handle a late SECTIONS clause


PR 10979 shows a gold error building arj.  It turns out that arj
passes in a linker script as an input file.  The linker script
is just

SECTIONS
{
 /DISCARD/ : { *(.comment) *(.note) *(.stab) *(.stabstr) }
}

The problem is that once gold sees a SECTIONS clause, it more or less
has to go through the linker script processing.  When it sees a
SECTIONS clause in an input file, it has already handled crt1.o and
friends.  That fails, because they require special handling when using
a linker script.

I thought about different ways to tackle this, but I finally decided
to simply forbid it.  I committed this patch to give a sensible error
for this case, rather than simply crashing.

Ian


2009-12-30  Ian Lance Taylor  <iant@google.com>

	PR 10979
	* script.cc (read_input_script): If we see a new SECTIONS clause,
	and we have added an input section, give an error.
	* layout.h (class Layout): Add have_added_input_section function.
	Add have_added_input_section_ field.
	* layout.cc (Layout::Layout): Initialize
	have_added_input_section_.
	(Layout::layout): Set have_added_input_section_.
	(Layout::layout_eh_frame): Likewise.


Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.153
diff -p -u -r1.153 layout.cc
--- layout.cc	30 Dec 2009 07:45:32 -0000	1.153
+++ layout.cc	31 Dec 2009 03:46:57 -0000
@@ -192,6 +192,7 @@ Layout::Layout(int number_of_input_files
     debug_info_(NULL),
     group_signatures_(),
     output_file_size_(-1),
+    have_added_input_section_(false),
     sections_are_attached_(false),
     input_requires_executable_stack_(false),
     input_with_gnu_stack_note_(false),
@@ -610,6 +611,7 @@ Layout::layout(Sized_relobj<size, big_en
 
   *off = os->add_input_section(object, shndx, name, shdr, reloc_shndx,
 			       this->script_options_->saw_sections_clause());
+  this->have_added_input_section_ = true;
 
   return os;
 }
@@ -818,6 +820,7 @@ Layout::layout_eh_frame(Sized_relobj<siz
       bool saw_sections_clause = this->script_options_->saw_sections_clause();
       *off = os->add_input_section(object, shndx, name, shdr, reloc_shndx,
 				   saw_sections_clause);
+      this->have_added_input_section_ = true;
     }
 
   return os;
Index: layout.h
===================================================================
RCS file: /cvs/src/src/gold/layout.h,v
retrieving revision 1.75
diff -p -u -r1.75 layout.h
--- layout.h	30 Dec 2009 06:57:17 -0000	1.75
+++ layout.h	31 Dec 2009 03:46:57 -0000
@@ -433,6 +433,11 @@ class Layout
   is_linkonce(const char* name)
   { return strncmp(name, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0; }
 
+  // Whether we have added an input section.
+  bool
+  have_added_input_section() const
+  { return this->have_added_input_section_; }
+
   // Return true if a section is a debugging section.
   static inline bool
   is_debug_info_section(const char* name)
@@ -990,6 +995,8 @@ class Layout
   Group_signatures group_signatures_;
   // The size of the output file.
   off_t output_file_size_;
+  // Whether we have added an input section to an output section.
+  bool have_added_input_section_;
   // Whether we have attached the sections to the segments.
   bool sections_are_attached_;
   // Whether we have seen an object file marked to require an
Index: script.cc
===================================================================
RCS file: /cvs/src/src/gold/script.cc,v
retrieving revision 1.63
diff -p -u -r1.63 script.cc
--- script.cc	30 Dec 2009 22:35:48 -0000	1.63
+++ script.cc	31 Dec 2009 03:46:58 -0000
@@ -1398,6 +1398,9 @@ read_input_script(Workqueue* workqueue, 
 			 &lex,
 			 input_file->will_search_for());
 
+  bool old_saw_sections_clause =
+    layout->script_options()->saw_sections_clause();
+
   if (yyparse(&closure) != 0)
     {
       if (closure.found_incompatible_target())
@@ -1411,6 +1414,12 @@ read_input_script(Workqueue* workqueue, 
       return false;
     }
 
+  if (!old_saw_sections_clause
+      && layout->script_options()->saw_sections_clause()
+      && layout->have_added_input_section())
+    gold_error(_("%s: SECTIONS seen after other input files; try -T/--script"),
+	       input_file->filename().c_str());
+
   if (!closure.saw_inputs())
     return true;
 

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