diff --git a/gold/ChangeLog b/gold/ChangeLog index 6dbb2e6..f9795b4 100644 --- a/gold/ChangeLog +++ b/gold/ChangeLog @@ -1,16 +1,28 @@ +2013-02-04 Alexander Ivchenko + + * options.h (sort_section): New option. + * options.cc (General_options::finalize): Warning if both + --sort-section=name and --no-text-reorder are specified. + * output.h (Input_section_sort_section_name_special_ordering_compare): + Add sorting by name for .text sections with the same prefix if + --sort-section=name is specified. + * layout.cc (Layout::layout): + Add sorting by name for .data and .sdata sections --sort-section=name + is specified. + 2013-01-28 Cary Coutant - * dwp.cc (File_list): New typedef. - (Dwo_name_info_reader): New class. - (Dwo_id_info_reader::Dwo_id_info_reader): Remove unused parameters. - (Dwo_id_info_reader::visit_top_die): Remove unused member function. - (Dwo_file::~Dwo_file): Delete input_file_ after obj_. - (Dwo_file::read_executable): New function. - (Dwo_file::read): Move common setup code to ... - (Dwo_file::make_object): ... here. - (dwp_options): Add --exec/-e. - (usage): Likewise. - (main): Likewise. + * dwp.cc (File_list): New typedef. + (Dwo_name_info_reader): New class. + (Dwo_id_info_reader::Dwo_id_info_reader): Remove unused parameters. + (Dwo_id_info_reader::visit_top_die): Remove unused member function. + (Dwo_file::~Dwo_file): Delete input_file_ after obj_. + (Dwo_file::read_executable): New function. + (Dwo_file::read): Move common setup code to ... + (Dwo_file::make_object): ... here. + (dwp_options): Add --exec/-e. + (usage): Likewise. + (main): Likewise. 2013-01-24 Sriraman Tallam diff --git a/gold/layout.cc b/gold/layout.cc index 1eb2cc0..d8bec35 100644 --- a/gold/layout.cc +++ b/gold/layout.cc @@ -1142,6 +1142,9 @@ Layout::layout(Sized_relobj_file* object, unsigned int shndx, || is_prefix_of(".dtors.", name) || is_prefix_of(".init_array.", name) || is_prefix_of(".fini_array.", name) + || (strcmp(parameters->options().sort_section(), "name") == 0 + && (is_prefix_of(".data.", name) + || is_prefix_of(".sdata.", name))) || (parameters->options().ctors_in_init_array() && (strcmp(name, ".ctors") == 0 || strcmp(name, ".dtors") == 0)))) diff --git a/gold/options.cc b/gold/options.cc index fe9a00e..3583d71 100644 --- a/gold/options.cc +++ b/gold/options.cc @@ -1198,6 +1198,12 @@ General_options::finalize() // in the path, as appropriate. this->add_sysroot(); + // Let's warn if the user wants text sections to be sorted, + // but at the same time --no-text-reorder is given. + if (strcmp(this->sort_section(), "name") == 0 + && !this->text_reorder()) + gold_warning(_("ignoring --sort-section=name since --no-text-reorder is specified")); + // Now that we've normalized the options, check for contradictory ones. if (this->shared() && this->is_static()) gold_fatal(_("-shared and -static are incompatible")); diff --git a/gold/options.h b/gold/options.h index c138fa2..5419dd7 100644 --- a/gold/options.h +++ b/gold/options.h @@ -1016,6 +1016,11 @@ class General_options N_("Sort common symbols by alignment"), N_("[={ascending,descending}]")); + DEFINE_enum(sort_section, options::TWO_DASHES, '\0', "none", + N_("Sort text sections by name"), + N_("[none,name]"), + {"none", "name"}); + DEFINE_uint(spare_dynamic_tags, options::TWO_DASHES, '\0', 5, N_("Dynamic tag slots to reserve (default 5)"), N_("COUNT")); diff --git a/gold/output.cc b/gold/output.cc index 22c0bf0..1654038 100644 --- a/gold/output.cc +++ b/gold/output.cc @@ -3498,6 +3498,7 @@ Output_section::Input_section_sort_section_order_index_compare::operator()( // Return true if S1 should come before S2. This is the sort comparison // function for .text to sort sections with prefixes // .text.{unlikely,exit,startup,hot} before other sections. + bool Output_section::Input_section_sort_section_name_special_ordering_compare ::operator()( @@ -3513,7 +3514,7 @@ Output_section::Input_section_sort_section_name_special_ordering_compare 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()); @@ -3527,8 +3528,16 @@ Output_section::Input_section_sort_section_name_special_ordering_compare return o1 < o2; } + if (strcmp(parameters->options().sort_section(), "name") == 0) + { + // Within each prefix we sort by name. + int compare = s1.section_name().compare(s2.section_name()); + if (compare != 0) + return compare < 0; + } + // Keep input order otherwise. - return s1.index() < s2.index(); + return s1.index() < s2.index(); } // This updates the section order index of input sections according to the