1 # Copyright (C) 1995-2020 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"
30 if { [istarget "*-*-vms"] } then {
34 # send_user "Version [binutil_version $AR]"
36 # Test long file name support
38 proc long_filenames { bfdtests } {
43 set testname "ar long file names"
45 set n1 "abcdefghijklmnopqrstuvwxyz1"
46 set n2 "abcdefghijklmnopqrstuvwxyz2"
50 remote_file build delete $file1
51 remote_file host delete $n1
53 # Some file systems truncate file names at 14 characters, which
54 # makes it impossible to run this test. Check for that now.
55 set status [catch "set f [open tmpdir/$n1 w]" errs]
57 verbose -log "open tmpdir/$n1 returned $errs"
64 remote_file build delete $file2
65 remote_file host delete $n2
67 set status [catch "set f [open tmpdir/$n2 w]" errs]
69 verbose -log "open tmpdir/$n2 returned $errs"
77 set file1 [remote_download host $file1]
78 set file2 [remote_download host $file2]
81 set dest tmpdir/artest.a
84 remote_file host delete $dest
86 set got [binutils_run $AR "rc $dest $file1 $file2"]
88 remote_upload host $file1 tmpdir/$n1
91 set f [open tmpdir/$n1 r]
94 if ![string match "first" $string] {
95 verbose -log "reading tmpdir/$n1 returned $string"
100 remote_file host delete $dest
101 set got [binutils_run $AR "rc $dest $file1 $file2"]
103 if ![string match "" $got] {
108 remote_file build delete tmpdir/$n1
109 remote_file build delete tmpdir/$n2
111 set got [binutils_run $AR "t $dest"]
112 regsub "\[\r\n \t\]*$" "$got" "" got
113 if ![string match "$n1*$n2" $got] {
118 if [is_remote host] {
119 remote_file host delete $file1
120 remote_file host delete $file2
123 set exec_output [binutils_run $AR "x $dest"]
124 set exec_output [prune_warnings $exec_output]
125 if ![string match "" $exec_output] {
126 verbose -log $exec_output
131 foreach bfdtest $bfdtests {
132 set exec_output [binutils_run "$base_dir/$bfdtest" "$dest"]
133 if ![string match "" $exec_output] {
134 verbose -log $exec_output
135 fail "$testname ($bfdtest)"
140 if [is_remote host] {
141 remote_upload host $n1 tmpdir/$n1
142 remote_upload host $n2 tmpdir/$n2
150 if ![file exists $file1] {
151 verbose -log "$file1 does not exist"
155 if ![file exists $file2] {
156 verbose -log "$file2 does not exist"
161 set f [open $file1 r]
162 if { [gets $f line] == -1 || $line != "first" } {
163 verbose -log "$file1 contents:"
171 set f [open $file2 r]
172 if { [gets $f line] == -1 || $line != "second" } {
173 verbose -log "$file2 contents:"
181 file delete $file1 $file2
185 # Test building the symbol table.
187 proc symbol_table { } {
195 set testname "ar symbol table"
197 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
202 if [is_remote host] {
204 set objfile [remote_download host tmpdir/bintest.${obj}]
205 remote_file host delete $archive
207 set archive tmpdir/artest.a
208 set objfile tmpdir/bintest.${obj}
211 remote_file build delete tmpdir/artest.a
213 set got [binutils_run $AR "rc $archive ${objfile}"]
214 if ![string match "" $got] {
219 set got [binutils_run $NM "--print-armap $archive"]
220 if { ![string match "*text_symbol in bintest.${obj}*" $got] \
221 || ![string match "*data_symbol in bintest.${obj}*" $got] \
222 || ![string match "*common_symbol in bintest.${obj}*" $got] \
223 || [string match "*static_text_symbol in bintest.${obj}*" $got] \
224 || [string match "*static_data_symbol in bintest.${obj}*" $got] \
225 || [string match "*external_symbol in bintest.${obj}*" $got] } {
233 # Test building a thin archive.
235 proc thin_archive { bfdtests } {
244 set testname "ar thin archive"
246 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
251 if [is_remote host] {
253 set objfile [remote_download host tmpdir/bintest.${obj}]
254 remote_file host delete $archive
256 set archive tmpdir/artest.a
257 set objfile tmpdir/bintest.${obj}
260 remote_file build delete tmpdir/artest.a
262 set got [binutils_run $AR "rcT $archive ${objfile}"]
263 if ![string match "" $got] {
268 foreach bfdtest $bfdtests {
269 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
270 if ![string match "" $exec_output] {
271 verbose -log $exec_output
272 fail "$testname ($bfdtest)"
277 set got [binutils_run $NM "--print-armap $archive"]
278 if { ![string match "*text_symbol in *bintest.${obj}*" $got] \
279 || ![string match "*data_symbol in *bintest.${obj}*" $got] \
280 || ![string match "*common_symbol in *bintest.${obj}*" $got] \
281 || [string match "*static_text_symbol in *bintest.${obj}*" $got] \
282 || [string match "*static_data_symbol in *bintest.${obj}*" $got] \
283 || [string match "*external_symbol in *bintest.${obj}*" $got] } {
291 # Test building a thin archive with a nested archive.
293 proc thin_archive_with_nested { bfdtests } {
302 set testname "ar thin archive with nested archive"
304 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
309 if [is_remote host] {
311 set archive2 artest2.a
312 set objfile [remote_download host tmpdir/bintest.${obj}]
313 remote_file host delete $archive
315 set archive tmpdir/artest.a
316 set archive2 tmpdir/artest2.a
317 set objfile tmpdir/bintest.${obj}
320 remote_file build delete tmpdir/artest.a
322 set got [binutils_run $AR "rc $archive ${objfile}"]
323 if ![string match "" $got] {
328 remote_file build delete tmpdir/artest2.a
330 set got [binutils_run $AR "rcT $archive2 ${archive}"]
331 if ![string match "" $got] {
336 foreach bfdtest $bfdtests {
337 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
338 if ![string match "" $exec_output] {
339 verbose -log $exec_output
340 fail "$testname ($bfdtest)"
344 set exec_output [binutils_run "$base_dir/$bfdtest" "$archive2"]
345 if ![string match "" $exec_output] {
346 verbose -log $exec_output
347 fail "$testname ($bfdtest)"
352 set got [binutils_run $NM "--print-armap $archive"]
353 if { ![string match "*text_symbol in *bintest.${obj}*" $got] \
354 || ![string match "*data_symbol in *bintest.${obj}*" $got] \
355 || ![string match "*common_symbol in *bintest.${obj}*" $got] \
356 || [string match "*static_text_symbol in *bintest.${obj}*" $got] \
357 || [string match "*static_data_symbol in *bintest.${obj}*" $got] \
358 || [string match "*external_symbol in *bintest.${obj}*" $got] } {
366 # Test POSIX-compatible argument parsing.
368 proc argument_parsing { } {
375 set testname "ar argument parsing"
377 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
382 if [is_remote host] {
384 set objfile [remote_download host tmpdir/bintest.${obj}]
385 remote_file host delete $archive
387 set archive tmpdir/artest.a
388 set objfile tmpdir/bintest.${obj}
391 remote_file build delete tmpdir/artest.a
393 set got [binutils_run $AR "-r -c $archive ${objfile}"]
394 if ![string match "" $got] {
402 # Test building a deterministic archive.
404 proc deterministic_archive { } {
412 set testname "ar deterministic archive"
414 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
419 if [is_remote host] {
421 set objfile [remote_download host tmpdir/bintest.${obj}]
422 remote_file host delete $archive
424 set archive tmpdir/artest.a
425 set objfile tmpdir/bintest.${obj}
428 remote_file build delete tmpdir/artest.a
430 set got [binutils_run $AR "rcD $archive ${objfile}"]
431 if ![string match "" $got] {
436 set got [binutils_run $AR "tv $archive"]
437 # This only checks the file mode and uid/gid. We can't easily match
438 # date because it's printed with the user's timezone.
439 if ![string match "rw-r--r-- 0/0 *bintest.${obj}*" $got] {
444 set got [binutils_run $AR "tvO $archive"]
445 if ![string match "rw-r--r-- 0/0 *bintest.${obj} 0x*" $got] {
453 proc unique_symbol { } {
461 set testname "ar unique symbol in archive"
463 if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.${obj}] {
468 if [is_remote host] {
470 set objfile [remote_download host tmpdir/unique.${obj}]
471 remote_file host delete $archive
473 set archive tmpdir/artest.a
474 set objfile tmpdir/unique.${obj}
477 remote_file build delete tmpdir/artest.a
479 set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
480 if ![string match "" $got] {
485 set got [binutils_run $NM "--print-armap $archive"]
486 if ![string match "*foo in *unique.${obj}*" $got] {
494 # Test deleting an element.
496 proc delete_an_element { } {
503 set testname "ar deleting an element"
505 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
510 if [is_remote host] {
512 set objfile [remote_download host tmpdir/bintest.${obj}]
513 remote_file host delete $archive
515 set archive tmpdir/artest.a
516 set objfile tmpdir/bintest.${obj}
519 remote_file build delete tmpdir/artest.a
521 set got [binutils_run $AR "-r -c $archive ${objfile}"]
522 if ![string match "" $got] {
527 set got [binutils_run $AR "-d $archive ${objfile}"]
528 if ![string match "" $got] {
536 # Test moving an element.
538 proc move_an_element { } {
545 set testname "ar moving an element"
547 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
552 if [is_remote host] {
554 set objfile [remote_download host tmpdir/bintest.${obj}]
555 remote_file host delete $archive
557 set archive tmpdir/artest.a
558 set objfile tmpdir/bintest.${obj}
561 remote_file build delete tmpdir/artest.a
563 set got [binutils_run $AR "-r -c $archive ${objfile}"]
564 if ![string match "" $got] {
569 set got [binutils_run $AR "-m $archive ${objfile}"]
570 if ![string match "" $got] {
578 # PR 19775: Test creating and listing archives with an empty element.
580 proc empty_archive { } {
585 set testname "archive with empty element"
587 # FIXME: There ought to be a way to dynamically create an empty file.
588 set empty $srcdir/$subdir/empty
590 if [is_remote host] {
592 set objfile [remote_download host $empty]
593 remote_file host delete $archive
595 set archive tmpdir/artest.a
599 remote_file build delete tmpdir/artest.a
601 set got [binutils_run $AR "-r -c $archive ${objfile}"]
602 if ![string match "" $got] {
607 # This commmand used to fail with: "Malformed archive".
608 set got [binutils_run $AR "-t $archive"]
609 if ![string match "empty
" $got] {
617 # Test extracting an element.
619 proc extract_an_element { } {
626 set testname "ar extracting an element"
628 if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
635 if [is_remote host] {
636 set objfile [remote_download host tmpdir/bintest.${obj}]
637 remote_file host delete $archive
639 set objfile tmpdir/bintest.${obj}
642 remote_file build delete $archive
644 set got [binutils_run $AR "-r -c $archive ${objfile}"]
645 if ![string match "" $got] {
650 set got [binutils_run $AR "--output=tmpdir -x $archive ${objfile}"]
651 if ![string match "" $got] {
656 remote_file build delete $archive
657 remote_file build delete tmpdir/$archive
662 proc many_files { } {
669 set testname "ar many files"
673 for { set i 0 } { $i < $max_file } { incr i } {
674 set sfile "tmpdir/d-$i.s"
675 if [catch { set ofd [open $sfile w] } x] {
681 puts $ofd " .globl data_sym$i"
683 puts $ofd "data_sym$i:"
684 puts $ofd " .long $i"
687 set ofile "tmpdir/d-$i.${obj}"
688 if ![binutils_assemble $sfile $ofile] {
694 if [is_remote host] {
695 remote_file host delete $sfile
696 set objfile [remote_download host $ofile]
697 remote_file build delete $ofile
699 remote_file build delete $sfile
700 lappend ofiles $objfile
703 set archive tmpdir/many.a
704 remote_file host delete $archive
706 set got [binutils_run $AR "cr $archive $ofiles"]
707 if ![string match "" $got] {
712 remote_file host delete $archive
713 eval remote_file host delete $ofiles
720 # Only run the bfdtest checks if the programs exist. Since these
721 # programs are built but not installed, running the testsuite on an
722 # installed toolchain will produce ERRORs about missing bfdtest1 and
723 # bfdtest2 executables.
724 if { [file exists $base_dir/bfdtest1] && [file exists $base_dir/bfdtest2] } {
725 set bfdtests [list bfdtest1 bfdtest2]
727 long_filenames $bfdtests
729 # xcoff, ecoff, and vms archive support doesn't handle thin archives
730 if { ![istarget "*-*-aix*"]
731 && ![istarget "*-*-*ecoff"]
732 && ![istarget "*-*-vms"] } {
733 thin_archive $bfdtests
734 thin_archive_with_nested $bfdtests
740 deterministic_archive
747 if { [is_elf_format] && [supports_gnu_unique] } {