summaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-elf/linux-x86.exp
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2018-07-20 09:18:47 -0700
committerH.J. Lu <hjl.tools@gmail.com>2018-07-20 09:19:00 -0700
commit241e64e3b42cd9eba514b8e0ad2ef39a337f10a5 (patch)
treed62e37adef725407d44dd34d778ddda4c20a60cb /ld/testsuite/ld-elf/linux-x86.exp
parentcbb09508e4b515501273288aaa11a8ef5e15e0ff (diff)
x86: Add a GNU_PROPERTY_X86_ISA_1_USED note if needed
When -z separate-code, which is enabled by default for Linux/x86, is used to create executable, ld won't place any data in the code-only PT_LOAD segment. If there are no data sections placed before the code-only PT_LOAD segment, the program headers won't be mapped into any PT_LOAD segment. When the executable tries to access it (based on the program header address passed in AT_PHDR), it will lead to segfault. This patch inserts a GNU_PROPERTY_X86_ISA_1_USED note if there may be no data sections before the text section so that the first PT_LOAD segment won't be code-only and will contain the program header. Testcases are adjusted to either pass "-z noseparate-code" to ld or discard the .note.gnu.property section. A Linux/x86 run-time test is added. bfd/ PR ld/23428 * elfxx-x86.c (_bfd_x86_elf_link_setup_gnu_properties): If the separate code program header is needed, make sure that the first read-only PT_LOAD segment has no code by adding a GNU_PROPERTY_X86_ISA_1_USED note. ld/ PR ld/23428 * testsuite/ld-elf/linux-x86.S: New file. * testsuite/ld-elf/linux-x86.exp: Likewise. * testsuite/ld-elf/pr23428.c: Likewise. * testsuite/ld-elf/sec64k.exp: Pass "-z noseparate-code" to ld for Linux/x86 targets. * testsuite/ld-i386/abs-iamcu.d: Likewise. * testsuite/ld-i386/abs.d: Likewise. * testsuite/ld-i386/pr12718.d: Likewise. * testsuite/ld-i386/pr12921.d: Likewise. * testsuite/ld-x86-64/abs-k1om.d: Likewise. * testsuite/ld-x86-64/abs-l1om.d: Likewise. * testsuite/ld-x86-64/abs.d: Likewise. * testsuite/ld-x86-64/pr12718.d: Likewise. * testsuite/ld-x86-64/pr12921.d: Likewise. * testsuite/ld-linkonce/zeroeh.ld: Discard .note.gnu.property section. * testsuite/ld-scripts/print-memory-usage.t: Likewise. * testsuite/ld-scripts/size-2.t: Likewise. * testsuite/lib/ld-lib.exp (run_ld_link_exec_tests): Use ld to create executable if language is "asm".
Diffstat (limited to 'ld/testsuite/ld-elf/linux-x86.exp')
-rw-r--r--ld/testsuite/ld-elf/linux-x86.exp46
1 files changed, 46 insertions, 0 deletions
diff --git a/ld/testsuite/ld-elf/linux-x86.exp b/ld/testsuite/ld-elf/linux-x86.exp
new file mode 100644
index 0000000000..36217c6fb4
--- /dev/null
+++ b/ld/testsuite/ld-elf/linux-x86.exp
@@ -0,0 +1,46 @@
+# Expect script for simple native Linux/x86 tests.
+# Copyright (C) 2018 Free Software Foundation, Inc.
+#
+# This file is part of the GNU Binutils.
+#
+# 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.
+#
+
+# Test very simple native Linux/x86 programs with linux-x86.S.
+if { ![isnative] || [which $CC] == 0 \
+ || (![istarget "i?86-*-linux*"] \
+ && ![istarget "x86_64-*-linux*"] \
+ && ![istarget "amd64-*-linux*"]) } {
+ return
+}
+
+# Add $PLT_CFLAGS if PLT is expected.
+global PLT_CFLAGS
+# Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
+global NOPIE_CFLAGS NOPIE_LDFLAGS
+
+run_ld_link_exec_tests [list \
+ [list \
+ "Run PR ld/23428 test" \
+ "--no-dynamic-linker -z separate-code" \
+ "" \
+ { linux-x86.S pr23428.c } \
+ "pr23428" \
+ "pass.out" \
+ "$NOPIE_CFLAGS -fno-asynchronous-unwind-tables" \
+ "asm" \
+ ] \
+]