aboutsummaryrefslogtreecommitdiff
path: root/gold/layout.cc
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/layout.cc
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/layout.cc')
-rw-r--r--gold/layout.cc25
1 files changed, 14 insertions, 11 deletions
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);