Update release-README after completing the 2.43 release.
[binutils-gdb.git] / binutils / testsuite / binutils-all / ar.exp
blob998cbe1f0a9f7993339bda13d1bd46321da87ca6
1 #   Copyright (C) 1995-2024 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"
25         return
26     }
29 set obj o
30 if { [istarget "*-*-vms"] } then {
31     set obj obj
34 # send_user "Version [binutil_version $AR]"
36 # Test long file name support
38 proc long_filenames { bfdtests } {
39     global AR
40     global host_triplet
41     global base_dir
43     set testname "ar long file names"
45     set n1 "abcdefghijklmnopqrstuvwxyz1"
46     set n2 "abcdefghijklmnopqrstuvwxyz2"
47     set file1 tmpdir/$n1
48     set file2 tmpdir/$n2
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]
56     if { $status != 0 } {
57         verbose -log "open tmpdir/$n1 returned $errs"
58         unsupported $testname
59         return
60     }
61     puts $f "first"
62     close $f
64     remote_file build delete $file2
65     remote_file host delete $n2
67     set status [catch "set f [open tmpdir/$n2 w]" errs]
68     if { $status != 0 } {
69         verbose -log "open tmpdir/$n2 returned $errs"
70         unsupported $testname
71         return
72     }
73     puts $f "second"
74     close $f
76     if [is_remote host] {
77         set file1 [remote_download host $file1]
78         set file2 [remote_download host $file2]
79         set dest artest.a
80     } else {
81         set dest tmpdir/artest.a
82     }
84     remote_file host delete $dest
86     set got [binutils_run $AR "rc $dest $file1 $file2"]
87     if [is_remote host] {
88         remote_upload host $file1 tmpdir/$n1
89     }
91     set f [open tmpdir/$n1 r]
92     gets $f string
93     close $f
94     if ![string match "first" $string] {
95         verbose -log "reading tmpdir/$n1 returned $string"
96         unsupported $testname
97         return
98     }
100     remote_file host delete $dest
101     set got [binutils_run $AR "rc $dest $file1 $file2"]
103     if ![string match "" $got] {
104         fail $testname
105         return
106     }
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] {
114         fail $testname
115         return
116     }
118     if [is_remote host] {
119         remote_file host delete $file1
120         remote_file host delete $file2
121     }
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
127         fail $testname
128         return
129     }
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)"
136             return
137         }
138     }
140     if [is_remote host] {
141         remote_upload host $n1 tmpdir/$n1
142         remote_upload host $n2 tmpdir/$n2
143         set file1 tmpdir/$n1
144         set file2 tmpdir/$n2
145     } else {
146         set file1 $n1
147         set file2 $n2
148     }
150     if ![file exists $file1] {
151         verbose -log "$file1 does not exist"
152         fail $testname
153         return
154     }
155     if ![file exists $file2] {
156         verbose -log "$file2 does not exist"
157         fail $testname
158         return
159     }
161     set f [open $file1 r]
162     if { [gets $f line] == -1 || $line != "first" } {
163         verbose -log "$file1 contents:"
164         verbose -log "$line"
165         close $f
166         fail $testname
167         return
168     }
169     close $f
171     set f [open $file2 r]
172     if { [gets $f line] == -1 || $line != "second" } {
173         verbose -log "$file2 contents:"
174         verbose -log "$line"
175         close $f
176         fail $testname
177         return
178     }
179     close $f
181     file delete $file1 $file2
182     pass $testname
185 # Test building the symbol table.
187 proc symbol_table { } {
188     global AR
189     global AS
190     global NM
191     global srcdir
192     global subdir
193     global obj
195     set testname "ar symbol table"
197     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
198         unsupported $testname
199         return
200     }
202     if [is_remote host] {
203         set archive artest.a
204         set objfile [remote_download host tmpdir/bintest.${obj}]
205         remote_file host delete $archive
206     } else {
207         set archive tmpdir/artest.a
208         set objfile tmpdir/bintest.${obj}
209     }
211     remote_file build delete tmpdir/artest.a
213     set got [binutils_run $AR "rc $archive ${objfile}"]
214     if ![string match "" $got] {
215         fail $testname
216         return
217     }
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] } {
226         fail $testname
227         return
228     }
230     pass $testname
233 # Test building a thin archive.
235 proc thin_archive { bfdtests } {
236     global AR
237     global AS
238     global NM
239     global srcdir
240     global subdir
241     global base_dir
242     global obj
244     set testname "ar thin archive"
246     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
247         unsupported $testname
248         return
249     }
251     if [is_remote host] {
252         set archive artest.a
253         set objfile [remote_download host tmpdir/bintest.${obj}]
254         remote_file host delete $archive
255     } else {
256         set archive tmpdir/artest.a
257         set objfile tmpdir/bintest.${obj}
258     }
260     remote_file build delete tmpdir/artest.a
262     set got [binutils_run $AR "rcT $archive ${objfile}"]
263     if ![string match "" $got] {
264         fail $testname
265         return
266     }
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)"
273             return
274         }
275     }
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] } {
284         fail $testname
285         return
286     }
288     pass $testname
291 # Test building a thin archive with a nested archive.
293 proc thin_archive_with_nested { bfdtests } {
294     global AR
295     global AS
296     global NM
297     global srcdir
298     global subdir
299     global base_dir
300     global obj
302     set testname "ar thin archive with nested archive"
304     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
305         unsupported $testname
306         return
307     }
309     if [is_remote host] {
310         set archive artest.a
311         set archive2 artest2.a
312         set archive3 artest3.a
313         set objfile [remote_download host tmpdir/bintest.${obj}]
314         remote_file host delete $archive
315     } else {
316         set archive tmpdir/artest.a
317         set archive2 tmpdir/artest2.a
318         set archive3 tmpdir/artest3.a
319         set objfile tmpdir/bintest.${obj}
320     }
322     remote_file build delete tmpdir/artest.a
324     set got [binutils_run $AR "rc $archive ${objfile}"]
325     if ![string match "" $got] {
326         fail $testname
327         return
328     }
330     remote_file build delete tmpdir/artest2.a
332     set got [binutils_run $AR "rcT $archive2 ${archive}"]
333     if ![string match "" $got] {
334         fail $testname
335         return
336     }
338     remote_file build delete tmpdir/artest3.a
340     set got [binutils_run $AR "rc --thin $archive3 ${archive}"]
341     if ![string match "" $got] {
342         fail $testname
343         return
344     }
346     foreach bfdtest $bfdtests {
347         set exec_output [binutils_run "$base_dir/$bfdtest" "$archive"]
348         if ![string match "" $exec_output] {
349             verbose -log $exec_output
350             fail "$testname ($bfdtest)"
351             return
352         }
354         set exec_output [binutils_run "$base_dir/$bfdtest" "$archive2"]
355         if ![string match "" $exec_output] {
356             verbose -log $exec_output
357             fail "$testname ($bfdtest)"
358             return
359         }
361         set exec_output [binutils_run "$base_dir/$bfdtest" "$archive3"]
362         if ![string match "" $exec_output] {
363             verbose -log $exec_output
364             fail "$testname ($bfdtest)"
365             return
366         }
367     }
369     set got [binutils_run $NM "--print-armap $archive"]
370     if { ![string match "*text_symbol in *bintest.${obj}*" $got] \
371          || ![string match "*data_symbol in *bintest.${obj}*" $got] \
372          || ![string match "*common_symbol in *bintest.${obj}*" $got] \
373          || [string match "*static_text_symbol in *bintest.${obj}*" $got] \
374          || [string match "*static_data_symbol in *bintest.${obj}*" $got] \
375          || [string match "*external_symbol in *bintest.${obj}*" $got] } {
376         fail $testname
377         return
378     }
380     pass $testname
383 # Test POSIX-compatible argument parsing.
385 proc argument_parsing { } {
386     global AR
387     global AS
388     global srcdir
389     global subdir
390     global obj
392     set testname "ar argument parsing"
394     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
395         unsupported $testname
396         return
397     }
399     if [is_remote host] {
400         set archive artest.a
401         set objfile [remote_download host tmpdir/bintest.${obj}]
402         remote_file host delete $archive
403     } else {
404         set archive tmpdir/artest.a
405         set objfile tmpdir/bintest.${obj}
406     }
408     remote_file build delete tmpdir/artest.a
410     set got [binutils_run $AR "-r -c $archive ${objfile}"]
411     if ![string match "" $got] {
412         fail $testname
413         return
414     }
416     pass $testname
419 # Test building a deterministic archive.
421 proc deterministic_archive { } {
422     global AR
423     global AS
424     global NM
425     global srcdir
426     global subdir
427     global obj
429     set testname "ar deterministic archive"
431     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
432         unsupported $testname
433         return
434     }
436     if [is_remote host] {
437         set archive artest.a
438         set objfile [remote_download host tmpdir/bintest.${obj}]
439         remote_file host delete $archive
440     } else {
441         set archive tmpdir/artest.a
442         set objfile tmpdir/bintest.${obj}
443     }
445     remote_file build delete tmpdir/artest.a
447     set got [binutils_run $AR "rcD $archive ${objfile}"]
448     if ![string match "" $got] {
449         fail $testname
450         return
451     }
453     set got [binutils_run $AR "tv $archive"]
454     # This only checks the file mode and uid/gid.  We can't easily match
455     # date because it's printed with the user's timezone.
456     if ![string match "rw-r--r-- 0/0 *bintest.${obj}*" $got] {
457         fail $testname
458         return
459     }
461     set got [binutils_run $AR "tvO $archive"]
462     if ![string match "rw-r--r-- 0/0 *bintest.${obj} 0x*" $got] {
463         fail $testname
464         return
465     }
467     pass $testname
470 # Test replacing a member of a deterministic archive.
472 proc replacing_deterministic_member { } {
473     global AR
474     global AS
475     global NM
476     global srcdir
477     global subdir
478     global obj
480     set testname "replacing deterministic member"
482     if [is_remote host] {
483         # The kind of filename trickery that we are about to
484         #  play is hard to do if we have to operate remotely.
485         unsupported $testname
486         return
487     }
489     file mkdir tmpdir/ar
490     
491     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
492         unsupported $testname
493         return
494     }
496     # Wait a second and then build a second object file - with the same name
497     # as the first, but in a different directory.
498     sleep 1
499     if ![binutils_assemble $srcdir/$subdir/copytest.s tmpdir/ar/bintest.${obj}] {
500         unsupported $testname
501         return
502     }
504     set archive tmpdir/artest.a
505     set older_objfile tmpdir/bintest.${obj}
506     set newer_objfile tmpdir/ar/bintest.${obj}
507     set older_length [file size $older_objfile]
508     # set newer_length [file size $newer_objfile]
509     
510     remote_file build delete tmpdir/artest.a
512     # Build the archive with the *newer* object file.
513     
514     set got [binutils_run $AR "rcD $archive ${newer_objfile}"]
515     if ![string match "" $got] {
516         fail "$testname: (could not build archive)"
517         return
518     }
520     # Now replace the newer file with the older one.  On a normal
521     # archive this will not work, but one created to be deterministic
522     # should always replace its members.
523     
524     set got [binutils_run $AR "ruD $archive $older_objfile"]
525     # The archiver will warn that 'u' and 'D' do not work together
526     if ![string match "*not meaningful*" $got] {
527         fail "$testname: (failed to replace file)"
528         return
529     }
531     set got [binutils_run $AR "tvO $archive"]
532     if ![string match "rw-r--r-- 0/0 *${older_length} *bintest.${obj} 0x*" $got] {
533         fail "$testname (wrong size, expected: $older_length)"
534         return
535     }
537     pass $testname
540 # Test replacing a member of a non-deterministic archive.
541 # This test expects SOURCE_DATE_EPOCH to not be set in the environment.
543 proc replacing_non_deterministic_member { } {
544     global AR
545     global AS
546     global NM
547     global srcdir
548     global subdir
549     global obj
551     set testname "replacing non-deterministic member"
553     if [is_remote host] {
554         # The kind of filename trickery that we are about to
555         #  play is hard to do if we have to operate remotely.
556         unsupported $testname
557         return
558     }
560     file mkdir tmpdir/ar
561     
562     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
563         unsupported $testname
564         return
565     }
567     # Wait a second and then build a second object file - with the same name
568     # as the first, but in a different directory.
569     sleep 1
570     if ![binutils_assemble $srcdir/$subdir/copytest.s tmpdir/ar/bintest.${obj}] {
571         unsupported $testname
572         return
573     }
575     set archive tmpdir/artest.a
576     set older_objfile tmpdir/bintest.${obj}
577     set newer_objfile tmpdir/ar/bintest.${obj}
578     # set older_length [file size $older_objfile]
579     set newer_length [file size $newer_objfile]
580     
581     remote_file build delete tmpdir/artest.a
583     # Build the archive with the *newer* object file.
584     
585     set got [binutils_run $AR "rcU $archive ${newer_objfile}"]
586     if ![string match "" $got] {
587         fail "$testname: (could not build archive)"
588         return
589     }
591     # Now try to replace the newer file with the older one.  This should not work.
592     
593     set got [binutils_run $AR "ruU $archive $older_objfile"]
594     if ![string match "" $got] {
595         fail "$testname: (failed to replace file)"
596         return
597     }
599     # Since this archive is non-deterministic, we do not know what the
600     # user or group ids will be, so we have to use */* to match them.
601     set got [binutils_run $AR "tvO $archive"]
602     if ![string match "\[rw-\]* */* *${newer_length} *bintest.${obj} 0x*" $got] {
603         fail "$testname (wrong size, expected: $newer_length)"
604         return
605     }
607     pass $testname
610 # Test replacing a member of deterministic archive created by using SOURCE_DATE_EPOCH.
612 proc replacing_sde_deterministic_member { } {
613     global AR
614     global AS
615     global NM
616     global srcdir
617     global subdir
618     global obj
620     set testname "replacing SOURCE_DATE_EPOCH deterministic member"
622     if [is_remote host] {
623         # The kind of filename trickery that we are about to
624         #  play is hard to do if we have to operate remotely.
625         unsupported $testname
626         return
627     }
629     file mkdir tmpdir/ar
630     
631     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
632         unsupported $testname
633         return
634     }
636     # Wait a second and then build a second object file - with the same name
637     # as the first, but in a different directory.
638     sleep 1
639     if ![binutils_assemble $srcdir/$subdir/copytest.s tmpdir/ar/bintest.${obj}] {
640         unsupported $testname
641         return
642     }
644     set archive tmpdir/artest.a
645     set older_objfile tmpdir/bintest.${obj}
646     set newer_objfile tmpdir/ar/bintest.${obj}
647     set older_length [file size $older_objfile]
648     # set newer_length [file size $newer_objfile]
649     
650     remote_file build delete tmpdir/artest.a
652     # Build the archive with the *newer* object file.
653     setenv SOURCE_DATE_EPOCH "1000"
654     
655     set got [binutils_run $AR "rcU $archive ${newer_objfile}"]
656     if ![string match "" $got] {
657         fail "$testname: (could not build archive)"
658         unsetenv SOURCE_DATE_EPOCH
659         return
660     }
662     # Now replace the newer file with the older one.  On a normal
663     # archive this will not work, but one created to be deterministic
664     # should always replace its members.
665     
666     set got [binutils_run $AR "ruU $archive $older_objfile"]
667     if ![string match "" $got] {
668         fail "$testname: (failed to replace file)"
669         unsetenv SOURCE_DATE_EPOCH
670         return
671     }
673     # Since this archive has fixed source dates, but non-deterministic
674     # uid and gid values we have to use */* to match them.
675     set got [binutils_run $AR "tvO $archive"]
676     if ![string match "\[rw-\]* */* *${older_length} *bintest.${obj} 0x*" $got] {
677         fail "$testname (wrong size, expected: $older_length)"
678         unsetenv SOURCE_DATE_EPOCH
679         return
680     }
682     # FIXME - it would be nice if we could check to see that the time & date
683     # in the archive listing matches SOURCE_DATE_EPOCH.
685     unsetenv SOURCE_DATE_EPOCH
686     pass $testname
690 proc unique_symbol { } {
691     global AR
692     global AS
693     global NM
694     global srcdir
695     global subdir
696     global obj
698     set testname "ar unique symbol in archive"
700     if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.${obj}] {
701         unsupported $testname
702         return
703     }
705     if [is_remote host] {
706         set archive artest.a
707         set objfile [remote_download host tmpdir/unique.${obj}]
708         remote_file host delete $archive
709     } else {
710         set archive tmpdir/artest.a
711         set objfile tmpdir/unique.${obj}
712     }
714     remote_file build delete tmpdir/artest.a
716     set got [binutils_run $AR "-s -r -c $archive ${objfile}"]
717     if ![string match "" $got] {
718         fail $testname
719         return
720     }
722     set got [binutils_run $NM "--print-armap $archive"]
723     if ![string match "*foo in *unique.${obj}*" $got] {
724         fail $testname
725         return
726     }
728     pass $testname
731 # Test deleting an element.
733 proc delete_an_element { } {
734     global AR
735     global AS
736     global srcdir
737     global subdir
738     global obj
740     set testname "ar deleting an element"
742     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
743         unsupported $testname
744         return
745     }
747     if [is_remote host] {
748         set archive artest.a
749         set objfile [remote_download host tmpdir/bintest.${obj}]
750         remote_file host delete $archive
751     } else {
752         set archive tmpdir/artest.a
753         set objfile tmpdir/bintest.${obj}
754     }
756     remote_file build delete tmpdir/artest.a
758     set got [binutils_run $AR "-r -c $archive ${objfile}"]
759     if ![string match "" $got] {
760         fail $testname
761         return
762     }
764     set got [binutils_run $AR "-d $archive ${objfile}"]
765     if ![string match "" $got] {
766         fail $testname
767         return
768     }
770     pass $testname
773 # Test moving an element.
775 proc move_an_element { } {
776     global AR
777     global AS
778     global srcdir
779     global subdir
780     global obj
782     set testname "ar moving an element"
784     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
785         unsupported $testname
786         return
787     }
789     if [is_remote host] {
790         set archive artest.a
791         set objfile [remote_download host tmpdir/bintest.${obj}]
792         remote_file host delete $archive
793     } else {
794         set archive tmpdir/artest.a
795         set objfile tmpdir/bintest.${obj}
796     }
798     remote_file build delete tmpdir/artest.a
800     set got [binutils_run $AR "-r -c $archive ${objfile}"]
801     if ![string match "" $got] {
802         fail $testname
803         return
804     }
806     set got [binutils_run $AR "-m $archive ${objfile}"]
807     if ![string match "" $got] {
808         fail $testname
809         return
810     }
812     pass $testname
815 # PR 19775: Test creating and listing archives with an empty element.
817 proc empty_archive { } {
818     global AR
819     global srcdir
820     global subdir
822     set testname "archive with empty element"
824     # FIXME: There ought to be a way to dynamically create an empty file.
825     set empty $srcdir/$subdir/empty
827     if [is_remote host] {
828         set archive artest.a
829         set objfile [remote_download host $empty]
830         remote_file host delete $archive
831     } else {
832         set archive tmpdir/artest.a
833         set objfile $empty
834     }
836     remote_file build delete tmpdir/artest.a
838     set got [binutils_run $AR "-r -c $archive ${objfile}"]
839     if ![string match "" $got] {
840         fail $testname
841         return
842     }
844     # This commmand used to fail with: "Malformed archive".
845     set got [binutils_run $AR "-t $archive"]
846     if ![string match "empty
847 " $got] {
848         fail $testname
849         return
850     }
852     pass $testname
855 # Test extracting an element.
857 proc extract_an_element { } {
858     global AR
859     global AS
860     global srcdir
861     global subdir
862     global obj
864     set testname "ar extracting an element"
866     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
867         unsupported $testname
868         return
869     }
871     set archive artest.a
873     if [is_remote host] {
874         set objfile [remote_download host tmpdir/bintest.${obj}]
875         remote_file host delete $archive
876     } else {
877         set objfile tmpdir/bintest.${obj}
878     }
880     remote_file build delete $archive
882     set got [binutils_run $AR "-r -c $archive ${objfile}"]
883     if ![string match "" $got] {
884         fail $testname
885         return
886     }
888     set got [binutils_run $AR "--output=tmpdir -x $archive ${objfile}"]
889     if ![string match "" $got] {
890         fail $testname
891         return
892     }
894     remote_file build delete $archive
895     remote_file build delete tmpdir/$archive
897     pass $testname
900 proc many_files { } {
901     global AR
902     global AS
903     global srcdir
904     global subdir
905     global obj
907     set testname "ar many files"
909     set ofiles {}
910     set max_file 150
911     for { set i 0 } { $i < $max_file } { incr i } {
912         set sfile "tmpdir/d-$i.s"
913         if [catch { set ofd [open $sfile w] } x] {
914             perror "$x"
915             unresolved $testname
916             return
917         }
919         puts $ofd " .globl data_sym$i"
920         puts $ofd " .data"
921         puts $ofd "data_sym$i:"
922         puts $ofd " .long $i"
923         close $ofd
925         set ofile "tmpdir/d-$i.${obj}"
926         if ![binutils_assemble $sfile $ofile] {
927             unsupported $testname
928             return
929         }
931         set objfile $ofile
932         if [is_remote host] {
933             remote_file host delete $sfile
934             set objfile [remote_download host $ofile]
935             remote_file build delete $ofile
936         }
937         remote_file build delete $sfile
938         lappend ofiles $objfile
939     }
941     set archive tmpdir/many.a
942     remote_file host delete $archive
944     set got [binutils_run $AR "cr $archive $ofiles"]
945     if ![string match "" $got] {
946         fail $testname
947         return
948     }
950     remote_file host delete $archive
951     eval remote_file host delete $ofiles
953     pass $testname
956 proc test_add_dependencies { } {
957     global AR
958     global AS
959     global srcdir
960     global subdir
961     global obj
963     set testname "ar adding library dependencies"
965     if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] {
966         unsupported $testname
967         return
968     }
970     if [is_remote host] {
971         set archive artest.a
972         set objfile [remote_download host tmpdir/bintest.${obj}]
973         remote_file host delete $archive
974     } else {
975         set archive tmpdir/artest.a
976         set objfile tmpdir/bintest.${obj}
977     }
979     remote_file build delete tmpdir/artest.a
981     set got [binutils_run $AR "-r -c $archive --record-libdeps /foo/bar ${objfile}"]
982     if ![string match "" $got] {
983         fail $testname
984         return
985     }
987     set got [binutils_run $AR "-t $archive"]
988     if ![string match "*bintest.${obj}
989 __.LIBDEP*" $got] {
990         fail $testname
991         return
992     }
994     pass $testname
997 # Run the tests.
999 # Only run the bfdtest checks if the programs exist.  Since these
1000 # programs are built but not installed, running the testsuite on an
1001 # installed toolchain will produce ERRORs about missing bfdtest1 and
1002 # bfdtest2 executables.
1003 if { [file exists $base_dir/bfdtest1] && [file exists $base_dir/bfdtest2] } {
1004     set bfdtests [list bfdtest1 bfdtest2]
1006     long_filenames $bfdtests
1008     # xcoff, ecoff, and vms archive support doesn't handle thin archives
1009     if { ![is_xcoff_format]
1010          && ![istarget "*-*-*ecoff"]
1011          && ![istarget "*-*-vms"] } {
1012         thin_archive $bfdtests
1013         thin_archive_with_nested $bfdtests
1014     }
1017 symbol_table
1018 argument_parsing
1019 deterministic_archive
1020 replacing_deterministic_member
1021 replacing_non_deterministic_member
1022 replacing_sde_deterministic_member
1023 delete_an_element
1024 move_an_element
1025 empty_archive
1026 extract_an_element
1027 many_files
1028 test_add_dependencies
1030 if { [is_elf_format] && [supports_gnu_unique] } {
1031     unique_symbol