summaryrefslogtreecommitdiff
path: root/gold/testsuite
diff options
context:
space:
mode:
authorSriraman Tallam <tmsriram@google.com>2017-10-20 11:00:28 -0700
committerSriraman Tallam <tmsriram@google.com>2017-10-20 11:00:28 -0700
commit3b4190ccb31be262a5aac78238e6d659746f1f0f (patch)
tree462cab8fff8edfd52d66b6e46e73620c88ea1ea7 /gold/testsuite
parentf3012016f008030b48597b578a5fb1e550907374 (diff)
downloadbinutils-gdb-3b4190ccb31be262a5aac78238e6d659746f1f0f.tar.gz
New gold linker option -z,text-unlikely-segment.
2017-10-04 Sriraman Tallam <tmsriram@google.com> * options.h (-z,text_unlikely_segment): New option. * layout.cc (Layout::layout): Create new output section for .text.unlikely sections with the new option. (Layout::segment_precedes): Check for the new option when segment flags match. * testsuite/text_unlikely_segment.cc: New test source. * testsuite/text_unlikely_segment.sh: New test script. * testsuite/Makefile.am (text_unlikely_segment): New test. * testsuite/Makefile.in: Regenerate.
Diffstat (limited to 'gold/testsuite')
-rw-r--r--gold/testsuite/Makefile.am10
-rw-r--r--gold/testsuite/Makefile.in11
-rw-r--r--gold/testsuite/text_unlikely_segment.cc30
-rwxr-xr-xgold/testsuite/text_unlikely_segment.sh60
4 files changed, 111 insertions, 0 deletions
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 8eca3d8e072..d9a0669fb4c 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -340,6 +340,16 @@ section_sorting_name: section_sorting_name.o gcctestdir/ld
section_sorting_name.stdout: section_sorting_name
$(TEST_NM) -n --synthetic section_sorting_name > section_sorting_name.stdout
+check_SCRIPTS += text_unlikely_segment.sh
+check_DATA += text_unlikely_segment_readelf.stdout
+MOSTLYCLEANFILES += text_unlikely_segment
+text_unlikely_segment.o: text_unlikely_segment.cc
+ $(CXXCOMPILE) -O0 -c -ffunction-sections -g -o $@ $<
+text_unlikely_segment: text_unlikely_segment.o gcctestdir/ld
+ $(CXXLINK) -Bgcctestdir/ -Wl,-z,text-unlikely-segment text_unlikely_segment.o
+text_unlikely_segment_readelf.stdout: text_unlikely_segment
+ $(TEST_READELF) -Wl $< >$@
+
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 10f9493abe3..b8db70d75db 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -87,6 +87,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@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@ text_unlikely_segment.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 \
@@ -114,6 +115,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@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@ text_unlikely_segment_readelf.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 \
@@ -139,6 +141,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) \
@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@ text_unlikely_segment \
@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 \
@@ -5148,6 +5151,8 @@ 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)
+text_unlikely_segment.sh.log: text_unlikely_segment.sh
+ @p='text_unlikely_segment.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
@@ -6015,6 +6020,12 @@ uninstall-am:
@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@text_unlikely_segment.o: text_unlikely_segment.cc
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXCOMPILE) -O0 -c -ffunction-sections -g -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@text_unlikely_segment: text_unlikely_segment.o gcctestdir/ld
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ -Wl,-z,text-unlikely-segment text_unlikely_segment.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@text_unlikely_segment_readelf.stdout: text_unlikely_segment
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(TEST_READELF) -Wl $< >$@
@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/text_unlikely_segment.cc b/gold/testsuite/text_unlikely_segment.cc
new file mode 100644
index 00000000000..f8e6dd7e669
--- /dev/null
+++ b/gold/testsuite/text_unlikely_segment.cc
@@ -0,0 +1,30 @@
+/* text_unlikey_segment.cc -- a test case for gold
+
+ Copyright (C) 2017 onwards Free Software Foundation, Inc.
+ Written by Sriraman Tallam <tmsriram@google.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. */
+
+__attribute__((section(".text.unlikely")))
+int foo(void) {
+ return 0;
+}
+
+int main(void) {
+ return 0;
+}
diff --git a/gold/testsuite/text_unlikely_segment.sh b/gold/testsuite/text_unlikely_segment.sh
new file mode 100755
index 00000000000..b01fe6c7157
--- /dev/null
+++ b/gold/testsuite/text_unlikely_segment.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+
+# plugin_final_layout.sh -- test
+
+# Copyright (C) 2011-2017 Free Software Foundation, Inc.
+# Written by Sriraman Tallam <tmsriram@google.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 if -z,text-unlikely-segment works as
+# intended. File text_unlikely_segment.cc is part of this test.
+
+
+set -e
+
+# With readelf -l, an ELF Section to Segment mapping is printed as :
+##############################################
+# Section to Segment mapping:
+# Segment Sections...
+# ...
+# 0x .text.unlikely
+# ...
+##############################################
+# Check if .text.unlikely is the only section in the segment.
+check_unique_segment()
+{
+ awk "
+BEGIN { saw_section = 0; saw_unique = 0; }
+/$2/ { saw_section = 1; }
+/[ ]*0[0-9][ ]*$2[ ]*\$/ { saw_unique = 1; }
+END {
+ if (!saw_section)
+ {
+ printf \"Section $2 not seen in output\\n\";
+ exit 1;
+ }
+ else if (!saw_unique)
+ {
+ printf \"Unique segment not seen for: $2\\n\";
+ exit 1;
+ }
+ }" $1
+}
+
+check_unique_segment text_unlikely_segment_readelf.stdout ".text.unlikely"