aboutsummaryrefslogtreecommitdiff
path: root/gold
diff options
context:
space:
mode:
authorCary Coutant <ccoutant@gmail.com>2015-06-11 10:17:04 -0700
committerCary Coutant <ccoutant@gmail.com>2015-06-11 13:21:10 -0700
commitdd68f8fa8e2412c5c16380871d8ac5e40909aef6 (patch)
tree7edf3728b35100d172f4e5af0dded1ac7cd87070 /gold
parenta3a0c39166742c9ef9bb5d87ab51320b7f62cb92 (diff)
downloadgdb-dd68f8fa8e2412c5c16380871d8ac5e40909aef6.zip
gdb-dd68f8fa8e2412c5c16380871d8ac5e40909aef6.tar.gz
gdb-dd68f8fa8e2412c5c16380871d8ac5e40909aef6.tar.bz2
Fix bug where SECTIONS clause does not handle compressed debug sections.
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).
Diffstat (limited to 'gold')
-rw-r--r--gold/ChangeLog9
-rw-r--r--gold/layout.cc25
-rw-r--r--gold/layout.h4
-rw-r--r--gold/script-sections.cc7
4 files changed, 33 insertions, 12 deletions
diff --git a/gold/ChangeLog b/gold/ChangeLog
index 60d16d5..4d6cd3d 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -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.
diff --git a/gold/layout.cc b/gold/layout.cc
index 8820fe3..52f5551 100644
--- a/gold/layout.cc
+++ b/gold/layout.cc
@@ -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);
diff --git a/gold/layout.h b/gold/layout.h
index 4e29ba8..7bdaaca 100644
--- a/gold/layout.h
+++ b/gold/layout.h
@@ -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.
diff --git a/gold/script-sections.cc b/gold/script-sections.cc
index 08c31e9..3e377aa 100644
--- a/gold/script-sections.cc
+++ b/gold/script-sections.cc
@@ -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