[gold patch] Fix PR gold/12220 where linker script causes internal error with compressed debug sections

Cary Coutant ccoutant@google.com
Mon Nov 15 22:45:00 GMT 2010


PR 12220 is about an internal error in gold when compressed debug
sections are used with a linker script. There were two problems here:
the presence of a SECTIONS clause in the script prevented the linker
from remapping the .zdebug section names properly, and also caused the
linker to calculate the output section size based on the compressed
sizes of the input sections instead of the uncompressed size. This
patch should fix both problems.

Tested on x86_64. OK?

-cary

        PR gold/12220
        * layout.cc (Layout::choose_output_section): Call output_section_name
        even when using a script with a SECTIONS clause.
        (Layout::output_section_name): Don't use standard mappings if a
        SECTIONS clause has been seen.
        * layout.h (Layout::output_section_name): Add parameter.
        * output.cc (Output_section::add_input_section): Use uncompressed
        section size when tracking input sections.
-------------- next part --------------
Index: layout.cc
===================================================================
RCS file: /cvs/src/src/gold/layout.cc,v
retrieving revision 1.186
diff -u -p -r1.186 layout.cc
--- layout.cc	9 Nov 2010 07:56:10 -0000	1.186
+++ layout.cc	15 Nov 2010 22:30:29 -0000
@@ -498,7 +498,9 @@ Layout::choose_output_section(const Relo
   if (!parameters->options().relocatable())
     flags &= ~elfcpp::SHF_LINK_ORDER;
 
-  if (this->script_options_->saw_sections_clause())
+  bool saw_sections_clause = this->script_options_->saw_sections_clause();
+
+  if (saw_sections_clause)
     {
       // We are using a SECTIONS clause, so the output section is
       // chosen based only on the name.
@@ -586,9 +588,8 @@ Layout::choose_output_section(const Relo
 
   size_t len = strlen(name);
   if (is_input_section
-      && !this->script_options_->saw_sections_clause()
       && !parameters->options().relocatable())
-    name = Layout::output_section_name(name, &len);
+    name = Layout::output_section_name(name, &len, saw_sections_clause);
 
   Stringpool::Key name_key;
   name = this->namepool_.add_with_length(name, len, true, &name_key);
@@ -3874,10 +3875,12 @@ const int Layout::section_name_mapping_c
 
 // Choose the output section name to use given an input section name.
 // Set *PLEN to the length of the name.  *PLEN is initialized to the
-// length of NAME.
+// length of NAME.  If SAW_SECTIONS_CLAUSE is TRUE, we do not apply
+// the standard mappings, but we do map compressed debug section names.
 
 const char*
-Layout::output_section_name(const char* name, size_t* plen)
+Layout::output_section_name(const char* name, size_t* plen,
+			    bool saw_sections_clause)
 {
   // gcc 4.3 generates the following sorts of section names when it
   // needs a section name specific to a function:
@@ -3914,13 +3917,16 @@ Layout::output_section_name(const char* 
   // not found in the table, we simply use it as the output section
   // name.
 
-  const Section_name_mapping* psnm = section_name_mapping;
-  for (int i = 0; i < section_name_mapping_count; ++i, ++psnm)
+  if (!saw_sections_clause)
     {
-      if (strncmp(name, psnm->from, psnm->fromlen) == 0)
+      const Section_name_mapping* psnm = section_name_mapping;
+      for (int i = 0; i < section_name_mapping_count; ++i, ++psnm)
 	{
-	  *plen = psnm->tolen;
-	  return psnm->to;
+	  if (strncmp(name, psnm->from, psnm->fromlen) == 0)
+	    {
+	      *plen = psnm->tolen;
+	      return psnm->to;
+	    }
 	}
     }
 
Index: layout.h
===================================================================
RCS file: /cvs/src/src/gold/layout.h,v
retrieving revision 1.86
diff -u -p -r1.86 layout.h
--- layout.h	25 Aug 2010 08:36:54 -0000	1.86
+++ layout.h	15 Nov 2010 22:30:29 -0000
@@ -876,7 +876,7 @@ class Layout
   // name.  Set *PLEN to the length of the name.  *PLEN must be
   // initialized to the length of NAME.
   static const char*
-  output_section_name(const char* name, size_t* plen);
+  output_section_name(const char* name, size_t* plen, bool);
 
   // Return the number of allocated output sections.
   size_t
Index: output.cc
===================================================================
RCS file: /cvs/src/src/gold/output.cc,v
retrieving revision 1.137
diff -u -p -r1.137 output.cc
--- output.cc	29 Oct 2010 20:49:20 -0000	1.137
+++ output.cc	15 Nov 2010 22:30:29 -0000
@@ -2165,7 +2165,7 @@ Output_section::add_input_section(Layout
       || parameters->target().may_relax()
       || parameters->options().section_ordering_file())
     {
-      Input_section isecn(object, shndx, shdr.get_sh_size(), addralign);
+      Input_section isecn(object, shndx, input_section_size, addralign);
       if (parameters->options().section_ordering_file())
         {
           unsigned int section_order_index =


More information about the Binutils mailing list