Commit | Line | Data |
---|---|---|
b3adc24a | 1 | # Copyright (C) 1995-2020 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 | 6 | # (at your option) any later version. |
1869e86f | 7 | # |
252b5132 RH |
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. | |
1869e86f | 12 | # |
252b5132 RH |
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 | ||
22 | if ![is_remote host] { | |
23 | if {[which $AR] == 0} then { | |
24 | perror "$AR does not exist" | |
25 | return | |
26 | } | |
27 | } | |
28 | ||
0bee4d1c AM |
29 | set obj o |
30 | if { [istarget "*-*-vms"] } then { | |
31 | set obj obj | |
96037eb0 NC |
32 | } |
33 | ||
252b5132 RH |
34 | # send_user "Version [binutil_version $AR]" |
35 | ||
36 | # Test long file name support | |
37 | ||
f7da43f3 | 38 | proc long_filenames { bfdtests } { |
252b5132 RH |
39 | global AR |
40 | global host_triplet | |
f7da43f3 | 41 | global base_dir |
252b5132 RH |
42 | |
43 | set testname "ar long file names" | |
44 | ||
45 | set n1 "abcdefghijklmnopqrstuvwxyz1" | |
46 | set n2 "abcdefghijklmnopqrstuvwxyz2" | |
47 | set file1 tmpdir/$n1 | |
48 | set file2 tmpdir/$n2 | |
49 | ||
50 | remote_file build delete $file1 | |
7f6a71ff | 51 | remote_file host delete $n1 |
252b5132 RH |
52 | |
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 | |
63 | ||
252b5132 | 64 | remote_file build delete $file2 |
7f6a71ff | 65 | remote_file host delete $n2 |
252b5132 RH |
66 | |
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 | |
75 | ||
76 | if [is_remote host] { | |
8d263650 BE |
77 | set file1 [remote_download host $file1] |
78 | set file2 [remote_download host $file2] | |
252b5132 RH |
79 | set dest artest.a |
80 | } else { | |
81 | set dest tmpdir/artest.a | |
82 | } | |
83 | ||
8d263650 | 84 | remote_file host delete $dest |
252b5132 RH |
85 | |
86 | set got [binutils_run $AR "rc $dest $file1 $file2"] | |
87 | if [is_remote host] { | |
88 | remote_upload host $file1 tmpdir/$n1 | |
89 | } | |
90 | ||
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 | } | |
99 | ||
8d263650 | 100 | remote_file host delete $dest |
252b5132 RH |
101 | set got [binutils_run $AR "rc $dest $file1 $file2"] |
102 | ||
103 | if ![string match "" $got] { | |
104 | fail $testname | |
105 | return | |
106 | } | |
107 | ||
108 | remote_file build delete tmpdir/$n1 | |
109 | remote_file build delete tmpdir/$n2 | |
110 | ||
111 | set got [binutils_run $AR "t $dest"] | |
8d263650 | 112 | regsub "\[\r\n \t\]*$" "$got" "" got |
252b5132 RH |
113 | if ![string match "$n1*$n2" $got] { |
114 | fail $testname | |
115 | return | |
116 | } | |
1869e86f | 117 | |
252b5132 | 118 | if [is_remote host] { |
8d263650 BE |
119 | remote_file host delete $file1 |
120 | remote_file host delete $file2 | |
252b5132 RH |
121 | } |
122 | ||
252b5132 RH |
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 | } | |
130 | ||
f7da43f3 L |
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 | } | |
58f594cd L |
138 | } |
139 | ||
252b5132 | 140 | if [is_remote host] { |
8d263650 BE |
141 | remote_upload host $n1 tmpdir/$n1 |
142 | remote_upload host $n2 tmpdir/$n2 | |
252b5132 RH |
143 | set file1 tmpdir/$n1 |
144 | set file2 tmpdir/$n2 | |
145 | } else { | |
146 | set file1 $n1 | |
147 | set file2 $n2 | |
148 | } | |
149 | ||
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 | } | |
160 | ||
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 | |
170 | ||
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 | |
180 | ||
690649be | 181 | file delete $file1 $file2 |
252b5132 RH |
182 | pass $testname |
183 | } | |
184 | ||
185 | # Test building the symbol table. | |
186 | ||
187 | proc symbol_table { } { | |
188 | global AR | |
189 | global AS | |
190 | global NM | |
191 | global srcdir | |
192 | global subdir | |
0bee4d1c | 193 | global obj |
252b5132 RH |
194 | |
195 | set testname "ar symbol table" | |
196 | ||
0bee4d1c | 197 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
252b5132 RH |
198 | unresolved $testname |
199 | return | |
200 | } | |
201 | ||
202 | if [is_remote host] { | |
203 | set archive artest.a | |
0bee4d1c | 204 | set objfile [remote_download host tmpdir/bintest.${obj}] |
252b5132 RH |
205 | remote_file host delete $archive |
206 | } else { | |
207 | set archive tmpdir/artest.a | |
0bee4d1c | 208 | set objfile tmpdir/bintest.${obj} |
252b5132 RH |
209 | } |
210 | ||
211 | remote_file build delete tmpdir/artest.a | |
212 | ||
213 | set got [binutils_run $AR "rc $archive ${objfile}"] | |
214 | if ![string match "" $got] { | |
215 | fail $testname | |
216 | return | |
217 | } | |
218 | ||
219 | set got [binutils_run $NM "--print-armap $archive"] | |
0bee4d1c AM |
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] } { | |
252b5132 RH |
226 | fail $testname |
227 | return | |
228 | } | |
229 | ||
230 | pass $testname | |
231 | } | |
232 | ||
a8da6403 NC |
233 | # Test building a thin archive. |
234 | ||
f7da43f3 | 235 | proc thin_archive { bfdtests } { |
a8da6403 NC |
236 | global AR |
237 | global AS | |
238 | global NM | |
239 | global srcdir | |
240 | global subdir | |
f7da43f3 | 241 | global base_dir |
0bee4d1c | 242 | global obj |
a8da6403 NC |
243 | |
244 | set testname "ar thin archive" | |
245 | ||
0bee4d1c | 246 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
a8da6403 NC |
247 | unresolved $testname |
248 | return | |
249 | } | |
250 | ||
251 | if [is_remote host] { | |
252 | set archive artest.a | |
0bee4d1c | 253 | set objfile [remote_download host tmpdir/bintest.${obj}] |
a8da6403 NC |
254 | remote_file host delete $archive |
255 | } else { | |
256 | set archive tmpdir/artest.a | |
0bee4d1c | 257 | set objfile tmpdir/bintest.${obj} |
a8da6403 NC |
258 | } |
259 | ||
260 | remote_file build delete tmpdir/artest.a | |
261 | ||
262 | set got [binutils_run $AR "rcT $archive ${objfile}"] | |
263 | if ![string match "" $got] { | |
264 | fail $testname | |
265 | return | |
266 | } | |
267 | ||
f7da43f3 L |
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 | } | |
58f594cd L |
275 | } |
276 | ||
a8da6403 | 277 | set got [binutils_run $NM "--print-armap $archive"] |
0bee4d1c AM |
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] } { | |
a8da6403 NC |
284 | fail $testname |
285 | return | |
286 | } | |
287 | ||
288 | pass $testname | |
289 | } | |
290 | ||
291 | # Test building a thin archive with a nested archive. | |
292 | ||
f7da43f3 | 293 | proc thin_archive_with_nested { bfdtests } { |
a8da6403 NC |
294 | global AR |
295 | global AS | |
296 | global NM | |
297 | global srcdir | |
298 | global subdir | |
f7da43f3 | 299 | global base_dir |
0bee4d1c | 300 | global obj |
a8da6403 NC |
301 | |
302 | set testname "ar thin archive with nested archive" | |
303 | ||
0bee4d1c | 304 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
a8da6403 NC |
305 | unresolved $testname |
306 | return | |
307 | } | |
308 | ||
309 | if [is_remote host] { | |
310 | set archive artest.a | |
311 | set archive2 artest2.a | |
0bee4d1c | 312 | set objfile [remote_download host tmpdir/bintest.${obj}] |
a8da6403 NC |
313 | remote_file host delete $archive |
314 | } else { | |
315 | set archive tmpdir/artest.a | |
316 | set archive2 tmpdir/artest2.a | |
0bee4d1c | 317 | set objfile tmpdir/bintest.${obj} |
a8da6403 NC |
318 | } |
319 | ||
320 | remote_file build delete tmpdir/artest.a | |
321 | ||
322 | set got [binutils_run $AR "rc $archive ${objfile}"] | |
323 | if ![string match "" $got] { | |
324 | fail $testname | |
325 | return | |
326 | } | |
327 | ||
328 | remote_file build delete tmpdir/artest2.a | |
329 | ||
330 | set got [binutils_run $AR "rcT $archive2 ${archive}"] | |
331 | if ![string match "" $got] { | |
332 | fail $testname | |
333 | return | |
334 | } | |
335 | ||
f7da43f3 L |
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)" | |
341 | return | |
342 | } | |
58f594cd | 343 | |
f7da43f3 L |
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)" | |
348 | return | |
349 | } | |
eb4dc530 L |
350 | } |
351 | ||
a8da6403 | 352 | set got [binutils_run $NM "--print-armap $archive"] |
0bee4d1c AM |
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] } { | |
a8da6403 NC |
359 | fail $testname |
360 | return | |
361 | } | |
362 | ||
363 | pass $testname | |
364 | } | |
365 | ||
af865222 AS |
366 | # Test POSIX-compatible argument parsing. |
367 | ||
368 | proc argument_parsing { } { | |
369 | global AR | |
370 | global AS | |
371 | global srcdir | |
372 | global subdir | |
0bee4d1c | 373 | global obj |
af865222 AS |
374 | |
375 | set testname "ar argument parsing" | |
376 | ||
0bee4d1c | 377 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
af865222 AS |
378 | unresolved $testname |
379 | return | |
380 | } | |
381 | ||
382 | if [is_remote host] { | |
383 | set archive artest.a | |
0bee4d1c | 384 | set objfile [remote_download host tmpdir/bintest.${obj}] |
af865222 AS |
385 | remote_file host delete $archive |
386 | } else { | |
387 | set archive tmpdir/artest.a | |
0bee4d1c | 388 | set objfile tmpdir/bintest.${obj} |
af865222 AS |
389 | } |
390 | ||
391 | remote_file build delete tmpdir/artest.a | |
392 | ||
393 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
394 | if ![string match "" $got] { | |
395 | fail $testname | |
396 | return | |
397 | } | |
398 | ||
399 | pass $testname | |
400 | } | |
401 | ||
36e4dce6 CD |
402 | # Test building a deterministic archive. |
403 | ||
404 | proc deterministic_archive { } { | |
405 | global AR | |
406 | global AS | |
407 | global NM | |
408 | global srcdir | |
409 | global subdir | |
0bee4d1c | 410 | global obj |
36e4dce6 CD |
411 | |
412 | set testname "ar deterministic archive" | |
413 | ||
0bee4d1c | 414 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
36e4dce6 CD |
415 | unresolved $testname |
416 | return | |
417 | } | |
418 | ||
419 | if [is_remote host] { | |
420 | set archive artest.a | |
0bee4d1c | 421 | set objfile [remote_download host tmpdir/bintest.${obj}] |
36e4dce6 CD |
422 | remote_file host delete $archive |
423 | } else { | |
424 | set archive tmpdir/artest.a | |
0bee4d1c | 425 | set objfile tmpdir/bintest.${obj} |
36e4dce6 CD |
426 | } |
427 | ||
428 | remote_file build delete tmpdir/artest.a | |
429 | ||
430 | set got [binutils_run $AR "rcD $archive ${objfile}"] | |
431 | if ![string match "" $got] { | |
432 | fail $testname | |
433 | return | |
434 | } | |
435 | ||
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. | |
0bee4d1c | 439 | if ![string match "rw-r--r-- 0/0 *bintest.${obj}*" $got] { |
36e4dce6 CD |
440 | fail $testname |
441 | return | |
442 | } | |
443 | ||
1869e86f | 444 | set got [binutils_run $AR "tvO $archive"] |
0bee4d1c | 445 | if ![string match "rw-r--r-- 0/0 *bintest.${obj} 0x*" $got] { |
1869e86f AB |
446 | fail $testname |
447 | return | |
448 | } | |
449 | ||
36e4dce6 CD |
450 | pass $testname |
451 | } | |
452 | ||
a45fc993 AM |
453 | proc unique_symbol { } { |
454 | global AR | |
455 | global AS | |
456 | global NM | |
457 | global srcdir | |
458 | global subdir | |
0bee4d1c | 459 | global obj |
a45fc993 AM |
460 | |
461 | set testname "ar unique symbol in archive" | |
462 | ||
0bee4d1c | 463 | if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.${obj}] { |
a45fc993 | 464 | unresolved $testname |
f795c494 | 465 | return |
a45fc993 AM |
466 | } |
467 | ||
468 | if [is_remote host] { | |
469 | set archive artest.a | |
0bee4d1c | 470 | set objfile [remote_download host tmpdir/unique.${obj}] |
a45fc993 AM |
471 | remote_file host delete $archive |
472 | } else { | |
473 | set archive tmpdir/artest.a | |
0bee4d1c | 474 | set objfile tmpdir/unique.${obj} |
a45fc993 AM |
475 | } |
476 | ||
477 | remote_file build delete tmpdir/artest.a | |
478 | ||
479 | set got [binutils_run $AR "-s -r -c $archive ${objfile}"] | |
480 | if ![string match "" $got] { | |
481 | fail $testname | |
482 | return | |
483 | } | |
484 | ||
485 | set got [binutils_run $NM "--print-armap $archive"] | |
0bee4d1c | 486 | if ![string match "*foo in *unique.${obj}*" $got] { |
a45fc993 AM |
487 | fail $testname |
488 | return | |
489 | } | |
490 | ||
491 | pass $testname | |
492 | } | |
493 | ||
fde6f1fc L |
494 | # Test deleting an element. |
495 | ||
496 | proc delete_an_element { } { | |
497 | global AR | |
498 | global AS | |
499 | global srcdir | |
500 | global subdir | |
0bee4d1c | 501 | global obj |
fde6f1fc L |
502 | |
503 | set testname "ar deleting an element" | |
504 | ||
0bee4d1c | 505 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
fde6f1fc L |
506 | unresolved $testname |
507 | return | |
508 | } | |
509 | ||
510 | if [is_remote host] { | |
511 | set archive artest.a | |
0bee4d1c | 512 | set objfile [remote_download host tmpdir/bintest.${obj}] |
fde6f1fc L |
513 | remote_file host delete $archive |
514 | } else { | |
515 | set archive tmpdir/artest.a | |
0bee4d1c | 516 | set objfile tmpdir/bintest.${obj} |
fde6f1fc L |
517 | } |
518 | ||
519 | remote_file build delete tmpdir/artest.a | |
520 | ||
521 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
522 | if ![string match "" $got] { | |
523 | fail $testname | |
524 | return | |
525 | } | |
526 | ||
527 | set got [binutils_run $AR "-d $archive ${objfile}"] | |
528 | if ![string match "" $got] { | |
529 | fail $testname | |
530 | return | |
531 | } | |
532 | ||
533 | pass $testname | |
534 | } | |
535 | ||
536 | # Test moving an element. | |
537 | ||
538 | proc move_an_element { } { | |
539 | global AR | |
540 | global AS | |
541 | global srcdir | |
542 | global subdir | |
0bee4d1c | 543 | global obj |
fde6f1fc L |
544 | |
545 | set testname "ar moving an element" | |
546 | ||
0bee4d1c | 547 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
fde6f1fc L |
548 | unresolved $testname |
549 | return | |
550 | } | |
551 | ||
552 | if [is_remote host] { | |
553 | set archive artest.a | |
0bee4d1c | 554 | set objfile [remote_download host tmpdir/bintest.${obj}] |
fde6f1fc L |
555 | remote_file host delete $archive |
556 | } else { | |
557 | set archive tmpdir/artest.a | |
0bee4d1c | 558 | set objfile tmpdir/bintest.${obj} |
fde6f1fc L |
559 | } |
560 | ||
561 | remote_file build delete tmpdir/artest.a | |
562 | ||
563 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
564 | if ![string match "" $got] { | |
565 | fail $testname | |
566 | return | |
567 | } | |
568 | ||
569 | set got [binutils_run $AR "-m $archive ${objfile}"] | |
570 | if ![string match "" $got] { | |
571 | fail $testname | |
572 | return | |
573 | } | |
574 | ||
575 | pass $testname | |
576 | } | |
577 | ||
4fc87424 NC |
578 | # PR 19775: Test creating and listing archives with an empty element. |
579 | ||
580 | proc empty_archive { } { | |
581 | global AR | |
582 | global srcdir | |
583 | global subdir | |
584 | ||
585 | set testname "archive with empty element" | |
586 | ||
587 | # FIXME: There ought to be a way to dynamically create an empty file. | |
588 | set empty $srcdir/$subdir/empty | |
1869e86f | 589 | |
4fc87424 NC |
590 | if [is_remote host] { |
591 | set archive artest.a | |
592 | set objfile [remote_download host $empty] | |
593 | remote_file host delete $archive | |
594 | } else { | |
595 | set archive tmpdir/artest.a | |
596 | set objfile $empty | |
597 | } | |
598 | ||
599 | remote_file build delete tmpdir/artest.a | |
600 | ||
601 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
602 | if ![string match "" $got] { | |
603 | fail $testname | |
604 | return | |
605 | } | |
606 | ||
607 | # This commmand used to fail with: "Malformed archive". | |
608 | set got [binutils_run $AR "-t $archive"] | |
609 | if ![string match "empty\r" $got] { | |
610 | fail $testname | |
611 | return | |
612 | } | |
613 | ||
614 | pass $testname | |
615 | } | |
616 | ||
197245e3 FS |
617 | # Test extracting an element. |
618 | ||
619 | proc extract_an_element { } { | |
620 | global AR | |
621 | global AS | |
622 | global srcdir | |
623 | global subdir | |
0bee4d1c | 624 | global obj |
197245e3 FS |
625 | |
626 | set testname "ar extracting an element" | |
627 | ||
0bee4d1c | 628 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
197245e3 FS |
629 | unresolved $testname |
630 | return | |
631 | } | |
632 | ||
633 | set archive artest.a | |
634 | ||
635 | if [is_remote host] { | |
0bee4d1c | 636 | set objfile [remote_download host tmpdir/bintest.${obj}] |
197245e3 FS |
637 | remote_file host delete $archive |
638 | } else { | |
0bee4d1c | 639 | set objfile tmpdir/bintest.${obj} |
197245e3 FS |
640 | } |
641 | ||
642 | remote_file build delete $archive | |
643 | ||
644 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
645 | if ![string match "" $got] { | |
646 | fail $testname | |
647 | return | |
648 | } | |
649 | ||
650 | set got [binutils_run $AR "--output=tmpdir -x $archive ${objfile}"] | |
651 | if ![string match "" $got] { | |
652 | fail $testname | |
653 | return | |
654 | } | |
655 | ||
656 | remote_file build delete $archive | |
657 | remote_file build delete tmpdir/$archive | |
658 | ||
659 | pass $testname | |
660 | } | |
661 | ||
3f3c3608 AM |
662 | proc many_files { } { |
663 | global AR | |
664 | global AS | |
665 | global srcdir | |
666 | global subdir | |
0bee4d1c | 667 | global obj |
3f3c3608 AM |
668 | |
669 | set testname "ar many files" | |
670 | ||
671 | set ofiles {} | |
672 | set max_file 150 | |
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] { | |
676 | perror "$x" | |
677 | unresolved $testname | |
678 | return | |
679 | } | |
680 | ||
681 | puts $ofd " .globl data_sym$i" | |
682 | puts $ofd " .data" | |
683 | puts $ofd "data_sym$i:" | |
684 | puts $ofd " .long $i" | |
685 | close $ofd | |
686 | ||
0bee4d1c | 687 | set ofile "tmpdir/d-$i.${obj}" |
3f3c3608 AM |
688 | if ![binutils_assemble $sfile $ofile] { |
689 | unresolved $testname | |
690 | return | |
691 | } | |
692 | ||
693 | set objfile $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 | |
698 | } | |
699 | remote_file build delete $sfile | |
700 | lappend ofiles $objfile | |
701 | } | |
702 | ||
703 | set archive tmpdir/many.a | |
704 | remote_file host delete $archive | |
705 | ||
706 | set got [binutils_run $AR "cr $archive $ofiles"] | |
707 | if ![string match "" $got] { | |
708 | fail $testname | |
709 | return | |
710 | } | |
711 | ||
712 | remote_file host delete $archive | |
713 | eval remote_file host delete $ofiles | |
714 | ||
715 | pass $testname | |
716 | } | |
717 | ||
252b5132 RH |
718 | # Run the tests. |
719 | ||
9bc24099 NC |
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. | |
0bee4d1c | 724 | if { [file exists $base_dir/bfdtest1] && [file exists $base_dir/bfdtest2] } { |
9bc24099 NC |
725 | set bfdtests [list bfdtest1 bfdtest2] |
726 | ||
727 | long_filenames $bfdtests | |
0bee4d1c AM |
728 | |
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 | |
735 | } | |
9bc24099 | 736 | } |
f7da43f3 | 737 | |
252b5132 | 738 | symbol_table |
af865222 | 739 | argument_parsing |
36e4dce6 | 740 | deterministic_archive |
fde6f1fc L |
741 | delete_an_element |
742 | move_an_element | |
4fc87424 | 743 | empty_archive |
197245e3 | 744 | extract_an_element |
3f3c3608 | 745 | many_files |
9bc24099 | 746 | |
eb9bb5b4 | 747 | if { [is_elf_format] && [supports_gnu_unique] } { |
a45fc993 AM |
748 | unique_symbol |
749 | } |