]>
Commit | Line | Data |
---|---|---|
d87bef3a | 1 | # Copyright (C) 1995-2023 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}] { |
17e04eff | 198 | unsupported $testname |
252b5132 RH |
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}] { |
17e04eff | 247 | unsupported $testname |
a8da6403 NC |
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}] { |
17e04eff | 305 | unsupported $testname |
a8da6403 NC |
306 | return |
307 | } | |
308 | ||
309 | if [is_remote host] { | |
310 | set archive artest.a | |
311 | set archive2 artest2.a | |
d1b69c50 | 312 | set archive3 artest3.a |
0bee4d1c | 313 | set objfile [remote_download host tmpdir/bintest.${obj}] |
a8da6403 NC |
314 | remote_file host delete $archive |
315 | } else { | |
316 | set archive tmpdir/artest.a | |
317 | set archive2 tmpdir/artest2.a | |
d1b69c50 | 318 | set archive3 tmpdir/artest3.a |
0bee4d1c | 319 | set objfile tmpdir/bintest.${obj} |
a8da6403 NC |
320 | } |
321 | ||
322 | remote_file build delete tmpdir/artest.a | |
323 | ||
324 | set got [binutils_run $AR "rc $archive ${objfile}"] | |
325 | if ![string match "" $got] { | |
326 | fail $testname | |
327 | return | |
328 | } | |
329 | ||
330 | remote_file build delete tmpdir/artest2.a | |
331 | ||
332 | set got [binutils_run $AR "rcT $archive2 ${archive}"] | |
333 | if ![string match "" $got] { | |
334 | fail $testname | |
335 | return | |
336 | } | |
337 | ||
d1b69c50 FS |
338 | remote_file build delete tmpdir/artest3.a |
339 | ||
340 | set got [binutils_run $AR "rc --thin $archive3 ${archive}"] | |
341 | if ![string match "" $got] { | |
342 | fail $testname | |
343 | return | |
344 | } | |
345 | ||
f7da43f3 L |
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 | } | |
58f594cd | 353 | |
f7da43f3 L |
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 | } | |
d1b69c50 FS |
360 | |
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 | } | |
eb4dc530 L |
367 | } |
368 | ||
a8da6403 | 369 | set got [binutils_run $NM "--print-armap $archive"] |
0bee4d1c AM |
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] } { | |
a8da6403 NC |
376 | fail $testname |
377 | return | |
378 | } | |
379 | ||
380 | pass $testname | |
381 | } | |
382 | ||
af865222 AS |
383 | # Test POSIX-compatible argument parsing. |
384 | ||
385 | proc argument_parsing { } { | |
386 | global AR | |
387 | global AS | |
388 | global srcdir | |
389 | global subdir | |
0bee4d1c | 390 | global obj |
af865222 AS |
391 | |
392 | set testname "ar argument parsing" | |
393 | ||
0bee4d1c | 394 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
17e04eff | 395 | unsupported $testname |
af865222 AS |
396 | return |
397 | } | |
398 | ||
399 | if [is_remote host] { | |
400 | set archive artest.a | |
0bee4d1c | 401 | set objfile [remote_download host tmpdir/bintest.${obj}] |
af865222 AS |
402 | remote_file host delete $archive |
403 | } else { | |
404 | set archive tmpdir/artest.a | |
0bee4d1c | 405 | set objfile tmpdir/bintest.${obj} |
af865222 AS |
406 | } |
407 | ||
408 | remote_file build delete tmpdir/artest.a | |
409 | ||
410 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
411 | if ![string match "" $got] { | |
412 | fail $testname | |
413 | return | |
414 | } | |
415 | ||
416 | pass $testname | |
417 | } | |
418 | ||
36e4dce6 CD |
419 | # Test building a deterministic archive. |
420 | ||
421 | proc deterministic_archive { } { | |
422 | global AR | |
423 | global AS | |
424 | global NM | |
425 | global srcdir | |
426 | global subdir | |
0bee4d1c | 427 | global obj |
36e4dce6 CD |
428 | |
429 | set testname "ar deterministic archive" | |
430 | ||
0bee4d1c | 431 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
17e04eff | 432 | unsupported $testname |
36e4dce6 CD |
433 | return |
434 | } | |
435 | ||
436 | if [is_remote host] { | |
437 | set archive artest.a | |
0bee4d1c | 438 | set objfile [remote_download host tmpdir/bintest.${obj}] |
36e4dce6 CD |
439 | remote_file host delete $archive |
440 | } else { | |
441 | set archive tmpdir/artest.a | |
0bee4d1c | 442 | set objfile tmpdir/bintest.${obj} |
36e4dce6 CD |
443 | } |
444 | ||
445 | remote_file build delete tmpdir/artest.a | |
446 | ||
447 | set got [binutils_run $AR "rcD $archive ${objfile}"] | |
448 | if ![string match "" $got] { | |
449 | fail $testname | |
450 | return | |
451 | } | |
452 | ||
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. | |
0bee4d1c | 456 | if ![string match "rw-r--r-- 0/0 *bintest.${obj}*" $got] { |
36e4dce6 CD |
457 | fail $testname |
458 | return | |
459 | } | |
460 | ||
1869e86f | 461 | set got [binutils_run $AR "tvO $archive"] |
0bee4d1c | 462 | if ![string match "rw-r--r-- 0/0 *bintest.${obj} 0x*" $got] { |
1869e86f AB |
463 | fail $testname |
464 | return | |
465 | } | |
466 | ||
36e4dce6 CD |
467 | pass $testname |
468 | } | |
469 | ||
a45fc993 AM |
470 | proc unique_symbol { } { |
471 | global AR | |
472 | global AS | |
473 | global NM | |
474 | global srcdir | |
475 | global subdir | |
0bee4d1c | 476 | global obj |
a45fc993 AM |
477 | |
478 | set testname "ar unique symbol in archive" | |
479 | ||
0bee4d1c | 480 | if ![binutils_assemble $srcdir/$subdir/unique.s tmpdir/unique.${obj}] { |
17e04eff | 481 | unsupported $testname |
f795c494 | 482 | return |
a45fc993 AM |
483 | } |
484 | ||
485 | if [is_remote host] { | |
486 | set archive artest.a | |
0bee4d1c | 487 | set objfile [remote_download host tmpdir/unique.${obj}] |
a45fc993 AM |
488 | remote_file host delete $archive |
489 | } else { | |
490 | set archive tmpdir/artest.a | |
0bee4d1c | 491 | set objfile tmpdir/unique.${obj} |
a45fc993 AM |
492 | } |
493 | ||
494 | remote_file build delete tmpdir/artest.a | |
495 | ||
496 | set got [binutils_run $AR "-s -r -c $archive ${objfile}"] | |
497 | if ![string match "" $got] { | |
498 | fail $testname | |
499 | return | |
500 | } | |
501 | ||
502 | set got [binutils_run $NM "--print-armap $archive"] | |
0bee4d1c | 503 | if ![string match "*foo in *unique.${obj}*" $got] { |
a45fc993 AM |
504 | fail $testname |
505 | return | |
506 | } | |
507 | ||
508 | pass $testname | |
509 | } | |
510 | ||
fde6f1fc L |
511 | # Test deleting an element. |
512 | ||
513 | proc delete_an_element { } { | |
514 | global AR | |
515 | global AS | |
516 | global srcdir | |
517 | global subdir | |
0bee4d1c | 518 | global obj |
fde6f1fc L |
519 | |
520 | set testname "ar deleting an element" | |
521 | ||
0bee4d1c | 522 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
17e04eff | 523 | unsupported $testname |
fde6f1fc L |
524 | return |
525 | } | |
526 | ||
527 | if [is_remote host] { | |
528 | set archive artest.a | |
0bee4d1c | 529 | set objfile [remote_download host tmpdir/bintest.${obj}] |
fde6f1fc L |
530 | remote_file host delete $archive |
531 | } else { | |
532 | set archive tmpdir/artest.a | |
0bee4d1c | 533 | set objfile tmpdir/bintest.${obj} |
fde6f1fc L |
534 | } |
535 | ||
536 | remote_file build delete tmpdir/artest.a | |
537 | ||
538 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
539 | if ![string match "" $got] { | |
540 | fail $testname | |
541 | return | |
542 | } | |
543 | ||
544 | set got [binutils_run $AR "-d $archive ${objfile}"] | |
545 | if ![string match "" $got] { | |
546 | fail $testname | |
547 | return | |
548 | } | |
549 | ||
550 | pass $testname | |
551 | } | |
552 | ||
553 | # Test moving an element. | |
554 | ||
555 | proc move_an_element { } { | |
556 | global AR | |
557 | global AS | |
558 | global srcdir | |
559 | global subdir | |
0bee4d1c | 560 | global obj |
fde6f1fc L |
561 | |
562 | set testname "ar moving an element" | |
563 | ||
0bee4d1c | 564 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
17e04eff | 565 | unsupported $testname |
fde6f1fc L |
566 | return |
567 | } | |
568 | ||
569 | if [is_remote host] { | |
570 | set archive artest.a | |
0bee4d1c | 571 | set objfile [remote_download host tmpdir/bintest.${obj}] |
fde6f1fc L |
572 | remote_file host delete $archive |
573 | } else { | |
574 | set archive tmpdir/artest.a | |
0bee4d1c | 575 | set objfile tmpdir/bintest.${obj} |
fde6f1fc L |
576 | } |
577 | ||
578 | remote_file build delete tmpdir/artest.a | |
579 | ||
580 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
581 | if ![string match "" $got] { | |
582 | fail $testname | |
583 | return | |
584 | } | |
585 | ||
586 | set got [binutils_run $AR "-m $archive ${objfile}"] | |
587 | if ![string match "" $got] { | |
588 | fail $testname | |
589 | return | |
590 | } | |
591 | ||
592 | pass $testname | |
593 | } | |
594 | ||
4fc87424 NC |
595 | # PR 19775: Test creating and listing archives with an empty element. |
596 | ||
597 | proc empty_archive { } { | |
598 | global AR | |
599 | global srcdir | |
600 | global subdir | |
601 | ||
602 | set testname "archive with empty element" | |
603 | ||
604 | # FIXME: There ought to be a way to dynamically create an empty file. | |
605 | set empty $srcdir/$subdir/empty | |
1869e86f | 606 | |
4fc87424 NC |
607 | if [is_remote host] { |
608 | set archive artest.a | |
609 | set objfile [remote_download host $empty] | |
610 | remote_file host delete $archive | |
611 | } else { | |
612 | set archive tmpdir/artest.a | |
613 | set objfile $empty | |
614 | } | |
615 | ||
616 | remote_file build delete tmpdir/artest.a | |
617 | ||
618 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
619 | if ![string match "" $got] { | |
620 | fail $testname | |
621 | return | |
622 | } | |
623 | ||
624 | # This commmand used to fail with: "Malformed archive". | |
625 | set got [binutils_run $AR "-t $archive"] | |
d87bef3a AM |
626 | if ![string match "empty |
627 | " $got] { | |
4fc87424 NC |
628 | fail $testname |
629 | return | |
630 | } | |
631 | ||
632 | pass $testname | |
633 | } | |
634 | ||
197245e3 FS |
635 | # Test extracting an element. |
636 | ||
637 | proc extract_an_element { } { | |
638 | global AR | |
639 | global AS | |
640 | global srcdir | |
641 | global subdir | |
0bee4d1c | 642 | global obj |
197245e3 FS |
643 | |
644 | set testname "ar extracting an element" | |
645 | ||
0bee4d1c | 646 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { |
17e04eff | 647 | unsupported $testname |
197245e3 FS |
648 | return |
649 | } | |
650 | ||
651 | set archive artest.a | |
652 | ||
653 | if [is_remote host] { | |
0bee4d1c | 654 | set objfile [remote_download host tmpdir/bintest.${obj}] |
197245e3 FS |
655 | remote_file host delete $archive |
656 | } else { | |
0bee4d1c | 657 | set objfile tmpdir/bintest.${obj} |
197245e3 FS |
658 | } |
659 | ||
660 | remote_file build delete $archive | |
661 | ||
662 | set got [binutils_run $AR "-r -c $archive ${objfile}"] | |
663 | if ![string match "" $got] { | |
664 | fail $testname | |
665 | return | |
666 | } | |
667 | ||
668 | set got [binutils_run $AR "--output=tmpdir -x $archive ${objfile}"] | |
669 | if ![string match "" $got] { | |
670 | fail $testname | |
671 | return | |
672 | } | |
673 | ||
674 | remote_file build delete $archive | |
675 | remote_file build delete tmpdir/$archive | |
676 | ||
677 | pass $testname | |
678 | } | |
679 | ||
3f3c3608 AM |
680 | proc many_files { } { |
681 | global AR | |
682 | global AS | |
683 | global srcdir | |
684 | global subdir | |
0bee4d1c | 685 | global obj |
3f3c3608 AM |
686 | |
687 | set testname "ar many files" | |
688 | ||
689 | set ofiles {} | |
690 | set max_file 150 | |
691 | for { set i 0 } { $i < $max_file } { incr i } { | |
692 | set sfile "tmpdir/d-$i.s" | |
693 | if [catch { set ofd [open $sfile w] } x] { | |
694 | perror "$x" | |
695 | unresolved $testname | |
696 | return | |
697 | } | |
698 | ||
699 | puts $ofd " .globl data_sym$i" | |
700 | puts $ofd " .data" | |
701 | puts $ofd "data_sym$i:" | |
702 | puts $ofd " .long $i" | |
703 | close $ofd | |
704 | ||
0bee4d1c | 705 | set ofile "tmpdir/d-$i.${obj}" |
3f3c3608 | 706 | if ![binutils_assemble $sfile $ofile] { |
17e04eff | 707 | unsupported $testname |
3f3c3608 AM |
708 | return |
709 | } | |
710 | ||
711 | set objfile $ofile | |
712 | if [is_remote host] { | |
713 | remote_file host delete $sfile | |
714 | set objfile [remote_download host $ofile] | |
715 | remote_file build delete $ofile | |
716 | } | |
717 | remote_file build delete $sfile | |
718 | lappend ofiles $objfile | |
719 | } | |
720 | ||
721 | set archive tmpdir/many.a | |
722 | remote_file host delete $archive | |
723 | ||
724 | set got [binutils_run $AR "cr $archive $ofiles"] | |
725 | if ![string match "" $got] { | |
726 | fail $testname | |
727 | return | |
728 | } | |
729 | ||
730 | remote_file host delete $archive | |
731 | eval remote_file host delete $ofiles | |
732 | ||
733 | pass $testname | |
734 | } | |
735 | ||
f3016d6c HC |
736 | proc test_add_dependencies { } { |
737 | global AR | |
738 | global AS | |
739 | global srcdir | |
740 | global subdir | |
741 | global obj | |
742 | ||
743 | set testname "ar adding library dependencies" | |
744 | ||
745 | if ![binutils_assemble $srcdir/$subdir/bintest.s tmpdir/bintest.${obj}] { | |
17e04eff | 746 | unsupported $testname |
f3016d6c HC |
747 | return |
748 | } | |
749 | ||
750 | if [is_remote host] { | |
751 | set archive artest.a | |
752 | set objfile [remote_download host tmpdir/bintest.${obj}] | |
753 | remote_file host delete $archive | |
754 | } else { | |
755 | set archive tmpdir/artest.a | |
756 | set objfile tmpdir/bintest.${obj} | |
757 | } | |
758 | ||
759 | remote_file build delete tmpdir/artest.a | |
760 | ||
761 | set got [binutils_run $AR "-r -c $archive --record-libdeps /foo/bar ${objfile}"] | |
762 | if ![string match "" $got] { | |
763 | fail $testname | |
764 | return | |
765 | } | |
766 | ||
767 | set got [binutils_run $AR "-t $archive"] | |
d87bef3a AM |
768 | if ![string match "*bintest.${obj} |
769 | __.LIBDEP*" $got] { | |
f3016d6c HC |
770 | fail $testname |
771 | return | |
772 | } | |
773 | ||
774 | pass $testname | |
775 | } | |
776 | ||
252b5132 RH |
777 | # Run the tests. |
778 | ||
9bc24099 NC |
779 | # Only run the bfdtest checks if the programs exist. Since these |
780 | # programs are built but not installed, running the testsuite on an | |
781 | # installed toolchain will produce ERRORs about missing bfdtest1 and | |
782 | # bfdtest2 executables. | |
0bee4d1c | 783 | if { [file exists $base_dir/bfdtest1] && [file exists $base_dir/bfdtest2] } { |
9bc24099 NC |
784 | set bfdtests [list bfdtest1 bfdtest2] |
785 | ||
786 | long_filenames $bfdtests | |
0bee4d1c AM |
787 | |
788 | # xcoff, ecoff, and vms archive support doesn't handle thin archives | |
5a2296ac | 789 | if { ![is_xcoff_format] |
0bee4d1c AM |
790 | && ![istarget "*-*-*ecoff"] |
791 | && ![istarget "*-*-vms"] } { | |
792 | thin_archive $bfdtests | |
793 | thin_archive_with_nested $bfdtests | |
794 | } | |
9bc24099 | 795 | } |
f7da43f3 | 796 | |
252b5132 | 797 | symbol_table |
af865222 | 798 | argument_parsing |
36e4dce6 | 799 | deterministic_archive |
fde6f1fc L |
800 | delete_an_element |
801 | move_an_element | |
4fc87424 | 802 | empty_archive |
197245e3 | 803 | extract_an_element |
3f3c3608 | 804 | many_files |
f3016d6c | 805 | test_add_dependencies |
9bc24099 | 806 | |
eb9bb5b4 | 807 | if { [is_elf_format] && [supports_gnu_unique] } { |
a45fc993 AM |
808 | unique_symbol |
809 | } |