diff options
author | Cary Coutant <ccoutant@google.com> | 2014-07-02 09:39:41 -0700 |
---|---|---|
committer | Cary Coutant <ccoutant@google.com> | 2014-09-02 14:49:18 -0700 |
commit | 9860cbcfb60bdae2f9800e6a6ea5f21ef1507d08 (patch) | |
tree | da0a996a6e7e26eec815fc647283fe878fe23e7a /gold/output.cc | |
parent | df7e526582809b829ee8651a1315a17627cfea4d (diff) | |
download | gdb-9860cbcfb60bdae2f9800e6a6ea5f21ef1507d08.zip gdb-9860cbcfb60bdae2f9800e6a6ea5f21ef1507d08.tar.gz gdb-9860cbcfb60bdae2f9800e6a6ea5f21ef1507d08.tar.bz2 |
Fix problem with optimization of .eh_frame section and --sort-section option.
When --sort-section=name is used, gold will sort the linker-generated contents
of .eh_frame (after optimization) after the endcap provided by crtendS.o.
This causes two problems: the .eh_frame_hdr section is generated assuming that
the optimized .eh_frame contents will be placed at the very beginning of the
section, and the endcap no longer appears at the end of the section.
This patch fixes the first problem by adjusting FDE offsets to take into account
the actual starting offset within the output section, and fixes the second
problem by sorting linker-generated (Output_section_data) sections based on the
name of the output section.
gold/
PR gold/17005
* ehframe.cc (Fde::write): Add output_offset parameter.
(Cie::write): Likewise.
(Eh_frame::set_final_data_size): Account for offset within output
section.
(Eh_frame::do_sized_write): Likewise.
* ehframe.h (Fde::write): Add output_offset parameter.
(Cie::write): Likewise.
* output.cc (Output_section::Input_section_sort_entry): Remove
section_has_name_; add output_section_name parameter. Use
output section name for non-input sections.
(Output_section::Input_section_sort_entry::section_has_name): Remove.
(Output_section::Input_section_sort_entry::section_has_name_): Remove.
(Output_section::Input_section_sort_compare): Remove logic for
sections without names.
(Output_section::Input_section_sort_init_fini_compare): Likewise.
(Output_section::Input_section_sort_section_prefix_special_ordering_compare):
Likewise.
(Output_section::Input_section_sort_section_name_compare): Likewise.
Diffstat (limited to 'gold/output.cc')
-rw-r--r-- | gold/output.cc | 73 |
1 files changed, 14 insertions, 59 deletions
diff --git a/gold/output.cc b/gold/output.cc index c078fbb..3361991a 100644 --- a/gold/output.cc +++ b/gold/output.cc @@ -3206,18 +3206,17 @@ class Output_section::Input_section_sort_entry { public: Input_section_sort_entry() - : input_section_(), index_(-1U), section_has_name_(false), - section_name_() + : input_section_(), index_(-1U), section_name_() { } Input_section_sort_entry(const Input_section& input_section, unsigned int index, - bool must_sort_attached_input_sections) - : input_section_(input_section), index_(index), - section_has_name_(input_section.is_input_section() - || input_section.is_relaxed_input_section()) + bool must_sort_attached_input_sections, + const char* output_section_name) + : input_section_(input_section), index_(index), section_name_() { - if (this->section_has_name_ + if ((input_section.is_input_section() + || input_section.is_relaxed_input_section()) && must_sort_attached_input_sections) { // This is only called single-threaded from Layout::finalize, @@ -3233,6 +3232,12 @@ class Output_section::Input_section_sort_entry // Layout::layout if this becomes a speed problem. this->section_name_ = obj->section_name(input_section.shndx()); } + else if (input_section.is_output_section_data() + && must_sort_attached_input_sections) + { + // For linker-generated sections, use the output section name. + this->section_name_.assign(output_section_name); + } } // Return the Input_section. @@ -3252,16 +3257,10 @@ class Output_section::Input_section_sort_entry return this->index_; } - // Whether there is a section name. - bool - section_has_name() const - { return this->section_has_name_; } - // The section name. const std::string& section_name() const { - gold_assert(this->section_has_name_); return this->section_name_; } @@ -3270,7 +3269,6 @@ class Output_section::Input_section_sort_entry bool has_priority() const { - gold_assert(this->section_has_name_); return this->section_name_.find('.', 1) != std::string::npos; } @@ -3280,7 +3278,6 @@ class Output_section::Input_section_sort_entry unsigned int get_priority() const { - gold_assert(this->section_has_name_); bool is_ctors; if (is_prefix_of(".ctors.", this->section_name_.c_str()) || is_prefix_of(".dtors.", this->section_name_.c_str())) @@ -3339,9 +3336,6 @@ class Output_section::Input_section_sort_entry Input_section input_section_; // The index of this Input_section in the original list. unsigned int index_; - // Whether this Input_section has a section name--it won't if this - // is some random Output_section_data. - bool section_has_name_; // The section name if there is one. std::string section_name_; }; @@ -3377,16 +3371,6 @@ Output_section::Input_section_sort_compare::operator()( return s1.index() < s2.index(); } - // We sort all the sections with no names to the end. - if (!s1.section_has_name() || !s2.section_has_name()) - { - if (s1.section_has_name()) - return true; - if (s2.section_has_name()) - return false; - return s1.index() < s2.index(); - } - // A section with a priority follows a section without a priority. bool s1_has_priority = s1.has_priority(); bool s2_has_priority = s2.has_priority(); @@ -3418,16 +3402,6 @@ Output_section::Input_section_sort_init_fini_compare::operator()( const Output_section::Input_section_sort_entry& s1, const Output_section::Input_section_sort_entry& s2) const { - // We sort all the sections with no names to the end. - if (!s1.section_has_name() || !s2.section_has_name()) - { - if (s1.section_has_name()) - return true; - if (s2.section_has_name()) - return false; - return s1.index() < s2.index(); - } - // A section without a priority follows a section with a priority. // This is the reverse of .ctors and .dtors sections. bool s1_has_priority = s1.has_priority(); @@ -3503,16 +3477,6 @@ Output_section::Input_section_sort_section_prefix_special_ordering_compare const Output_section::Input_section_sort_entry& s1, const Output_section::Input_section_sort_entry& s2) const { - // We sort all the sections with no names to the end. - if (!s1.section_has_name() || !s2.section_has_name()) - { - if (s1.section_has_name()) - return true; - if (s2.section_has_name()) - return false; - return s1.index() < s2.index(); - } - // Some input section names have special ordering requirements. int o1 = Layout::special_ordering_of_input_section(s1.section_name().c_str()); int o2 = Layout::special_ordering_of_input_section(s2.section_name().c_str()); @@ -3539,16 +3503,6 @@ Output_section::Input_section_sort_section_name_compare const Output_section::Input_section_sort_entry& s1, const Output_section::Input_section_sort_entry& s2) const { - // We sort all the sections with no names to the end. - if (!s1.section_has_name() || !s2.section_has_name()) - { - if (s1.section_has_name()) - return true; - if (s2.section_has_name()) - return false; - return s1.index() < s2.index(); - } - // We sort by name. int compare = s1.section_name().compare(s2.section_name()); if (compare != 0) @@ -3616,7 +3570,8 @@ Output_section::sort_attached_input_sections() p != this->input_sections_.end(); ++p, ++i) sort_list.push_back(Input_section_sort_entry(*p, i, - this->must_sort_attached_input_sections())); + this->must_sort_attached_input_sections(), + this->name())); // Sort the input sections. if (this->must_sort_attached_input_sections()) |