gold: Add a linker configure option --enable-relro
[deliverable/binutils-gdb.git] / binutils / testsuite / binutils-all / ar.exp
CommitLineData
6f2750fe 1# Copyright (C) 1995-2016 Free Software Foundation, Inc.
252b5132
RH
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
32866df7 5# the Free Software Foundation; either version 3 of the License, or
252b5132
RH
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program; if not, write to the Free Software
b43b5d5f 15# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
252b5132
RH
16
17# Please email any bugs, comments, and/or additions to this file to:
18# bug-dejagnu@prep.ai.mit.edu
19
20# Written by Ian Lance Taylor <ian@cygnus.com>
21
22if ![is_remote host] {
23 if {[which $AR] == 0} then {
24 perror "$AR does not exist"
25 return
26 }
27}
28
29# send_user "Version [binutil_version $AR]"
30
31# Test long file name support
32
f7da43f3 33proc long_filenames { bfdtests } {
252b5132
RH
34 global AR
35 global host_triplet
f7da43f3 36 global base_dir
252b5132
RH
37
38 set testname "ar long file names"
39
40 set n1 "abcdefghijklmnopqrstuvwxyz1"
41 set n2 "abcdefghijklmnopqrstuvwxyz2"
42 set file1 tmpdir/$n1
43 set file2 tmpdir/$n2
44
45 remote_file build delete $file1
7f6a71ff 46 remote_file host delete $n1
252b5132
RH
47
48 # Some file systems truncate file names at 14 characters, which
49 # makes it impossible to run this test. Check for that now.
50 set status [catch "set f [open tmpdir/$n1 w]" errs]
51 if { $status != 0 } {
52 verbose -log "open tmpdir/$n1 returned $errs"
53 unsupported $testname
54 return
55 }
56 puts $f "first"
57 close $f
58
252b5132 59 remote_file build delete $file2
7f6a71ff 60 remote_file host delete $n2
252b5132
RH
61
62 set status [catch "set f [open tmpdir/$n2 w]" errs]
63 if { $status != 0 } {
64 verbose -log "open tmpdir/$n2 returned $errs"
65 unsupported $testname
66 return
67 }
68 puts $f "second"
69 close $f
70
71 if [is_remote host] {
8d263650
BE
72 set file1 [remote_download host $file1]
73 set file2 [remote_download host $file2]
252b5132
RH
74 set dest artest.a
75 } else {
76 set dest tmpdir/artest.a
77 }
78
8d263650 79 remote_file host delete $dest
252b5132
RH
80
81 set got [binutils_run $AR "rc $dest $file1 $file2"]
82 if [is_remote host] {
83 remote_upload host $file1 tmpdir/$n1
84 }
85
86 set f [open tmpdir/$n1 r]
87 gets $f string
88 close $f
89 if ![string match "first" $string] {
90 verbose -log "reading tmpdir/$n1 returned $string"
91 unsupported $testname
92 return
93 }
94
8d263650 95 remote_file host delete $dest
252b5132
RH
96 set got [binutils_run $AR "rc $dest $file1 $file2"]
97
98 if ![string match "" $got] {
99 fail $testname
100 return
101 }
102
103 remote_file build delete tmpdir/$n1
104 remote_file build delete tmpdir/$n2
105
106 set got [binutils_run $AR "t $dest"]
8d263650 107 regsub "\[\r\n \t\]*$" "$got" "" got
252b5132
RH
108 if ![string match "$n1*$n2" $got] {
109 fail $testname
110 return
111 }
112
113 if [is_remote host] {
8d263650
BE
114 remote_file host delete $file1
115 remote_file host delete $file2
252b5132
RH
116 }
117
252b5132
RH
118 set exec_output [binutils_run $AR "x $dest"]
119 set exec_output [prune_warnings $exec_output]
120 if ![string match "" $exec_output] {
121 verbose -log $exec_output
122 fail $testname
123 return
124 }
125
f7da43f3
L
126 foreach bfdtest $bfdtests {
127 set exec_output [binutils_run "$base_dir/$bfdtest" "$dest"]
128 if ![string match "" $exec_output] {
129 verbose -log $exec_output
130 fail "$testname ($bfdtest)"
131 return
132 }
58f594cd
L
133 }
134
252b5132 135 if [is_remote host] {
8d263650
BE
136 remote_upload host $n1 tmpdir/$n1
137 remote_upload host $n2 tmpdir/$n2
252b5132
RH
138 set file1 tmpdir/$n1
139 set file2 tmpdir/$n2
140 } else {
141 set file1 $n1
142 set file2 $n2
143 }
144
145 if ![file exists $file1] {
146 verbose -log "$file1 does not exist"
147 fail $testname
148 return
149 }
150 if ![file exists $file2] {
151 verbose -log "$file2 does not exist"
152 fail $testname
153 return
154 }
155
156 set f [open $file1 r]
157 if { [gets $f line] == -1 || $line != "first" } {
158 verbose -log "$file1 contents:"
159 verbose -log "$line"
160 close $f
161 fail $testname
162 return
163 }
164 close $f
165
166 set f [open $file2 r]
167 if { [gets $f line] == -1 || $line != "second" } {
168 verbose -log "$file2 contents:"
169 verbose -log "$line"
170 close $f
171 fail $testname
172 return
173 }
174 close $f
175
690649be 176 file delete $file1 $file2
252b5132
RH
177 pass $testname
178}
179
180# Test building the symbol table.
181
182proc symbol_table { } {
183 global AR
184 global AS
185 global NM
186 global srcdir
187 global subdir
188
189 set testname "ar symbol table"
190
191 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
192 unresolved $testname
193 return
194 }
195
196 if [is_remote host] {
197 set archive artest.a
198 set objfile [remote_download host tmpdir/bintest.o]
199 remote_file host delete $archive
200 } else {
201 set archive tmpdir/artest.a
202 set objfile tmpdir/bintest.o
203 }
204
205 remote_file build delete tmpdir/artest.a
206
207 set got [binutils_run $AR "rc $archive ${objfile}"]
208 if ![string match "" $got] {
209 fail $testname
210 return
211 }
212
213 set got [binutils_run $NM "--print-armap $archive"]
214 if { ![string match "*text_symbol in bintest.o*" $got] \
215 || ![string match "*data_symbol in bintest.o*" $got] \
216 || ![string match "*common_symbol in bintest.o*" $got] \
217 || [string match "*static_text_symbol in bintest.o*" $got] \
218 || [string match "*static_data_symbol in bintest.o*" $got] \
219 || [string match "*external_symbol in bintest.o*" $got] } {
220 fail $testname
221 return
222 }
223
224 pass $testname
225}
226
a8da6403
NC
227# Test building a thin archive.
228
f7da43f3 229proc thin_archive { bfdtests } {
a8da6403
NC
230 global AR
231 global AS
232 global NM
233 global srcdir
234 global subdir
f7da43f3 235 global base_dir
a8da6403
NC
236
237 set testname "ar thin archive"
238
239 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
240 unresolved $testname
241 return
242 }
243
244 if [is_remote host] {
245 set archive artest.a
246 set objfile [remote_download host tmpdir/bintest.o]
247 remote_file host delete $archive
248 } else {
249 set archive tmpdir/artest.a
250 set objfile tmpdir/bintest.o
251 }
252
253 remote_file build delete tmpdir/artest.a
254
255 set got [binutils_run $AR "rcT $archive ${objfile}"]
256 if ![string match "" $got] {
257 fail $testname
258 return
259 }
260
f7da43f3
L
261 foreach bfdtest $bfdtests {
262 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
263 if ![string match "" $exec_output] {
264 verbose -log $exec_output
265 fail "$testname ($bfdtest)"
266 return
267 }
58f594cd
L
268 }
269
a8da6403
NC
270 set got [binutils_run $NM "--print-armap $archive"]
271 if { ![string match "*text_symbol in *bintest.o*" $got] \
272 || ![string match "*data_symbol in *bintest.o*" $got] \
273 || ![string match "*common_symbol in *bintest.o*" $got] \
274 || [string match "*static_text_symbol in *bintest.o*" $got] \
275 || [string match "*static_data_symbol in *bintest.o*" $got] \
276 || [string match "*external_symbol in *bintest.o*" $got] } {
277 fail $testname
278 return
279 }
280
281 pass $testname
282}
283
284# Test building a thin archive with a nested archive.
285
f7da43f3 286proc thin_archive_with_nested { bfdtests } {
a8da6403
NC
287 global AR
288 global AS
289 global NM
290 global srcdir
291 global subdir
f7da43f3 292 global base_dir
a8da6403
NC
293
294 set testname "ar thin archive with nested archive"
295
296 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
297 unresolved $testname
298 return
299 }
300
301 if [is_remote host] {
302 set archive artest.a
303 set archive2 artest2.a
304 set objfile [remote_download host tmpdir/bintest.o]
305 remote_file host delete $archive
306 } else {
307 set archive tmpdir/artest.a
308 set archive2 tmpdir/artest2.a
309 set objfile tmpdir/bintest.o
310 }
311
312 remote_file build delete tmpdir/artest.a
313
314 set got [binutils_run $AR "rc $archive ${objfile}"]
315 if ![string match "" $got] {
316 fail $testname
317 return
318 }
319
320 remote_file build delete tmpdir/artest2.a
321
322 set got [binutils_run $AR "rcT $archive2 ${archive}"]
323 if ![string match "" $got] {
324 fail $testname
325 return
326 }
327
f7da43f3
L
328 foreach bfdtest $bfdtests {
329 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
330 if ![string match "" $exec_output] {
331 verbose -log $exec_output
332 fail "$testname ($bfdtest)"
333 return
334 }
58f594cd 335
f7da43f3
L
336 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive2"]
337 if ![string match "" $exec_output] {
338 verbose -log $exec_output
339 fail "$testname ($bfdtest)"
340 return
341 }
eb4dc530
L
342 }
343
a8da6403
NC
344 set got [binutils_run $NM "--print-armap $archive"]
345 if { ![string match "*text_symbol in *bintest.o*" $got] \
346 || ![string match "*data_symbol in *bintest.o*" $got] \
347 || ![string match "*common_symbol in *bintest.o*" $got] \
348 || [string match "*static_text_symbol in *bintest.o*" $got] \
349 || [string match "*static_data_symbol in *bintest.o*" $got] \
350 || [string match "*external_symbol in *bintest.o*" $got] } {
351 fail $testname
352 return
353 }
354
355 pass $testname
356}
357
af865222
AS
358# Test POSIX-compatible argument parsing.
359
360proc argument_parsing { } {
361 global AR
362 global AS
363 global srcdir
364 global subdir
365
366 set testname "ar argument parsing"
367
368 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
369 unresolved $testname
370 return
371 }
372
373 if [is_remote host] {
374 set archive artest.a
375 set objfile [remote_download host tmpdir/bintest.o]
376 remote_file host delete $archive
377 } else {
378 set archive tmpdir/artest.a
379 set objfile tmpdir/bintest.o
380 }
381
382 remote_file build delete tmpdir/artest.a
383
384 set got [binutils_run $AR "-r -c $archive ${objfile}"]
385 if ![string match "" $got] {
386 fail $testname
387 return
388 }
389
390 pass $testname
391}
392
36e4dce6
CD
393# Test building a deterministic archive.
394
395proc deterministic_archive { } {
396 global AR
397 global AS
398 global NM
399 global srcdir
400 global subdir
401
402 set testname "ar deterministic archive"
403
404 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
405 unresolved $testname
406 return
407 }
408
409 if [is_remote host] {
410 set archive artest.a
411 set objfile [remote_download host tmpdir/bintest.o]
412 remote_file host delete $archive
413 } else {
414 set archive tmpdir/artest.a
415 set objfile tmpdir/bintest.o
416 }
417
418 remote_file build delete tmpdir/artest.a
419
420 set got [binutils_run $AR "rcD $archive ${objfile}"]
421 if ![string match "" $got] {
422 fail $testname
423 return
424 }
425
426 set got [binutils_run $AR "tv $archive"]
427 # This only checks the file mode and uid/gid. We can't easily match
428 # date because it's printed with the user's timezone.
429 if ![string match "rw-r--r-- 0/0 *bintest.o*" $got] {
430 fail $testname
431 return
432 }
433
434 pass $testname
435}
436
a45fc993
AM
437proc unique_symbol { } {
438 global AR
439 global AS
440 global NM
441 global srcdir
442 global subdir
443
444 set testname "ar unique symbol in archive"
445
446 if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o] {
447 unresolved $testname
448 }
449
450 if [is_remote host] {
451 set archive artest.a
452 set objfile [remote_download host tmpdir/unique.o]
453 remote_file host delete $archive
454 } else {
455 set archive tmpdir/artest.a
456 set objfile tmpdir/unique.o
457 }
458
459 remote_file build delete tmpdir/artest.a
460
461 set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
462 if ![string match "" $got] {
463 fail $testname
464 return
465 }
466
467 set got [binutils_run $NM "--print-armap $archive"]
468 if ![string match "*foo in *unique.o*" $got] {
469 fail $testname
470 return
471 }
472
473 pass $testname
474}
475
fde6f1fc
L
476# Test deleting an element.
477
478proc delete_an_element { } {
479 global AR
480 global AS
481 global srcdir
482 global subdir
483
484 set testname "ar deleting an element"
485
486 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
487 unresolved $testname
488 return
489 }
490
491 if [is_remote host] {
492 set archive artest.a
493 set objfile [remote_download host tmpdir/bintest.o]
494 remote_file host delete $archive
495 } else {
496 set archive tmpdir/artest.a
497 set objfile tmpdir/bintest.o
498 }
499
500 remote_file build delete tmpdir/artest.a
501
502 set got [binutils_run $AR "-r -c $archive ${objfile}"]
503 if ![string match "" $got] {
504 fail $testname
505 return
506 }
507
508 set got [binutils_run $AR "-d $archive ${objfile}"]
509 if ![string match "" $got] {
510 fail $testname
511 return
512 }
513
514 pass $testname
515}
516
517# Test moving an element.
518
519proc move_an_element { } {
520 global AR
521 global AS
522 global srcdir
523 global subdir
524
525 set testname "ar moving an element"
526
527 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
528 unresolved $testname
529 return
530 }
531
532 if [is_remote host] {
533 set archive artest.a
534 set objfile [remote_download host tmpdir/bintest.o]
535 remote_file host delete $archive
536 } else {
537 set archive tmpdir/artest.a
538 set objfile tmpdir/bintest.o
539 }
540
541 remote_file build delete tmpdir/artest.a
542
543 set got [binutils_run $AR "-r -c $archive ${objfile}"]
544 if ![string match "" $got] {
545 fail $testname
546 return
547 }
548
549 set got [binutils_run $AR "-m $archive ${objfile}"]
550 if ![string match "" $got] {
551 fail $testname
552 return
553 }
554
555 pass $testname
556}
557
4fc87424
NC
558# PR 19775: Test creating and listing archives with an empty element.
559
560proc empty_archive { } {
561 global AR
562 global srcdir
563 global subdir
564
565 set testname "archive with empty element"
566
567 # FIXME: There ought to be a way to dynamically create an empty file.
568 set empty $srcdir/$subdir/empty
569
570 if [is_remote host] {
571 set archive artest.a
572 set objfile [remote_download host $empty]
573 remote_file host delete $archive
574 } else {
575 set archive tmpdir/artest.a
576 set objfile $empty
577 }
578
579 remote_file build delete tmpdir/artest.a
580
581 set got [binutils_run $AR "-r -c $archive ${objfile}"]
582 if ![string match "" $got] {
583 fail $testname
584 return
585 }
586
587 # This commmand used to fail with: "Malformed archive".
588 set got [binutils_run $AR "-t $archive"]
589 if ![string match "empty\r" $got] {
590 fail $testname
591 return
592 }
593
594 pass $testname
595}
596
252b5132
RH
597# Run the tests.
598
9bc24099
NC
599# Only run the bfdtest checks if the programs exist. Since these
600# programs are built but not installed, running the testsuite on an
601# installed toolchain will produce ERRORs about missing bfdtest1 and
602# bfdtest2 executables.
603if { [file exists $base_dir/bfdtest1] && [file exists $base_dir/bfdtest2] } {
604 set bfdtests [list bfdtest1 bfdtest2]
605
606 long_filenames $bfdtests
607 thin_archive $bfdtests
608 thin_archive_with_nested $bfdtests
609}
f7da43f3 610
252b5132 611symbol_table
af865222 612argument_parsing
36e4dce6 613deterministic_archive
fde6f1fc
L
614delete_an_element
615move_an_element
4fc87424 616empty_archive
9bc24099 617
4cd28456
AM
618if { [is_elf_format]
619 && ![istarget "*-*-hpux*"]
620 && ![istarget "msp*-*-*"] } {
a45fc993
AM
621 unique_symbol
622}
This page took 0.65416 seconds and 4 git commands to generate.