ld: Add -z separate-code test for zero size section
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / binutils.exp
CommitLineData
24718e3b 1# Expect script for binutils tests
219d1afa 2# Copyright (C) 2006-2018 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
5940a93c 26if { ![istarget *-*-linux*]
5a68afcf 27 && ![istarget *-*-nacl*]
5940a93c 28 && ![istarget *-*-gnu*]} {
24718e3b
L
29 return
30}
31
1224efb8
L
32if { [istarget *-*-linux*aout*]
33 || [istarget *-*-linux*oldld*] } {
34 return
35}
36
a06ea964
NC
37# The optional test_name argument provides a mechanism for the caller
38# to hardwire the test name. This is important if ld_options contains
39# absolute path names because the default test name is constructed
40# from the prog_name and ld_options and we do not want absolute paths
ee3b52e9
L
41# to appear in the test_name. The optional readelf_options can be
42# used to specify different options for readelf.
43proc binutils_test { prog_name ld_options test {test_name ""} {readelf_options "-l"}} {
24718e3b
L
44 global as
45 global ld
46 global READELF
1224efb8 47 global objcopy
24718e3b
L
48 global strip
49 global srcdir
50 global subdir
1224efb8
L
51 global link_output
52
53 eval set prog \$$prog_name
a06ea964
NC
54
55 if { "$test_name" == "" } {
56 set test_name "$prog_name $ld_options ($test)"
57 }
24718e3b
L
58
59 if { ![ld_assemble $as $srcdir/$subdir/$test.s tmpdir/$test.o ] } {
1224efb8 60 unresolved "$test_name"
24718e3b
L
61 return
62 }
63
d9816402 64 if { ![ld_link $ld tmpdir/$test "$ld_options -z stack-size=0 tmpdir/$test.o"] } {
1224efb8 65 if { [string match "*not supported*" $link_output]
3b80b9ce
L
66 || [string match "*unrecognized option*" $link_output]
67 || [string match "*-z relro ignored*" $link_output] } {
1224efb8
L
68 unsupported "$ld_options is not supported by this target"
69 } else {
70 unresolved "$test_name"
71 }
24718e3b
L
72 return
73 }
74
ee3b52e9
L
75 send_log "$READELF $readelf_options --wide tmpdir/$test > tmpdir/$test.exp\n"
76 set got [remote_exec host "$READELF $readelf_options --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.exp"]
7f6a71ff 77 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
24718e3b 78 send_log "$got\n"
1224efb8 79 unresolved "$test_name"
24718e3b
L
80 return
81 }
82
d345186d 83 if [string match "*-z relro*" $ld_options] {
9a0f1d50
MR
84 # These targets set TEXT_DYNAMIC and therefore have `.dynamic'
85 # in the (read-only) text segment rather than data segment.
86 set relro_dynamic [expr !([istarget "hppa64*-*-*"] \
87 || ([istarget "mips*-*-*"] \
88 && ![istarget "*-*-vxworks*"]))]
927960f0
MR
89 # These targets have `.got' in regular data even though they do
90 # not have `.got' there.
91 set relro_gotplt [expr [istarget "mips*-*-*"]]
92 # These targets do not set NO_SMALL_DATA or DATA_GOT and therefore
93 # have `.got' in (read-write) small data rather than regular data.
94 set relro_got [expr !([istarget "alpha*-*-*"] \
95 || [istarget "hppa*-*-linux-*"] \
96 || [istarget "hppa*-*-netbsd*"] \
97 || [istarget "hppa*-*-openbsd*"] \
98 || [istarget "metag-*-*"] \
99 || [istarget "mips*-*-*"] \
100 || [istarget "nios2*-*-*"] \
101 || [istarget "or1k-*-*"] \
102 || [istarget "riscv*-*-*"] \
103 || [istarget "sh*-*-*"] \
104 || [istarget "x86_64-*-rdos*"])]
d345186d
L
105 # Check if GNU_RELRO segment is generated.
106 set got [remote_exec host "grep GNU_RELRO tmpdir/$test.exp"]
107 if { ![string match "*GNU_RELRO*" $got] } then {
108 set got [remote_exec host "cat tmpdir/$test.exp"]
109 if { [string match "*.data.rel.ro*" $got]
9a0f1d50 110 || ($relro_dynamic && [string match "*.dynamic*" $got])
927960f0
MR
111 || ($relro_gotplt && [string match "*.got.plt*" $got])
112 || ($relro_got && [string match "*.got*" $got])
d345186d
L
113 || [string match "*.eh_frame*" $got]
114 || [string match "*.gcc_except_table*" $got]
115 || [string match "*.exception_ranges*" $got]
116 || [string match "*.ctors*" $got]
117 || [string match "*.dtors*" $got]
118 || [string match "*.tdata*" $got]
119 || [string match "*.preinit_array*" $got]
120 || [string match "*.init_array*" $got]
121 || [string match "*.fini_array*" $got] } then {
122 # Fail if GNU_RELRO segment isn't generated, but should.
123 fail "$test_name"
124 return
125 }
126 }
127 }
128
1224efb8 129 send_log "$prog tmpdir/$test\n"
7f6a71ff
JM
130 set got [remote_exec host "$prog tmpdir/$test"]
131 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
24718e3b 132 send_log "$got\n"
1224efb8 133 fail "$test_name"
24718e3b
L
134 return
135 }
136
ee3b52e9
L
137 send_log "$READELF $readelf_options --wide tmpdir/$test > tmpdir/$test.out\n"
138 set got [remote_exec host "$READELF $readelf_options --wide tmpdir/$test" "" "/dev/null" "tmpdir/$test.out"]
7f6a71ff 139 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
24718e3b 140 send_log "$got\n"
1224efb8 141 unresolved "$test_name"
24718e3b
L
142 return
143 }
144
145 if { [catch {exec cmp tmpdir/$test.exp tmpdir/$test.out}] } then {
146 send_log "tmpdir/$test.exp tmpdir/$test.out differ.\n"
1224efb8 147 fail "$test_name"
24718e3b
L
148 return
149 }
150
1224efb8 151 pass "$test_name"
24718e3b
L
152}
153
1224efb8
L
154binutils_test strip "-z max-page-size=0x200000" maxpage1
155binutils_test strip "-z max-page-size=0x200000 -z common-page-size=0x100000" maxpage1
156binutils_test strip "-z max-page-size=0x100000" maxpage1
157binutils_test strip "-z max-page-size=0x100000 -z common-page-size=0x1000" maxpage1
158
159binutils_test strip "" maxpage1
160binutils_test strip "-shared" maxpage1
161binutils_test objcopy "" maxpage1
162binutils_test objcopy "-shared" maxpage1
163
f33cfcaa
L
164binutils_test strip "-z relro" relro1
165binutils_test strip "-z relro -shared" relro1
166binutils_test objcopy "-z relro" relro1
167binutils_test objcopy "-z relro -shared" relro1
5a68afcf 168if { ([istarget "i?86-*-elf*"]
99753d9d
AM
169 || (([istarget "i?86-*-linux*"]
170 || [istarget "i?86-*-gnu*"])
b10a8ae0
L
171 && ![istarget "*-*-*aout*"]
172 && ![istarget "*-*-*oldld*"])
173 || [istarget "x86_64-*-linux*"]
5a68afcf
RM
174 || [istarget "amd64-*-linux*"]
175 || [istarget "i?86-*nacl*"]
176 || [istarget "x86_64-*nacl*"]) } {
b10a8ae0
L
177 binutils_test strip "-z relro -shared" relro2
178 binutils_test objcopy "-z relro -shared" relro2
179}
c9df6640 180
a06ea964 181binutils_test strip "-T ${srcdir}/${subdir}/lma.lnk" lma "strip -T lma.lnk"
b26238c0 182
3bd61671 183set tls_tests { "tdata1" "tdata2" }
de5c4ae2
AM
184# hppa64 has its own .tbss section, with different flags.
185if { ![istarget "hppa64-*-*"] } {
3bd61671 186 lappend tls_tests "tdata3" "tbss1" "tbss2" "tbss3"
de5c4ae2 187}
67e9eb74 188set tls_opts {
34b00afa
L
189 "-z noseparate-code"
190 "-z separate-code"
67e9eb74 191 "-z relro"
34b00afa
L
192 "-shared -z noseparate-code"
193 "-shared -z separate-code"
67e9eb74
AM
194 "-shared -z relro"
195 "-z max-page-size=0x100000"
196 "-z max-page-size=0x100000 -z common-page-size=0x1000"
de5c4ae2 197}
b10a8ae0 198
67e9eb74
AM
199foreach testitem $tls_tests {
200 foreach testopt $tls_opts {
f33cfcaa 201 binutils_test objcopy $testopt $testitem
67e9eb74
AM
202 }
203}
ee3b52e9
L
204
205binutils_test strip "-s" gap "" "-lS"
This page took 0.527023 seconds and 4 git commands to generate.