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: Link .stab and .stabstr sections


The GNU linker links .stab and .stabstr sections via the sh_link field.
I don't know if that was copied from elsewhere or if we just made it up,
but some tools now depend upon it.  I committed this patch to gold to do
the same linking.

Ian


2009-06-23  Ian Lance Taylor  <iant@google.com>

	PR 10219
	* layout.cc (Layout::Layout): Initialize have_stabstr_section_.
	(Layout::make_output_section): Set have_stabstr_section_ if we see
	a .stab*str section.
	(Layout::finalize): Call link_stabs_sections.
	(Layout::link_stabs_sections): New file.
	* layout.h (class Layout): Add have_stabstr_section_ field.
	Declare link_stabs_sections.


Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.128
diff -p -u -r1.128 layout.cc
--- layout.cc	23 Jun 2009 07:04:10 -0000	1.128
+++ layout.cc	24 Jun 2009 00:30:08 -0000
@@ -124,6 +124,7 @@ Layout::Layout(int number_of_input_files
     has_static_tls_(false),
     any_postprocessing_sections_(false),
     resized_signatures_(false),
+    have_stabstr_section_(false),
     incremental_inputs_(NULL)
 {
   // Make space for more than enough segments for a typical file.
@@ -823,6 +824,14 @@ Layout::make_output_section(const char* 
 	}
     }
 
+  // Check for .stab*str sections, as .stab* sections need to link to
+  // them.
+  if (type == elfcpp::SHT_STRTAB
+      && !this->have_stabstr_section_
+      && strncmp(name, ".stab", 5) == 0
+      && strcmp(name + strlen(name) - 3, "str") == 0)
+    this->have_stabstr_section_ = true;
+
   // If we have already attached the sections to segments, then we
   // need to attach this one now.  This happens for sections created
   // directly by the linker.
@@ -1192,6 +1201,7 @@ Layout::finalize(const Input_objects* in
   this->create_gold_note();
   this->create_executable_stack_info(target);
   this->create_build_id();
+  this->link_stabs_sections();
 
   Output_segment* phdr_seg = NULL;
   if (!parameters->options().relocatable() && !parameters->doing_static_link())
@@ -1616,6 +1626,40 @@ Layout::create_build_id()
     }
 }
 
+// If we have both .stabXX and .stabXXstr sections, then the sh_link
+// field of the former should point to the latter.  I'm not sure who
+// started this, but the GNU linker does it, and some tools depend
+// upon it.
+
+void
+Layout::link_stabs_sections()
+{
+  if (!this->have_stabstr_section_)
+    return;
+
+  for (Section_list::iterator p = this->section_list_.begin();
+       p != this->section_list_.end();
+       ++p)
+    {
+      if ((*p)->type() != elfcpp::SHT_STRTAB)
+	continue;
+
+      const char* name = (*p)->name();
+      if (strncmp(name, ".stab", 5) != 0)
+	continue;
+
+      size_t len = strlen(name);
+      if (strcmp(name + len - 3, "str") != 0)
+	continue;
+
+      std::string stab_name(name, len - 3);
+      Output_section* stab_sec;
+      stab_sec = this->find_output_section(stab_name.c_str());
+      if (stab_sec != NULL)
+	stab_sec->set_link_section(*p);
+    }
+}
+
 // Create .gnu_incremental_inputs and .gnu_incremental_strtab sections needed
 // for the next run of incremental linking to check what has changed.
 
Index: layout.h
===================================================================
RCS file: /cvs/src/src/gold/layout.h,v
retrieving revision 1.65
diff -p -u -r1.65 layout.h
--- layout.h	4 Jun 2009 00:43:11 -0000	1.65
+++ layout.h	24 Jun 2009 00:30:09 -0000
@@ -480,6 +480,10 @@ class Layout
   void
   create_build_id();
 
+  // Link .stab and .stabstr sections.
+  void
+  link_stabs_sections();
+
   // Create .gnu_incremental_inputs and .gnu_incremental_strtab sections needed
   // for the next run of incremental linking to check what has changed.
   void
@@ -724,6 +728,8 @@ class Layout
   bool any_postprocessing_sections_;
   // Whether we have resized the signatures_ hash table.
   bool resized_signatures_;
+  // Whether we have created a .stab*str output section.
+  bool have_stabstr_section_;
   // In incremental build, holds information check the inputs and build the
   // .gnu_incremental_inputs section.
   Incremental_inputs* incremental_inputs_;

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