]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/testsuite/ld-elf/binutils.exp
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-elf / binutils.exp
CommitLineData
24718e3b 1# Expect script for binutils tests
a2c58332 2# Copyright (C) 2006-2022 Free Software Foundation, Inc.
24718e3b 3#
f96b4a7b
NC
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
24718e3b 7# it under the terms of the GNU General Public License as published by
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
24718e3b 9# (at your option) any later version.
f96b4a7b 10#
24718e3b
L
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
f96b4a7b 15#
24718e3b
L
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
f96b4a7b
NC
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
24718e3b
L
20#
21# Written by H.J. Lu (hongjiu.lu@intel.com)
22#
23
24# Make sure that binutils can correctly handle ld output in ELF.
25
b0ee49d2
AM
26if { !([istarget *-*-linux*]
27 || [istarget arm*-*-uclinuxfdpiceabi]
28 || [istarget *-*-nacl*]
29 || [istarget *-*-gnu*]) || [istarget *ecoff] } then {
24718e3b
L
30 return
31}
32
a06ea964
NC
33# The optional test_name argument provides a mechanism for the caller
34# to hardwire the test name. This is important if ld_options contains
35# absolute path names because the default test name is constructed
36# from the prog_name and ld_options and we do not want absolute paths
ee3b52e9
L
37# to appear in the test_name. The optional readelf_options can be
38# used to specify different options for readelf.
39proc binutils_test { prog_name ld_options test {test_name ""} {readelf_options "-l"}} {
24718e3b
L
40 global as
41 global ld
42 global READELF
1224efb8 43 global objcopy
24718e3b
L
44 global strip
45 global srcdir
46 global subdir
1224efb8
L
47 global link_output
48
49 eval set prog \$$prog_name
a06ea964
NC
50
51 if { "$test_name" == "" } {
52 set test_name "$prog_name $ld_options ($test)"
53 }
24718e3b
L
54
55 if { ![ld_assemble $as $srcdir/$subdir/$test.s tmpdir/$test.o ] } {
5b1f6c95 56 unsupported "$test_name"
24718e3b
L
57 return
58 }
59
d9816402 60 if { ![ld_link $ld tmpdir/$test "$ld_options -z stack-size=0 tmpdir/$test.o"] } {
1224efb8 61 if { [string match "*not supported*" $link_output]
3b80b9ce 62 || [string match "*unrecognized option*" $link_output]
5b1f6c95 63 || [string match "*-z * ignored*" $link_output] } {
1224efb8
L
64 unsupported "$ld_options is not supported by this target"
65 } else {
5b1f6c95 66 fail "$test_name"
1224efb8 67 }
24718e3b
L
68 return
69 }
70
ee3b52e9
L
71 send_log "$READELF $readelf_options --wide tmpdir/$test > tmpdir/$test.exp\n"
72 set got [remote_exec host "$READELF $readelf_options --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.exp"]
7f6a71ff 73 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
24718e3b 74 send_log "$got\n"
5b1f6c95 75 fail "$test_name"
24718e3b
L
76 return
77 }
78
d345186d 79 if [string match "*-z relro*" $ld_options] {
9a0f1d50
MR
80 # These targets set TEXT_DYNAMIC and therefore have `.dynamic'
81 # in the (read-only) text segment rather than data segment.
82 set relro_dynamic [expr !([istarget "hppa64*-*-*"] \
83 || ([istarget "mips*-*-*"] \
84 && ![istarget "*-*-vxworks*"]))]
927960f0
MR
85 # These targets have `.got' in regular data even though they do
86 # not have `.got' there.
87 set relro_gotplt [expr [istarget "mips*-*-*"]]
88 # These targets do not set NO_SMALL_DATA or DATA_GOT and therefore
89 # have `.got' in (read-write) small data rather than regular data.
90 set relro_got [expr !([istarget "alpha*-*-*"] \
91 || [istarget "hppa*-*-linux-*"] \
92 || [istarget "hppa*-*-netbsd*"] \
93 || [istarget "hppa*-*-openbsd*"] \
94 || [istarget "metag-*-*"] \
95 || [istarget "mips*-*-*"] \
96 || [istarget "nios2*-*-*"] \
97 || [istarget "or1k-*-*"] \
98 || [istarget "riscv*-*-*"] \
99 || [istarget "sh*-*-*"] \
100 || [istarget "x86_64-*-rdos*"])]
d345186d
L
101 # Check if GNU_RELRO segment is generated.
102 set got [remote_exec host "grep GNU_RELRO tmpdir/$test.exp"]
103 if { ![string match "*GNU_RELRO*" $got] } then {
104 set got [remote_exec host "cat tmpdir/$test.exp"]
105 if { [string match "*.data.rel.ro*" $got]
9a0f1d50 106 || ($relro_dynamic && [string match "*.dynamic*" $got])
927960f0
MR
107 || ($relro_gotplt && [string match "*.got.plt*" $got])
108 || ($relro_got && [string match "*.got*" $got])
d345186d
L
109 || [string match "*.eh_frame*" $got]
110 || [string match "*.gcc_except_table*" $got]
111 || [string match "*.exception_ranges*" $got]
112 || [string match "*.ctors*" $got]
113 || [string match "*.dtors*" $got]
114 || [string match "*.tdata*" $got]
115 || [string match "*.preinit_array*" $got]
116 || [string match "*.init_array*" $got]
117 || [string match "*.fini_array*" $got] } then {
118 # Fail if GNU_RELRO segment isn't generated, but should.
119 fail "$test_name"
120 return
121 }
122 }
123 }
124
1224efb8 125 send_log "$prog tmpdir/$test\n"
7f6a71ff
JM
126 set got [remote_exec host "$prog tmpdir/$test"]
127 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
24718e3b 128 send_log "$got\n"
1224efb8 129 fail "$test_name"
24718e3b
L
130 return
131 }
132
ee3b52e9
L
133 send_log "$READELF $readelf_options --wide tmpdir/$test > tmpdir/$test.out\n"
134 set got [remote_exec host "$READELF $readelf_options --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
7f6a71ff 135 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
24718e3b 136 send_log "$got\n"
5b1f6c95 137 fail "$test_name"
24718e3b
L
138 return
139 }
140
141 if { [catch {exec cmp tmpdir/$test.exp tmpdir/$test.out}] } then {
142 send_log "tmpdir/$test.exp tmpdir/$test.out differ.\n"
1224efb8 143 fail "$test_name"
24718e3b
L
144 return
145 }
146
1224efb8 147 pass "$test_name"
24718e3b
L
148}
149
1224efb8
L
150binutils_test strip "-z max-page-size=0x200000" maxpage1
151binutils_test strip "-z max-page-size=0x200000 -z common-page-size=0x100000" maxpage1
152binutils_test strip "-z max-page-size=0x100000" maxpage1
153binutils_test strip "-z max-page-size=0x100000 -z common-page-size=0x1000" maxpage1
154
155binutils_test strip "" maxpage1
156binutils_test strip "-shared" maxpage1
157binutils_test objcopy "" maxpage1
158binutils_test objcopy "-shared" maxpage1
159
f33cfcaa
L
160binutils_test strip "-z relro" relro1
161binutils_test strip "-z relro -shared" relro1
162binutils_test objcopy "-z relro" relro1
163binutils_test objcopy "-z relro -shared" relro1
5a68afcf 164if { ([istarget "i?86-*-elf*"]
c65c21e1
AM
165 || [istarget "i?86-*-linux*"]
166 || [istarget "i?86-*-gnu*"]
b10a8ae0 167 || [istarget "x86_64-*-linux*"]
bbd19b19 168 || [istarget "amd64-*-linux*"]) } {
b10a8ae0
L
169 binutils_test strip "-z relro -shared" relro2
170 binutils_test objcopy "-z relro -shared" relro2
171}
c9df6640 172
a06ea964 173binutils_test strip "-T ${srcdir}/${subdir}/lma.lnk" lma "strip -T lma.lnk"
b26238c0 174
3bd61671 175set tls_tests { "tdata1" "tdata2" }
de5c4ae2
AM
176# hppa64 has its own .tbss section, with different flags.
177if { ![istarget "hppa64-*-*"] } {
3bd61671 178 lappend tls_tests "tdata3" "tbss1" "tbss2" "tbss3"
de5c4ae2 179}
67e9eb74 180set tls_opts {
34b00afa
L
181 "-z noseparate-code"
182 "-z separate-code"
67e9eb74 183 "-z relro"
34b00afa
L
184 "-shared -z noseparate-code"
185 "-shared -z separate-code"
67e9eb74
AM
186 "-shared -z relro"
187 "-z max-page-size=0x100000"
188 "-z max-page-size=0x100000 -z common-page-size=0x1000"
de5c4ae2 189}
b10a8ae0 190
67e9eb74
AM
191foreach testitem $tls_tests {
192 foreach testopt $tls_opts {
f33cfcaa 193 binutils_test objcopy $testopt $testitem
67e9eb74
AM
194 }
195}
ee3b52e9
L
196
197binutils_test strip "-s" gap "" "-lS"