From 6934001a98509d5f40ececbd9aa793b8969e27a3 Mon Sep 17 00:00:00 2001 From: Cary Coutant Date: Thu, 30 May 2013 23:01:11 +0000 Subject: 2013-05-30 Alexander Ivchenko Sriraman Tallam * options.h (sort_section): New option. * output.h (Input_section_sort_section_prefix_special_ordering_compare): Rename from Input_section_sort_section_name_special_ordering_compare. (Input_section_sort_section_name_compare): New struct. * output.cc (Output_section::Input_section_sort_section_name_compare:: operator()): New function. (Output_section::sort_attached_input_sections): Use new sort function for .text if --sort-section=name is specified. * layout.cc (Layout::make_output_section): Add sorting by name when --sort-section=name is specified. * testsuite/Makefile.am (text_section_grouping): Test option --sort-section=name. * testsuite/Makefile.in: Regenerate. * testsuite/section_sorting_name.cc: New file. * testsuite/section_sorting_name.sh: New file. --- gold/testsuite/Makefile.am | 10 ++++++ gold/testsuite/Makefile.in | 11 ++++++ gold/testsuite/section_sorting_name.cc | 59 ++++++++++++++++++++++++++++++ gold/testsuite/section_sorting_name.sh | 66 ++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 gold/testsuite/section_sorting_name.cc create mode 100755 gold/testsuite/section_sorting_name.sh (limited to 'gold/testsuite') diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am index 4936e14..bccf54d 100644 --- a/gold/testsuite/Makefile.am +++ b/gold/testsuite/Makefile.am @@ -273,6 +273,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.map icf_virtual_function_folding_test.o: icf_virtual_function_folding_test.cc diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in index 495b7d0..aa01015 100644 --- a/gold/testsuite/Makefile.in +++ b/gold/testsuite/Makefile.in @@ -84,6 +84,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 \ @@ -119,6 +120,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 \ @@ -140,6 +142,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ final_layout_script.lds \ @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_virtual_function_folding_test.map \ @GCC_TRUE@@NATIVE_LINKER_TRUE@ icf_preemptible_functions_test \ @@ -3757,6 +3760,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 @@ -4424,6 +4429,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/gold/testsuite/section_sorting_name.cc b/gold/testsuite/section_sorting_name.cc new file mode 100644 index 0000000..e89c1ed --- /dev/null +++ b/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 . + +// 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/gold/testsuite/section_sorting_name.sh b/gold/testsuite/section_sorting_name.sh new file mode 100755 index 0000000..00b6994 --- /dev/null +++ b/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 . + +# 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" -- cgit v1.1