1 # Copyright (C) 1995-2017 Free Software Foundation, Inc.
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
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
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.
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
15 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
17 # Please email any bugs, comments, and/or additions to this file to:
18 # bug-dejagnu@prep.ai.mit.edu
20 # Written by Ian Lance Taylor <ian@cygnus.com>
22 if ![is_remote host] {
23 if {[which $AR] == 0} then {
24 perror "$AR does not exist"
29 if { [istarget "alpha-*-*"] && ![is_elf_format] } then {
33 # send_user "Version [binutil_version $AR]"
35 # Test long file name support
37 proc long_filenames { bfdtests } {
42 set testname "ar long file names"
44 set n1 "abcdefghijklmnopqrstuvwxyz1"
45 set n2 "abcdefghijklmnopqrstuvwxyz2"
49 remote_file build delete $file1
50 remote_file host delete $n1
52 # Some file systems truncate file names at 14 characters, which
53 # makes it impossible to run this test. Check for that now.
54 set status [catch "set f [open tmpdir/$n1 w]" errs]
56 verbose -log "open tmpdir/$n1 returned $errs"
63 remote_file build delete $file2
64 remote_file host delete $n2
66 set status [catch "set f [open tmpdir/$n2 w]" errs]
68 verbose -log "open tmpdir/$n2 returned $errs"
76 set file1 [remote_download host $file1]
77 set file2 [remote_download host $file2]
80 set dest tmpdir/artest.a
83 remote_file host delete $dest
85 set got [binutils_run $AR "rc $dest $file1 $file2"]
87 remote_upload host $file1 tmpdir/$n1
90 set f [open tmpdir/$n1 r]
93 if ![string match "first" $string] {
94 verbose -log "reading tmpdir/$n1 returned $string"
99 remote_file host delete $dest
100 set got [binutils_run $AR "rc $dest $file1 $file2"]
102 if ![string match "" $got] {
107 remote_file build delete tmpdir/$n1
108 remote_file build delete tmpdir/$n2
110 set got [binutils_run $AR "t $dest"]
111 regsub "\[\r\n \t\]*$" "$got" "" got
112 if ![string match "$n1*$n2" $got] {
117 if [is_remote host] {
118 remote_file host delete $file1
119 remote_file host delete $file2
122 set exec_output [binutils_run $AR "x $dest"]
123 set exec_output [prune_warnings $exec_output]
124 if ![string match "" $exec_output] {
125 verbose -log $exec_output
130 foreach bfdtest $bfdtests {
131 set exec_output [binutils_run "$base_dir/$bfdtest" "$dest"]
132 if ![string match "" $exec_output] {
133 verbose -log $exec_output
134 fail "$testname ($bfdtest)"
139 if [is_remote host] {
140 remote_upload host $n1 tmpdir/$n1
141 remote_upload host $n2 tmpdir/$n2
149 if ![file exists $file1] {
150 verbose -log "$file1 does not exist"
154 if ![file exists $file2] {
155 verbose -log "$file2 does not exist"
160 set f [open $file1 r]
161 if { [gets $f line] == -1 || $line != "first" } {
162 verbose -log "$file1 contents:"
170 set f [open $file2 r]
171 if { [gets $f line] == -1 || $line != "second" } {
172 verbose -log "$file2 contents:"
180 file delete $file1 $file2
184 # Test building the symbol table.
186 proc symbol_table { } {
193 set testname "ar symbol table"
195 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
200 if [is_remote host] {
202 set objfile [remote_download host tmpdir/bintest.o]
203 remote_file host delete $archive
205 set archive tmpdir/artest.a
206 set objfile tmpdir/bintest.o
209 remote_file build delete tmpdir/artest.a
211 set got [binutils_run $AR "rc $archive ${objfile}"]
212 if ![string match "" $got] {
217 set got [binutils_run $NM "--print-armap $archive"]
218 if { ![string match "*text_symbol in bintest.o*" $got] \
219 || ![string match "*data_symbol in bintest.o*" $got] \
220 || ![string match "*common_symbol in bintest.o*" $got] \
221 || [string match "*static_text_symbol in bintest.o*" $got] \
222 || [string match "*static_data_symbol in bintest.o*" $got] \
223 || [string match "*external_symbol in bintest.o*" $got] } {
231 # Test building a thin archive.
233 proc thin_archive { bfdtests } {
241 set testname "ar thin archive"
243 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
248 if [is_remote host] {
250 set objfile [remote_download host tmpdir/bintest.o]
251 remote_file host delete $archive
253 set archive tmpdir/artest.a
254 set objfile tmpdir/bintest.o
257 remote_file build delete tmpdir/artest.a
259 set got [binutils_run $AR "rcT $archive ${objfile}"]
260 if ![string match "" $got] {
265 foreach bfdtest $bfdtests {
266 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
267 if ![string match "" $exec_output] {
268 verbose -log $exec_output
269 fail "$testname ($bfdtest)"
274 set got [binutils_run $NM "--print-armap $archive"]
275 if { ![string match "*text_symbol in *bintest.o*" $got] \
276 || ![string match "*data_symbol in *bintest.o*" $got] \
277 || ![string match "*common_symbol in *bintest.o*" $got] \
278 || [string match "*static_text_symbol in *bintest.o*" $got] \
279 || [string match "*static_data_symbol in *bintest.o*" $got] \
280 || [string match "*external_symbol in *bintest.o*" $got] } {
288 # Test building a thin archive with a nested archive.
290 proc thin_archive_with_nested { bfdtests } {
298 set testname "ar thin archive with nested archive"
300 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
305 if [is_remote host] {
307 set archive2 artest2.a
308 set objfile [remote_download host tmpdir/bintest.o]
309 remote_file host delete $archive
311 set archive tmpdir/artest.a
312 set archive2 tmpdir/artest2.a
313 set objfile tmpdir/bintest.o
316 remote_file build delete tmpdir/artest.a
318 set got [binutils_run $AR "rc $archive ${objfile}"]
319 if ![string match "" $got] {
324 remote_file build delete tmpdir/artest2.a
326 set got [binutils_run $AR "rcT $archive2 ${archive}"]
327 if ![string match "" $got] {
332 foreach bfdtest $bfdtests {
333 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
334 if ![string match "" $exec_output] {
335 verbose -log $exec_output
336 fail "$testname ($bfdtest)"
340 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive2"]
341 if ![string match "" $exec_output] {
342 verbose -log $exec_output
343 fail "$testname ($bfdtest)"
348 set got [binutils_run $NM "--print-armap $archive"]
349 if { ![string match "*text_symbol in *bintest.o*" $got] \
350 || ![string match "*data_symbol in *bintest.o*" $got] \
351 || ![string match "*common_symbol in *bintest.o*" $got] \
352 || [string match "*static_text_symbol in *bintest.o*" $got] \
353 || [string match "*static_data_symbol in *bintest.o*" $got] \
354 || [string match "*external_symbol in *bintest.o*" $got] } {
362 # Test POSIX-compatible argument parsing.
364 proc argument_parsing { } {
370 set testname "ar argument parsing"
372 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
377 if [is_remote host] {
379 set objfile [remote_download host tmpdir/bintest.o]
380 remote_file host delete $archive
382 set archive tmpdir/artest.a
383 set objfile tmpdir/bintest.o
386 remote_file build delete tmpdir/artest.a
388 set got [binutils_run $AR "-r -c $archive ${objfile}"]
389 if ![string match "" $got] {
397 # Test building a deterministic archive.
399 proc deterministic_archive { } {
406 set testname "ar deterministic archive"
408 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
413 if [is_remote host] {
415 set objfile [remote_download host tmpdir/bintest.o]
416 remote_file host delete $archive
418 set archive tmpdir/artest.a
419 set objfile tmpdir/bintest.o
422 remote_file build delete tmpdir/artest.a
424 set got [binutils_run $AR "rcD $archive ${objfile}"]
425 if ![string match "" $got] {
430 set got [binutils_run $AR "tv $archive"]
431 # This only checks the file mode and uid/gid. We can't easily match
432 # date because it's printed with the user's timezone.
433 if ![string match "rw-r--r-- 0/0 *bintest.o*" $got] {
441 proc unique_symbol { } {
448 set testname "ar unique symbol in archive"
450 if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.o] {
455 if [is_remote host] {
457 set objfile [remote_download host tmpdir/unique.o]
458 remote_file host delete $archive
460 set archive tmpdir/artest.a
461 set objfile tmpdir/unique.o
464 remote_file build delete tmpdir/artest.a
466 set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
467 if ![string match "" $got] {
472 set got [binutils_run $NM "--print-armap $archive"]
473 if ![string match "*foo in *unique.o*" $got] {
481 # Test deleting an element.
483 proc delete_an_element { } {
489 set testname "ar deleting an element"
491 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
496 if [is_remote host] {
498 set objfile [remote_download host tmpdir/bintest.o]
499 remote_file host delete $archive
501 set archive tmpdir/artest.a
502 set objfile tmpdir/bintest.o
505 remote_file build delete tmpdir/artest.a
507 set got [binutils_run $AR "-r -c $archive ${objfile}"]
508 if ![string match "" $got] {
513 set got [binutils_run $AR "-d $archive ${objfile}"]
514 if ![string match "" $got] {
522 # Test moving an element.
524 proc move_an_element { } {
530 set testname "ar moving an element"
532 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.o] {
537 if [is_remote host] {
539 set objfile [remote_download host tmpdir/bintest.o]
540 remote_file host delete $archive
542 set archive tmpdir/artest.a
543 set objfile tmpdir/bintest.o
546 remote_file build delete tmpdir/artest.a
548 set got [binutils_run $AR "-r -c $archive ${objfile}"]
549 if ![string match "" $got] {
554 set got [binutils_run $AR "-m $archive ${objfile}"]
555 if ![string match "" $got] {
563 # PR 19775: Test creating and listing archives with an empty element.
565 proc empty_archive { } {
570 set testname "archive with empty element"
572 # FIXME: There ought to be a way to dynamically create an empty file.
573 set empty $srcdir/$subdir/empty
575 if [is_remote host] {
577 set objfile [remote_download host $empty]
578 remote_file host delete $archive
580 set archive tmpdir/artest.a
584 remote_file build delete tmpdir/artest.a
586 set got [binutils_run $AR "-r -c $archive ${objfile}"]
587 if ![string match "" $got] {
592 # This commmand used to fail with: "Malformed archive".
593 set got [binutils_run $AR "-t $archive"]
594 if ![string match "empty
" $got] {
604 # Only run the bfdtest checks if the programs exist. Since these
605 # programs are built but not installed, running the testsuite on an
606 # installed toolchain will produce ERRORs about missing bfdtest1 and
607 # bfdtest2 executables.
608 if { ![istarget "tic30-*-*"] && [file exists $base_dir/bfdtest1] && [file exists $base_dir/bfdtest2] } {
609 set bfdtests [list bfdtest1 bfdtest2]
611 long_filenames $bfdtests
612 thin_archive $bfdtests
613 thin_archive_with_nested $bfdtests
618 deterministic_archive
623 if { [is_elf_format] && [supports_gnu_unique] } {