diff options
author | Sriraman Tallam <tmsriram@google.com> | 2010-06-01 23:37:58 +0000 |
---|---|---|
committer | Sriraman Tallam <tmsriram@google.com> | 2010-06-01 23:37:58 +0000 |
commit | 6e9ba2ca9c85e1d04123b87af1d57d57a5e6e82a (patch) | |
tree | 8b4563c393ebbff8629de584992234b3c6ff6e67 /gold/layout.cc | |
parent | ae4d0c03d93ab5c671f7cb68c736ae2f28f3ec0b (diff) | |
download | gdb-6e9ba2ca9c85e1d04123b87af1d57d57a5e6e82a.zip gdb-6e9ba2ca9c85e1d04123b87af1d57d57a5e6e82a.tar.gz gdb-6e9ba2ca9c85e1d04123b87af1d57d57a5e6e82a.tar.bz2 |
* gold.h (is_wildcard_string): New function.
* layout.cc (Layout::layout): Pass this pointer to add_input_section.
(Layout::layout_eh_frame): Ditto.
(Layout::find_section_order_index): New method.
(Layout::read_layout_from_file): New method.
* layout.h (Layout::find_section_order_index): New method.
(Layout::read_layout_from_file): New method.
(Layout::input_section_position_): New private member.
(Layout::input_section_glob_): New private member.
* main.cc (main): Call read_layout_from_file here.
* options.h (--section-ordering-file): New option.
* output.cc (Output_section::input_section_order_specified_): New
member.
(Output_section::Output_section): Initialize new member.
(Output_section::add_input_section): Add new parameter.
Keep input sections when --section-ordering-file is used.
(Output_section::set_final_data_size): Sort input sections when
section ordering file is specified.
(Output_section::Input_section_sort_entry): Add new parameter.
Check sorting type.
(Output_section::Input_section_sort_entry::compare_section_ordering):
New method.
(Output_section::Input_section_sort_compare::operator()): Change to
consider section_order_index.
(Output_section::Input_section_sort_init_fini_compare::operator()):
Change to consider section_order_index.
(Output_section::Input_section_sort_section_order_index_compare
::operator()): New method.
(Output_section::sort_attached_input_sections): Change to sort
according to section order when specified.
(Output_section::add_input_section<32, true>): Add new parameter.
(Output_section::add_input_section<64, true>): Add new parameter.
(Output_section::add_input_section<32, false>): Add new parameter.
(Output_section::add_input_section<64, false>): Add new parameter.
* output.h (Output_section::add_input_section): Add new parameter.
(Output_section::input_section_order_specified): New
method.
(Output_section::set_input_section_order_specified): New method.
(Input_section::Input_section): Initialize section_order_index_.
(Input_section::section_order_index): New method.
(Input_section::set_section_order_index): New method.
(Input_section::section_order_index_): New member.
(Input_section::Input_section_sort_section_order_index_compare): New
struct.
(Output_section::input_section_order_specified_): New member.
* script-sections.cc (is_wildcard_string): Delete and move modified
method to gold.h.
(Output_section_element_input::Output_section_element_input): Modify
call to is_wildcard_string.
(Output_section_element_input::Input_section_pattern
::Input_section_pattern): Ditto.
(Output_section_element_input::Output_section_element_input): Ditto.
* testsuite/Makefile.am (final_layout): New test case.
* testsuite/Makefile.in: Regenerate.
* testsuite/final_layout.cc: New file.
* testsuite/final_layout.sh: New file.
Diffstat (limited to 'gold/layout.cc')
-rw-r--r-- | gold/layout.cc | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/gold/layout.cc b/gold/layout.cc index 36cfa8b..a39b115 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -26,8 +26,10 @@ #include <cstring> #include <algorithm> #include <iostream> +#include <fstream> #include <utility> #include <fcntl.h> +#include <fnmatch.h> #include <unistd.h> #include "libiberty.h" #include "md5.h" @@ -668,7 +670,7 @@ Layout::layout(Sized_relobj<size, big_endian>* object, unsigned int shndx, // FIXME: Handle SHF_LINK_ORDER somewhere. - *off = os->add_input_section(object, shndx, name, shdr, reloc_shndx, + *off = os->add_input_section(this, object, shndx, name, shdr, reloc_shndx, this->script_options_->saw_sections_clause()); this->have_added_input_section_ = true; @@ -886,7 +888,7 @@ Layout::layout_eh_frame(Sized_relobj<size, big_endian>* object, // We couldn't handle this .eh_frame section for some reason. // Add it as a normal section. bool saw_sections_clause = this->script_options_->saw_sections_clause(); - *off = os->add_input_section(object, shndx, name, shdr, reloc_shndx, + *off = os->add_input_section(this, object, shndx, name, shdr, reloc_shndx, saw_sections_clause); this->have_added_input_section_ = true; } @@ -1642,6 +1644,72 @@ Layout::relaxation_loop_body( return off; } +// Search the list of patterns and find the postion of the given section +// name in the output section. If the section name matches a glob +// pattern and a non-glob name, then the non-glob position takes +// precedence. Return 0 if no match is found. + +unsigned int +Layout::find_section_order_index(const std::string& section_name) +{ + Unordered_map<std::string, unsigned int>::iterator map_it; + map_it = this->input_section_position_.find(section_name); + if (map_it != this->input_section_position_.end()) + return map_it->second; + + // Absolute match failed. Linear search the glob patterns. + std::vector<std::string>::iterator it; + for (it = this->input_section_glob_.begin(); + it != this->input_section_glob_.end(); + ++it) + { + if (fnmatch((*it).c_str(), section_name.c_str(), FNM_NOESCAPE) == 0) + { + map_it = this->input_section_position_.find(*it); + gold_assert(map_it != this->input_section_position_.end()); + return map_it->second; + } + } + return 0; +} + +// Read the sequence of input sections from the file specified with +// --section-ordering-file. + +void +Layout::read_layout_from_file() +{ + const char* filename = parameters->options().section_ordering_file(); + std::ifstream in; + std::string line; + + in.open(filename); + if (!in) + gold_fatal(_("unable to open --section-ordering-file file %s: %s"), + filename, strerror(errno)); + + std::getline(in, line); // this chops off the trailing \n, if any + unsigned int position = 1; + + while (in) + { + if (!line.empty() && line[line.length() - 1] == '\r') // Windows + line.resize(line.length() - 1); + // Ignore comments, beginning with '#' + if (line[0] == '#') + { + std::getline(in, line); + continue; + } + this->input_section_position_[line] = position; + // Store all glob patterns in a vector. + if (is_wildcard_string(line.c_str())) + this->input_section_glob_.push_back(line); + position++; + std::getline(in, line); + } +} + // Finalize the layout. When this is called, we have created all the // output sections and all the output segments which are based on // input sections. We have several things to do, and we have to do |