Fix bug where SECTIONS clause does not handle compressed debug sections.
authorCary Coutant <ccoutant@gmail.com>
Thu, 11 Jun 2015 17:17:04 +0000 (10:17 -0700)
committerCary Coutant <ccoutant@gmail.com>
Thu, 11 Jun 2015 20:21:10 +0000 (13:21 -0700)
When laying out .debug_* sections, we translate the names of compressed
debug sections that start with ".zdebug", but when processing input
section specs in a linker script, we do not handle the translation there.
This results in an internal error as reported in PR 17731.

gold/
PR gold/17731
* layout.cc (corresponding_uncompressed_section_name): New function.
(Layout::choose_output_section): Call it.
* layout.h (corresponding_uncompressed_section_name): New function.
* script-sections.cc (Input_section_info::set_section_name): Check
for compressed debug section (.zdebug style).

gold/ChangeLog
gold/layout.cc
gold/layout.h
gold/script-sections.cc

index 60d16d5..4d6cd3d 100644 (file)
@@ -1,3 +1,12 @@
+2015-06-11  Cary Coutant  <ccoutant@gmail.com>
+
+       PR gold/17731
+       * layout.cc (corresponding_uncompressed_section_name): New function.
+       (Layout::choose_output_section): Call it.
+       * layout.h (corresponding_uncompressed_section_name): New function.
+       * script-sections.cc (Input_section_info::set_section_name): Check
+       for compressed debug section (.zdebug style).
+
 2015-06-11  Jing Yu  <jingyu@google.com>
 
        * testsuite/Makefile.am: Add -O0 for script_test_12 test.
index 8820fe3..52f5551 100644 (file)
@@ -636,6 +636,15 @@ is_compressed_debug_section(const char* secname)
   return (is_prefix_of(".zdebug", secname));
 }
 
+std::string
+corresponding_uncompressed_section_name(std::string secname)
+{
+  gold_assert(secname[0] == '.' && secname[1] == 'z');
+  std::string ret(".");
+  ret.append(secname, 2, std::string::npos);
+  return ret;
+}
+
 // Whether to include this section in the link.
 
 template<int size, bool big_endian>
@@ -1021,19 +1030,16 @@ Layout::choose_output_section(const Relobj* relobj, const char* name,
   // FIXME: Handle SHF_OS_NONCONFORMING somewhere.
 
   size_t len = strlen(name);
-  char* uncompressed_name = NULL;
+  std::string uncompressed_name;
 
   // Compressed debug sections should be mapped to the corresponding
   // uncompressed section.
   if (is_compressed_debug_section(name))
     {
-      uncompressed_name = new char[len];
-      uncompressed_name[0] = '.';
-      gold_assert(name[0] == '.' && name[1] == 'z');
-      strncpy(&uncompressed_name[1], &name[2], len - 2);
-      uncompressed_name[len - 1] = '\0';
-      len -= 1;
-      name = uncompressed_name;
+      uncompressed_name =
+         corresponding_uncompressed_section_name(std::string(name, len));
+      name = uncompressed_name.c_str();
+      len = uncompressed_name.length();
     }
 
   // Turn NAME from the name of the input section into the name of the
@@ -1051,9 +1057,6 @@ Layout::choose_output_section(const Relobj* relobj, const char* name,
   Stringpool::Key name_key;
   name = this->namepool_.add_with_length(name, len, true, &name_key);
 
-  if (uncompressed_name != NULL)
-    delete[] uncompressed_name;
-
   // Find or make the output section.  The output section is selected
   // based on the section name, type, and flags.
   return this->get_output_section(name, name_key, type, flags, order, is_relro);
index 4e29ba8..7bdaaca 100644 (file)
@@ -66,6 +66,10 @@ struct Timespec;
 extern bool
 is_compressed_debug_section(const char* secname);
 
+// Return the name of the corresponding uncompressed debug section.
+extern std::string
+corresponding_uncompressed_section_name(std::string secname);
+
 // Maintain a list of free space within a section, segment, or file.
 // Used for incremental update links.
 
index 08c31e9..3e377aa 100644 (file)
@@ -1457,7 +1457,12 @@ class Input_section_info
   // Set the section name.
   void
   set_section_name(const std::string name)
-  { this->section_name_ = name; }
+  {
+    if (is_compressed_debug_section(name.c_str()))
+      this->section_name_ = corresponding_uncompressed_section_name(name);
+    else
+      this->section_name_ = name;
+  }
 
   // Return the section size.
   uint64_t