Set NOPIE_CFLAGS and NOPIE_LDFLAGS
[deliverable/binutils-gdb.git] / ld / testsuite / ld-size / size.exp
1 # Expect script for linker support of size relocations.
2 #
3 # Copyright (C) 2013-2015 Free Software Foundation, Inc.
4 #
5 # This file is part of the GNU Binutils.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21 #
22
23
24 # Size relications have only been implemented for the ix86 and x86_64,
25 # so far.
26 if {!(([istarget "i?86-*-*"]
27 || [istarget "x86_64-*-*"])
28 && ([istarget "*-*-elf*"]
29 || [istarget "*-*-nacl*"]
30 || (([istarget "*-*-linux*"]
31 || [istarget "*-*-gnu*"])
32 && ![istarget "*-*-*aout*"]
33 && ![istarget "*-*-*oldld*"]))) } {
34 verbose "Size relocations tests not run - no target support"
35 return
36 }
37
38 # So as to avoid rewriting every last test case here in a nacl variant,
39 # we use black magic to massage the generic cases into nacl-variant cases.
40 if [istarget "*-*-nacl*"] {
41 # Change all the -melf_i386 to -melf_i386_nacl so linking can succeed.
42 set options_regsub(ld) {-m(\\S+) -m\\1_nacl}
43 }
44
45 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
46 foreach t $test_list {
47 # We need to strip the ".d", but can leave the dirname.
48 verbose [file rootname $t]
49 run_dump_test [file rootname $t]
50 }
51
52 # We need a native system.
53 if ![isnative] {
54 verbose "Native size relocation tests not run - not a native toolchain"
55 return
56 }
57
58 # We need a working compiler.
59 if { [which $CC] == 0 } {
60 verbose "Native size relocation tests not run - no compiler available"
61 return
62 }
63
64 # Add $NOPIE_CFLAGS and $NOPIE_LDFLAGS if non-PIE is required.
65 global NOPIE_CFLAGS NOPIE_LDFLAGS
66
67 run_cc_link_tests [list \
68 [list \
69 "Build libsize-1.so" \
70 "-shared" \
71 "-fPIC" \
72 {size-1a.c size-1b.c} \
73 {} \
74 "libsize-1.so" \
75 ] \
76 [list \
77 "Build libsize-2.so" \
78 "-shared" \
79 "-fPIC" \
80 {size-2a.c size-2b.c} \
81 {} \
82 "libsize-2.so" \
83 ] \
84 [list \
85 "Build libsize-3a.so" \
86 "-shared" "-fPIC" \
87 {size-3a.c} \
88 {} \
89 "libsize-3a.so" \
90 ] \
91 [list \
92 "Build libsize-3b.so" \
93 "-shared" \
94 "-fPIC" \
95 {size-3b.c} \
96 {} \
97 "libsize-3b.so" \
98 ] \
99 [list \
100 "Build libsize-3c.so" \
101 "-shared" \
102 "-fPIC" \
103 {size-3c.c} \
104 {} \
105 "libsize-3c.so" \
106 ] \
107 [list \
108 "Build libsize-6b.so" \
109 "-shared" \
110 "-fPIC" \
111 {size-6b.c} \
112 {} \
113 "libsize-6b.so" \
114 ] \
115 [list \
116 "Build libsize-7.so" \
117 "-shared" \
118 "-fPIC" \
119 {size-7b.c} \
120 {} \
121 "libsize-7.so" \
122 ] \
123 [list \
124 "Build size-7" \
125 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-7.so" \
126 "$NOPIE_CFLAGS" \
127 {size-7a.c} \
128 {{readelf -rW size-7.rd}} \
129 "size-7.exe" \
130 ] \
131 [list \
132 "Build libsize-8.so" \
133 "-shared" "-fPIC" \
134 {size-8b.c} \
135 {} \
136 "libsize-8.so" \
137 ] \
138 [list \
139 "Build size-8" \
140 "$NOPIE_LDFLAGS -Wl,--no-as-needed tmpdir/libsize-8.so" \
141 "$NOPIE_CFLAGS" \
142 {size-8a.c} \
143 {{readelf -rW size-8.rd}} \
144 "size-8.exe" \
145 ] \
146 [list \
147 "Build libsize-9.so" \
148 "-shared" \
149 "-fPIC" \
150 {size-9b.c} \
151 {{readelf -rW size-9.rd}} \
152 "libsize-9.so" \
153 ] \
154 [list \
155 "Build libsize-10.so" \
156 "-shared" \
157 "-fPIC" \
158 {size-10b.c} \
159 {{readelf -rW size-10.rd}} \
160 "libsize-10.so" \
161 ] \
162 ]
163
164 # Run-time size relocation tests.
165 run_ld_link_exec_tests [] [list \
166 [list \
167 "Run size-1" \
168 "tmpdir/libsize-1.so" \
169 "" \
170 {size-1.c} \
171 "size-1" \
172 "size-1.out" \
173 ] \
174 [list \
175 "Run size-2" \
176 "tmpdir/libsize-2.so" \
177 "" \
178 {size-2.c} \
179 "size-2" \
180 "size-2.out" \
181 ] \
182 [list \
183 "Run size-3a" \
184 "" \
185 "" \
186 {size-3.c size-3a.c} \
187 "size-3a" \
188 "size-3.out" \
189 ] \
190 [list \
191 "Run size-3b" \
192 "tmpdir/libsize-3a.so" \
193 "" \
194 {size-3.c} \
195 "size-3b" \
196 "size-3.out" \
197 ] \
198 [list \
199 "Run size-3c" \
200 "" \
201 "" \
202 {size-3.c size-3b.c} \
203 "size-3c" \
204 "size-3.out" \
205 ] \
206 [list \
207 "Run size-3d (1)" \
208 "tmpdir/libsize-3b.so" \
209 "" \
210 {size-3.c} \
211 "size-3d1" \
212 "size-3.out" \
213 ] \
214 [list \
215 "Run size-3d (2)" \
216 "" \
217 "" \
218 {size-3.c size-3c.c} \
219 "size-3d2" \
220 "size-3.out" \
221 ] \
222 [list \
223 {"Run size-3e"
224 "tmpdir/libsize-3c.so" ""
225 {size-3.c} "size-3e" "size-3.out"}
226 ] \
227 [list \
228 "Run size-4a" \
229 "" \
230 "" \
231 {size-4a.c size-4b.c} \
232 "size-4a" \
233 "size-4.out" \
234 "$NOPIE_CFLAGS" \
235 ] \
236 [list \
237 "Run size-4b" \
238 "" \
239 "" \
240 {size-4b.c size-4a.c} \
241 "size-4b" \
242 "size-4.out" \
243 "$NOPIE_CFLAGS" \
244 ] \
245 [list \
246 "Run size-5a" \
247 "" \
248 "" \
249 {size-5a.c size-5b.c} \
250 "size-5a" \
251 "size-5.out" \
252 "$NOPIE_CFLAGS" \
253 ] \
254 [list \
255 "Run size-5b" \
256 "" \
257 "" \
258 {size-5b.c size-5a.c} \
259 "size-5b" \
260 "size-5.out" \
261 "$NOPIE_CFLAGS" \
262 ] \
263 [list \
264 "Run size-6" \
265 "tmpdir/libsize-6b.so" \
266 "" \
267 {size-6a.c} \
268 "size-6" \
269 "size-6.out" \
270 "$NOPIE_CFLAGS" \
271 ] \
272 [list \
273 "Run size-8" \
274 "tmpdir/libsize-8.so --hash-styl=gnu" \
275 "" \
276 {size-8a.c} \
277 "size-8" \
278 "size-8.out" \
279 "$NOPIE_CFLAGS" \
280 ] \
281 [list \
282 "Run size-9" \
283 "tmpdir/libsize-9.so" \
284 "" \
285 {size-9a.c} \
286 "size-9" \
287 "size-9.out" \
288 ] \
289 [list \
290 "Run size-10" \
291 "tmpdir/libsize-10.so" \
292 "" \
293 {size-10a.c} \
294 "size-10" \
295 "size-10.out" \
296 ] \
297 ]
298
299 # Check if size relocation works at run-time.
300 catch "exec tmpdir/size-7.exe > tmpdir/dump.out" exec_output
301 if ![string match "" $exec_output] then {
302 send_log "No run-time size relocation support: $exec_output\n"
303 verbose "No run-time size relocation support: $exec_output" 1
304 return
305 }
306
307 if { [regexp_diff "tmpdir/dump.out" "$srcdir/$subdir/size-7.out" ] } then {
308 verbose "output is [file_contents "tmpdir/dump.out"]" 2
309 fail "Run-time size relocation"
310 return
311 }
This page took 0.068575 seconds and 4 git commands to generate.