summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Hsieh <andrewhsieh@google.com>2013-06-03 09:31:19 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2013-06-03 09:31:19 +0000
commit6e4f9ded07a7e180ad3f38be99b3a027351a7e67 (patch)
treeaa5100edc5a6043efe91a610f92760499d73a815
parent93e5e14dd61bc5c558ef5b0d1d1c0e9e3e11dc2c (diff)
parent2d40f3b3a19a2dbe48157af32fb3089bffb14aae (diff)
downloadtoolchain_binutils-6e4f9ded07a7e180ad3f38be99b3a027351a7e67.zip
toolchain_binutils-6e4f9ded07a7e180ad3f38be99b3a027351a7e67.tar.gz
toolchain_binutils-6e4f9ded07a7e180ad3f38be99b3a027351a7e67.tar.bz2
Merge "[2.22], [2.23] Backport of the patch that enables "--sort-section=name" command line option in gold."
-rw-r--r--binutils-2.22/gold/layout.cc4
-rw-r--r--binutils-2.22/gold/options.h6
-rw-r--r--binutils-2.22/gold/output.cc42
-rw-r--r--binutils-2.22/gold/output.h10
-rw-r--r--binutils-2.22/gold/testsuite/Makefile.in11
-rw-r--r--binutils-2.22/gold/testsuite/section_sorting_name.cc59
-rwxr-xr-xbinutils-2.22/gold/testsuite/section_sorting_name.sh66
-rw-r--r--binutils-2.23/gold/layout.cc4
-rw-r--r--binutils-2.23/gold/options.h6
-rw-r--r--binutils-2.23/gold/output.cc42
-rw-r--r--binutils-2.23/gold/output.h10
-rw-r--r--binutils-2.23/gold/testsuite/Makefile.am10
-rw-r--r--binutils-2.23/gold/testsuite/Makefile.in11
-rw-r--r--binutils-2.23/gold/testsuite/section_sorting_name.cc59
-rwxr-xr-xbinutils-2.23/gold/testsuite/section_sorting_name.sh66
15 files changed, 394 insertions, 12 deletions
diff --git a/binutils-2.22/gold/layout.cc b/binutils-2.22/gold/layout.cc
index 994249b..fbad272 100644
--- a/binutils-2.22/gold/layout.cc
+++ b/binutils-2.22/gold/layout.cc
@@ -1577,6 +1577,10 @@ Layout::make_output_section(const char* name, elfcpp::Elf_Word type,
&& strcmp(name, ".text") == 0)
os->set_may_sort_attached_input_sections();
+ // GNU linker sorts section by name with --sort-section=name.
+ if (strcmp(parameters->options().sort_section(), "name") == 0)
+ os->set_must_sort_attached_input_sections();
+
// Check for .stab*str sections, as .stab* sections need to link to
// them.
if (type == elfcpp::SHT_STRTAB
diff --git a/binutils-2.22/gold/options.h b/binutils-2.22/gold/options.h
index 5def1d5..45763cc 100644
--- a/binutils-2.22/gold/options.h
+++ b/binutils-2.22/gold/options.h
@@ -1004,6 +1004,12 @@ class General_options
N_("Sort common symbols by alignment"),
N_("[={ascending,descending}]"));
+ DEFINE_enum(sort_section, options::TWO_DASHES, '\0', "none",
+ N_("Sort sections by name. \'--no-text-reorder\'"
+ " will override \'--sort-section=name\' for .text"),
+ 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/binutils-2.22/gold/output.cc b/binutils-2.22/gold/output.cc
index 7ec6076..ea4d6bf 100644
--- a/binutils-2.22/gold/output.cc
+++ b/binutils-2.22/gold/output.cc
@@ -3439,8 +3439,9 @@ 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
+Output_section::Input_section_sort_section_prefix_special_ordering_compare
::operator()(
const Output_section::Input_section_sort_entry& s1,
const Output_section::Input_section_sort_entry& s2) const
@@ -3454,7 +3455,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());
@@ -3469,7 +3470,35 @@ Output_section::Input_section_sort_section_name_special_ordering_compare
}
// Keep input order otherwise.
- return s1.index() < s2.index();
+ return s1.index() < s2.index();
+}
+
+// Return true if S1 should come before S2. This is the sort comparison
+// function for sections to sort them by name.
+
+bool
+Output_section::Input_section_sort_section_name_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();
+ }
+
+ // 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();
}
// This updates the section order index of input sections according to the
@@ -3540,9 +3569,12 @@ Output_section::sort_attached_input_sections()
|| this->type() == elfcpp::SHT_FINI_ARRAY)
std::sort(sort_list.begin(), sort_list.end(),
Input_section_sort_init_fini_compare());
+ else if (strcmp(parameters->options().sort_section(), "name") == 0)
+ std::sort(sort_list.begin(), sort_list.end(),
+ Input_section_sort_section_name_compare());
else if (strcmp(this->name(), ".text") == 0)
- std::sort(sort_list.begin(), sort_list.end(),
- Input_section_sort_section_name_special_ordering_compare());
+ std::sort(sort_list.begin(), sort_list.end(),
+ Input_section_sort_section_prefix_special_ordering_compare());
else
std::sort(sort_list.begin(), sort_list.end(),
Input_section_sort_compare());
diff --git a/binutils-2.22/gold/output.h b/binutils-2.22/gold/output.h
index 553d76a..02c613c 100644
--- a/binutils-2.22/gold/output.h
+++ b/binutils-2.22/gold/output.h
@@ -4001,7 +4001,15 @@ class Output_section : public Output_data
// This is the sort comparison function for .text to sort sections with
// prefixes .text.{unlikely,exit,startup,hot} before other sections.
- struct Input_section_sort_section_name_special_ordering_compare
+ struct Input_section_sort_section_prefix_special_ordering_compare
+ {
+ bool
+ operator()(const Input_section_sort_entry&,
+ const Input_section_sort_entry&) const;
+ };
+
+ // This is the sort comparison function for sorting sections by name.
+ struct Input_section_sort_section_name_compare
{
bool
operator()(const Input_section_sort_entry&,
diff --git a/binutils-2.22/gold/testsuite/Makefile.in b/binutils-2.22/gold/testsuite/Makefile.in
index a8d157f..7ebad75 100644
--- a/binutils-2.22/gold/testsuite/Makefile.in
+++ b/binutils-2.22/gold/testsuite/Makefile.in
@@ -82,6 +82,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_so_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ section_sorting_name.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_sht_rel_addend_test.sh \
@@ -115,6 +116,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_no_grouping.stdout \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ section_sorting_name.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_sht_rel_addend_test.stdout \
@@ -129,6 +131,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_no_grouping \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ section_sorting_name \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_virtual_function_folding_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test \
@@ -3830,6 +3833,8 @@ final_layout.sh.log: final_layout.sh
@p='final_layout.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
text_section_grouping.sh.log: text_section_grouping.sh
@p='text_section_grouping.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+section_sorting_name.sh.log: section_sorting_name.sh
+ @p='section_sorting_name.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
icf_preemptible_functions_test.sh.log: icf_preemptible_functions_test.sh
@p='icf_preemptible_functions_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
icf_string_merge_test.sh.log: icf_string_merge_test.sh
@@ -4481,6 +4486,12 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -n --synthetic text_section_grouping > text_section_grouping.stdout
@GCC_TRUE@@NATIVE_LINKER_TRUE@text_section_no_grouping.stdout: text_section_no_grouping
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -n --synthetic text_section_no_grouping > text_section_no_grouping.stdout
+@GCC_TRUE@@NATIVE_LINKER_TRUE@section_sorting_name.o: section_sorting_name.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -g -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@section_sorting_name: section_sorting_name.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--sort-section=name section_sorting_name.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@section_sorting_name.stdout: section_sorting_name
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -n --synthetic section_sorting_name > section_sorting_name.stdout
@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIE -g -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test: icf_virtual_function_folding_test.o gcctestdir/ld
diff --git a/binutils-2.22/gold/testsuite/section_sorting_name.cc b/binutils-2.22/gold/testsuite/section_sorting_name.cc
new file mode 100644
index 0000000..e89c1ed
--- /dev/null
+++ b/binutils-2.22/gold/testsuite/section_sorting_name.cc
@@ -0,0 +1,59 @@
+// section_sorting_name.cc -- a test case for gold
+
+// Copyright 2013 Free Software Foundation, Inc.
+// Written by Alexander Ivchenko <alexander.ivchenko@intel.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+// The goal of this program is to verify that when using --sort-section=name
+// option all .text, .data and .bss sections are sorted by name
+
+extern "C"
+__attribute__ ((section(".text.hot0001")))
+int hot_foo_0001()
+{
+ return 1;
+}
+
+int vdata_0003 __attribute__((section(".data.0003"))) = 3;
+int vbss_0003 __attribute__((section(".bss.0003"))) = 0;
+
+extern "C"
+__attribute__ ((section(".text.hot0003")))
+int hot_foo_0003()
+{
+ return 1;
+}
+
+int vdata_0001 __attribute__((section(".data.0001"))) = 1;
+int vbss_0001 __attribute__((section(".bss.0001"))) = 0;
+
+extern "C"
+__attribute__ ((section(".text.hot0002")))
+int hot_foo_0002()
+{
+ return 1;
+}
+
+int vdata_0002 __attribute__((section(".data.0002"))) = 2;
+int vbss_0002 __attribute__((section(".bss.0002"))) = 0;
+
+int main()
+{
+ return 1;
+}
diff --git a/binutils-2.22/gold/testsuite/section_sorting_name.sh b/binutils-2.22/gold/testsuite/section_sorting_name.sh
new file mode 100755
index 0000000..00b6994
--- /dev/null
+++ b/binutils-2.22/gold/testsuite/section_sorting_name.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+# section_sorting_name.sh -- test
+
+# Copyright 2013 Free Software Foundation, Inc.
+# Written by Alexander Ivchenko <alexander.ivchenko@intel.com>.
+
+# This file is part of gold.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+# The goal of this program is to verify that when using --sort-section=name
+# option all .text, .data, and .bss sections are sorted by name
+
+set -e
+
+check()
+{
+ awk "
+BEGIN { saw1 = 0; saw2 = 0; err = 0; }
+/.*$2\$/ { saw1 = 1; }
+/.*$3\$/ {
+ saw2 = 1;
+ if (!saw1)
+ {
+ printf \"layout of $2 and $3 is not right\\n\";
+ err = 1;
+ exit 1;
+ }
+ }
+END {
+ if (!saw1 && !err)
+ {
+ printf \"did not see $2\\n\";
+ exit 1;
+ }
+ if (!saw2 && !err)
+ {
+ printf \"did not see $3\\n\";
+ exit 1;
+ }
+ }" $1
+}
+
+# addr (hot_foo_0001) < addr (hot_foo_0002) < addr (hot_foo_0003)
+check section_sorting_name.stdout "hot_foo_0001" "hot_foo_0002"
+check section_sorting_name.stdout "hot_foo_0002" "hot_foo_0003"
+
+check section_sorting_name.stdout "vdata_0001" "vdata_0002"
+check section_sorting_name.stdout "vdata_0002" "vdata_0003"
+
+check section_sorting_name.stdout "vbss_0001" "vbss_0002"
+check section_sorting_name.stdout "vbss_0002" "vbss_0003"
diff --git a/binutils-2.23/gold/layout.cc b/binutils-2.23/gold/layout.cc
index 994249b..fbad272 100644
--- a/binutils-2.23/gold/layout.cc
+++ b/binutils-2.23/gold/layout.cc
@@ -1577,6 +1577,10 @@ Layout::make_output_section(const char* name, elfcpp::Elf_Word type,
&& strcmp(name, ".text") == 0)
os->set_may_sort_attached_input_sections();
+ // GNU linker sorts section by name with --sort-section=name.
+ if (strcmp(parameters->options().sort_section(), "name") == 0)
+ os->set_must_sort_attached_input_sections();
+
// Check for .stab*str sections, as .stab* sections need to link to
// them.
if (type == elfcpp::SHT_STRTAB
diff --git a/binutils-2.23/gold/options.h b/binutils-2.23/gold/options.h
index 5def1d5..45763cc 100644
--- a/binutils-2.23/gold/options.h
+++ b/binutils-2.23/gold/options.h
@@ -1004,6 +1004,12 @@ class General_options
N_("Sort common symbols by alignment"),
N_("[={ascending,descending}]"));
+ DEFINE_enum(sort_section, options::TWO_DASHES, '\0', "none",
+ N_("Sort sections by name. \'--no-text-reorder\'"
+ " will override \'--sort-section=name\' for .text"),
+ 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/binutils-2.23/gold/output.cc b/binutils-2.23/gold/output.cc
index 09c632a..ee31234 100644
--- a/binutils-2.23/gold/output.cc
+++ b/binutils-2.23/gold/output.cc
@@ -3465,8 +3465,9 @@ 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
+Output_section::Input_section_sort_section_prefix_special_ordering_compare
::operator()(
const Output_section::Input_section_sort_entry& s1,
const Output_section::Input_section_sort_entry& s2) const
@@ -3480,7 +3481,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());
@@ -3495,7 +3496,35 @@ Output_section::Input_section_sort_section_name_special_ordering_compare
}
// Keep input order otherwise.
- return s1.index() < s2.index();
+ return s1.index() < s2.index();
+}
+
+// Return true if S1 should come before S2. This is the sort comparison
+// function for sections to sort them by name.
+
+bool
+Output_section::Input_section_sort_section_name_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();
+ }
+
+ // 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();
}
// This updates the section order index of input sections according to the
@@ -3566,9 +3595,12 @@ Output_section::sort_attached_input_sections()
|| this->type() == elfcpp::SHT_FINI_ARRAY)
std::sort(sort_list.begin(), sort_list.end(),
Input_section_sort_init_fini_compare());
+ else if (strcmp(parameters->options().sort_section(), "name") == 0)
+ std::sort(sort_list.begin(), sort_list.end(),
+ Input_section_sort_section_name_compare());
else if (strcmp(this->name(), ".text") == 0)
- std::sort(sort_list.begin(), sort_list.end(),
- Input_section_sort_section_name_special_ordering_compare());
+ std::sort(sort_list.begin(), sort_list.end(),
+ Input_section_sort_section_prefix_special_ordering_compare());
else
std::sort(sort_list.begin(), sort_list.end(),
Input_section_sort_compare());
diff --git a/binutils-2.23/gold/output.h b/binutils-2.23/gold/output.h
index 553d76a..02c613c 100644
--- a/binutils-2.23/gold/output.h
+++ b/binutils-2.23/gold/output.h
@@ -4001,7 +4001,15 @@ class Output_section : public Output_data
// This is the sort comparison function for .text to sort sections with
// prefixes .text.{unlikely,exit,startup,hot} before other sections.
- struct Input_section_sort_section_name_special_ordering_compare
+ struct Input_section_sort_section_prefix_special_ordering_compare
+ {
+ bool
+ operator()(const Input_section_sort_entry&,
+ const Input_section_sort_entry&) const;
+ };
+
+ // This is the sort comparison function for sorting sections by name.
+ struct Input_section_sort_section_name_compare
{
bool
operator()(const Input_section_sort_entry&,
diff --git a/binutils-2.23/gold/testsuite/Makefile.am b/binutils-2.23/gold/testsuite/Makefile.am
index 64a5f59..23bf9fa 100644
--- a/binutils-2.23/gold/testsuite/Makefile.am
+++ b/binutils-2.23/gold/testsuite/Makefile.am
@@ -234,6 +234,16 @@ text_section_grouping.stdout: text_section_grouping
text_section_no_grouping.stdout: text_section_no_grouping
$(TEST_NM) -n --synthetic text_section_no_grouping > text_section_no_grouping.stdout
+check_SCRIPTS += section_sorting_name.sh
+check_DATA += section_sorting_name.stdout
+MOSTLYCLEANFILES += section_sorting_name
+section_sorting_name.o: section_sorting_name.cc
+ $(CXXCOMPILE) -O0 -c -ffunction-sections -g -o $@ $<
+section_sorting_name: section_sorting_name.o gcctestdir/ld
+ $(CXXLINK) -Bgcctestdir/ -Wl,--sort-section=name section_sorting_name.o
+section_sorting_name.stdout: section_sorting_name
+ $(TEST_NM) -n --synthetic section_sorting_name > section_sorting_name.stdout
+
check_PROGRAMS += icf_virtual_function_folding_test
MOSTLYCLEANFILES += icf_virtual_function_folding_test
icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc
diff --git a/binutils-2.23/gold/testsuite/Makefile.in b/binutils-2.23/gold/testsuite/Makefile.in
index ecfe77d..bd2a082 100644
--- a/binutils-2.23/gold/testsuite/Makefile.in
+++ b/binutils-2.23/gold/testsuite/Makefile.in
@@ -82,6 +82,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_safe_so_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping.sh \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ section_sorting_name.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test.sh \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_sht_rel_addend_test.sh \
@@ -115,6 +116,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_no_grouping.stdout \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ section_sorting_name.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test.stdout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_sht_rel_addend_test.stdout \
@@ -129,6 +131,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_grouping \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ text_section_no_grouping \
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ section_sorting_name \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_virtual_function_folding_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_string_merge_test \
@@ -3683,6 +3686,8 @@ final_layout.sh.log: final_layout.sh
@p='final_layout.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
text_section_grouping.sh.log: text_section_grouping.sh
@p='text_section_grouping.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
+section_sorting_name.sh.log: section_sorting_name.sh
+ @p='section_sorting_name.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
icf_preemptible_functions_test.sh.log: icf_preemptible_functions_test.sh
@p='icf_preemptible_functions_test.sh'; $(am__check_pre) $(LOG_COMPILE) "$$tst" $(am__check_post)
icf_string_merge_test.sh.log: icf_string_merge_test.sh
@@ -4332,6 +4337,12 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -n --synthetic text_section_grouping > text_section_grouping.stdout
@GCC_TRUE@@NATIVE_LINKER_TRUE@text_section_no_grouping.stdout: text_section_no_grouping
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -n --synthetic text_section_no_grouping > text_section_no_grouping.stdout
+@GCC_TRUE@@NATIVE_LINKER_TRUE@section_sorting_name.o: section_sorting_name.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -g -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@section_sorting_name: section_sorting_name.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,--sort-section=name section_sorting_name.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@section_sorting_name.stdout: section_sorting_name
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_NM) -n --synthetic section_sorting_name > section_sorting_name.stdout
@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -fPIE -g -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@icf_virtual_function_folding_test: icf_virtual_function_folding_test.o gcctestdir/ld
diff --git a/binutils-2.23/gold/testsuite/section_sorting_name.cc b/binutils-2.23/gold/testsuite/section_sorting_name.cc
new file mode 100644
index 0000000..e89c1ed
--- /dev/null
+++ b/binutils-2.23/gold/testsuite/section_sorting_name.cc
@@ -0,0 +1,59 @@
+// section_sorting_name.cc -- a test case for gold
+
+// Copyright 2013 Free Software Foundation, Inc.
+// Written by Alexander Ivchenko <alexander.ivchenko@intel.com>.
+
+// This file is part of gold.
+
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 3 of the License, or
+// (at your option) any later version.
+
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+// MA 02110-1301, USA.
+
+// The goal of this program is to verify that when using --sort-section=name
+// option all .text, .data and .bss sections are sorted by name
+
+extern "C"
+__attribute__ ((section(".text.hot0001")))
+int hot_foo_0001()
+{
+ return 1;
+}
+
+int vdata_0003 __attribute__((section(".data.0003"))) = 3;
+int vbss_0003 __attribute__((section(".bss.0003"))) = 0;
+
+extern "C"
+__attribute__ ((section(".text.hot0003")))
+int hot_foo_0003()
+{
+ return 1;
+}
+
+int vdata_0001 __attribute__((section(".data.0001"))) = 1;
+int vbss_0001 __attribute__((section(".bss.0001"))) = 0;
+
+extern "C"
+__attribute__ ((section(".text.hot0002")))
+int hot_foo_0002()
+{
+ return 1;
+}
+
+int vdata_0002 __attribute__((section(".data.0002"))) = 2;
+int vbss_0002 __attribute__((section(".bss.0002"))) = 0;
+
+int main()
+{
+ return 1;
+}
diff --git a/binutils-2.23/gold/testsuite/section_sorting_name.sh b/binutils-2.23/gold/testsuite/section_sorting_name.sh
new file mode 100755
index 0000000..00b6994
--- /dev/null
+++ b/binutils-2.23/gold/testsuite/section_sorting_name.sh
@@ -0,0 +1,66 @@
+#!/bin/sh
+
+# section_sorting_name.sh -- test
+
+# Copyright 2013 Free Software Foundation, Inc.
+# Written by Alexander Ivchenko <alexander.ivchenko@intel.com>.
+
+# This file is part of gold.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+# MA 02110-1301, USA.
+
+# The goal of this program is to verify that when using --sort-section=name
+# option all .text, .data, and .bss sections are sorted by name
+
+set -e
+
+check()
+{
+ awk "
+BEGIN { saw1 = 0; saw2 = 0; err = 0; }
+/.*$2\$/ { saw1 = 1; }
+/.*$3\$/ {
+ saw2 = 1;
+ if (!saw1)
+ {
+ printf \"layout of $2 and $3 is not right\\n\";
+ err = 1;
+ exit 1;
+ }
+ }
+END {
+ if (!saw1 && !err)
+ {
+ printf \"did not see $2\\n\";
+ exit 1;
+ }
+ if (!saw2 && !err)
+ {
+ printf \"did not see $3\\n\";
+ exit 1;
+ }
+ }" $1
+}
+
+# addr (hot_foo_0001) < addr (hot_foo_0002) < addr (hot_foo_0003)
+check section_sorting_name.stdout "hot_foo_0001" "hot_foo_0002"
+check section_sorting_name.stdout "hot_foo_0002" "hot_foo_0003"
+
+check section_sorting_name.stdout "vdata_0001" "vdata_0002"
+check section_sorting_name.stdout "vdata_0002" "vdata_0003"
+
+check section_sorting_name.stdout "vbss_0001" "vbss_0002"
+check section_sorting_name.stdout "vbss_0002" "vbss_0003"