From: Cary Coutant Date: Thu, 11 Jun 2015 17:17:04 +0000 (-0700) Subject: Fix bug where SECTIONS clause does not handle compressed debug sections. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=dd68f8fa8e2412c5c16380871d8ac5e40909aef6;p=binutils-gdb.git 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). --- diff --git a/gold/ChangeLog b/gold/ChangeLog index 60d16d55a96..4d6cd3da847 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,3 +1,12 @@ +2015-06-11 Cary Coutant + + 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 * testsuite/Makefile.am: Add -O0 for script_test_12 test. diff --git a/gold/layout.cc b/gold/layout.cc index 8820fe39768..52f55516b97 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 @@ -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 4e29ba8de4e..7bdaaca28d7 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 08c31e99795..3e377aa3826 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