2003-05-06 H.J. Lu <hjl@gnu.org>
[external/binutils.git] / ld / testsuite / ld-elfvers / vers.exp
1 # Expect script for ld-version tests
2 #   Copyright 1997, 1998, 1999, 2001, 2003 Free Software Foundation, Inc.
3 #
4 # This file is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #
18 # Written by Eric Youngdale (eric@andante.jic.com)
19
20 #
21
22 # This test can only be run if ld generates native executables.
23 if ![isnative] then {return}
24
25 # This test can only be run on a couple of ELF platforms.
26 # Square bracket expressions seem to confuse istarget.
27 # This is similar to the test that is used in ld-shared, BTW.
28 if { ![istarget hppa*64*-*-hpux*] \
29      && ![istarget hppa*-*-linux*] \
30      && ![istarget i?86-*-sysv4*] \
31      && ![istarget i?86-*-unixware] \
32      && ![istarget i?86-*-elf*] \
33      && ![istarget i?86-*-linux*] \
34      && ![istarget ia64-*-elf*] \
35      && ![istarget ia64-*-linux*] \
36      && ![istarget m68k-*-linux*] \
37      && ![istarget mips*-*-irix5*] \
38      && ![istarget powerpc-*-elf*] \
39      && ![istarget powerpc-*-linux*] \
40      && ![istarget powerpc-*-sysv4*] \
41      && ![istarget sparc*-*-elf] \
42      && ![istarget sparc*-*-solaris2*] \
43      && ![istarget sparc*-*-linux*] \
44      && ![istarget arm*-*-linux*] \
45      && ![istarget mips*-*-linux*] \
46      && ![istarget alpha*-*-linux*] \
47      && ![istarget s390*-*-linux*] \
48      && ![istarget x86_64-*-linux*] } {
49     return
50 }
51
52 if { [istarget i?86-*-linux*aout*] \
53      || [istarget i?86-*-linux*oldld*] \
54      || [istarget m68k-*-linux*aout*] } {
55     return
56 }
57
58 if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
59     return
60 }
61
62 set diff diff
63 set tmpdir tmpdir
64 set VOBJDUMP_FLAGS --private-headers
65 set DOBJDUMP_FLAGS --dynamic-syms
66 set SOBJDUMP_FLAGS --syms
67 set shared "--shared --no-undefined-version"
68 set script --version-script
69
70 if [istarget mips*-*-*] {
71     set picflag ""
72 } else {
73     # Unfortunately, the gcc argument is -fpic and the cc argument is
74     # -KPIC.  We have to try both.
75     set picflag "-fpic"
76     send_log "$CC $picflag\n"
77     verbose "$CC $picflag"
78     catch "exec $CC $picflag" exec_output
79     send_log "$exec_output\n"
80     verbose "--" "$exec_output"
81     if { [string match "*illegal option*" $exec_output] \
82          || [string match "*option ignored*" $exec_output] \
83          || [string match "*unrecognized option*" $exec_output] \
84          || [string match "*passed to ld*" $exec_output] } {
85         if [istarget *-*-sunos4*] {
86             set picflag "-pic"
87         } else {
88             set picflag "-KPIC"
89         }
90     }
91 }
92
93 proc test_ar { test lib object expect } {
94     global ar
95     global nm
96     global tmpdir
97     global srcdir
98     global subdir
99     global diff
100
101     verbose -log "$ar -cr $tmpdir/$lib $tmpdir/$object"
102     catch "exec $ar -cr $tmpdir/$lib $tmpdir/$object" exec_output
103     set exec_output [prune_warnings $exec_output]
104     if ![string match "" $exec_output] {
105         verbose -log "$exec_output"
106         unresolved "$test"
107         return
108     }
109     
110     verbose -log "$nm --print-armap $tmpdir/$lib | grep \" in \" | egrep \"VERS\\|bar\\|foo\" | sort > $tmpdir/nm.out"
111
112     catch "exec $nm --print-armap $tmpdir/$lib | grep \\\ in\\\  | egrep VERS\\\|bar\\\|foo | sort > $tmpdir/nm.out" exec_output
113     if [string match "" $exec_output] then {
114         catch "exec $diff $tmpdir/nm.out $srcdir/$subdir/$expect" exec_output
115         set exec_output [prune_warnings $exec_output]
116         if [string match "" $exec_output] then {
117             pass $test
118             return
119         } else {
120             verbose -log "$exec_output"
121             fail "$test"
122             return
123         }
124     } else {
125         verbose -log "$exec_output"
126         fail "$test"
127     }
128 }
129
130 #
131 # objdump_emptysymstuff
132 #       Check non-dynamic symbols and make sure there are none with '@'.
133 #
134 proc objdump_emptysymstuff { objdump object } {
135     global SOBJDUMP_FLAGS
136     global version_output
137     global diff
138
139     if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" }
140
141     verbose -log "$objdump $SOBJDUMP_FLAGS $object | sed -n /\@/p"
142
143     catch "exec $objdump $SOBJDUMP_FLAGS $object | sed -n /\@/p" exec_output
144     set exec_output [prune_warnings $exec_output]
145     if [string match "" $exec_output] then {
146 # We shouldn't get anything here.
147         return 1
148     } else {
149 # it is not normal to come here - we have no output to compare.
150         verbose -log "$exec_output"
151         verbose -log "objdump_emptysymstuff: did not expect any output from objdump"
152         return 0
153     }
154
155 }
156
157 #
158 # objdump_emptydynsymstuff
159 #       Check dynamic symbols and make sure there are none with '@'.
160 #
161 proc objdump_emptydynsymstuff { objdump object } {
162     global DOBJDUMP_FLAGS
163     global version_output
164     global diff
165
166     if ![info exists VOBJDUMP_FLAGS] { set VOBJDUMP_FLAGS "" }
167
168     verbose -log "$objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p"
169
170     catch "exec $objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p" exec_output
171     set exec_output [prune_warnings $exec_output]
172     if [string match "" $exec_output] then {
173 # We shouldn't get anything here.
174         return 1
175     } else { if [string match "*objdump: *: not a dynamic object" $exec_output] then {
176         return 1
177     } else {
178 # it is not normal to come here - we have no output to compare.
179         verbose -log "$exec_output"
180         verbose -log "objdump_emptydynsymstuff: did not expect any output from objdump"
181         return 0
182     } }
183 }
184
185 #
186 # objdump_emptyverstuff
187 #       Make sure there is no version information
188 #
189 proc objdump_emptyverstuff { objdump object } {
190     global VOBJDUMP_FLAGS
191     global version_output
192     global diff
193     global tmpdir
194
195     if {[which $objdump] == 0} then {
196         perror "$objdump does not exist"
197         return 0
198     }
199
200     if ![info exists VOBJDUMP_FLAGS] { set VOBJDUMP_FLAGS "" }
201
202     verbose -log "$objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p > $tmpdir/objdump.out"
203
204     catch "exec $objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p" exec_output
205     set exec_output [prune_warnings $exec_output]
206     if [string match "" $exec_output] then {
207 # it is normal to fail here - we have no output to compare.
208         return 1
209     } else { if { [string match "*libc*" $exec_output] } then {
210 # this probably means that there is version information in libc, so we
211 # can't really perform this test.
212         return 1
213     } else {
214         verbose -log "$exec_output"
215         verbose -log "objdump_emptyverstuff: did not expect any output from objdump"
216         return 0
217     } }
218
219 }
220
221 #
222 # objdump_symstuff
223 #       Dump non-dynamic symbol stuff and make sure that it is sane.
224 #
225 proc objdump_symstuff { objdump object expectfile } {
226     global SOBJDUMP_FLAGS
227     global version_output
228     global diff
229     global tmpdir
230
231     if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" }
232
233     verbose -log "$objdump $SOBJDUMP_FLAGS $object | grep \@ | sort  > $tmpdir/objdump.out"
234
235     catch "exec $objdump $SOBJDUMP_FLAGS $object | grep \@ | sort  > $tmpdir/objdump.out" exec_output
236     set exec_output [prune_warnings $exec_output]
237     if [string match "" $exec_output] then {
238
239 # Now do a line-by-line comparison to effectively diff the darned things
240 # The stuff coming from the expectfile is actually a regex, so we can
241 # skip over the actual addresses and so forth.  This is currently very
242 # simpleminded - it expects a one-to-one correspondence in terms of line
243 # numbers.
244
245         if [file exists $expectfile] then {
246             set file_a [open $expectfile r]
247         } else {
248             perror "$expectfile doesn't exist"
249             return 0
250         }
251         
252         if [file exists $tmpdir/objdump.out] then {
253             set file_b [open $tmpdir/objdump.out r]
254         } else {
255             perror "$tmpdir/objdump.out doesn't exist"
256             return 0
257         }
258
259         verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
260
261         set eof -1
262         set differences 0
263
264         while { [gets $file_a line] != $eof } {
265             if [regexp "^#.*$" $line] then {
266                 continue
267             } else {
268                 lappend list_a $line
269             }
270         }
271         close $file_a
272
273         while { [gets $file_b line] != $eof } {
274             if [regexp "^#.*$" $line] then {
275                 continue
276             } else {
277                 lappend list_b $line
278             }
279         }
280         close $file_b
281         
282         for { set i 0 } { $i < [llength $list_a] } { incr i } {
283             set line_a [lindex $list_a $i]
284             set line_b [lindex $list_b $i]
285             
286
287             verbose "\t$expectfile: $i: $line_a" 3
288             verbose "\t/tmp/objdump.out: $i: $line_b" 3
289             if [regexp $line_a $line_b] then {
290                 continue
291             } else {
292                 verbose -log "\t$expectfile: $i: $line_a"
293                 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
294                 
295                 return 0
296             }
297         }
298         
299         if { [llength $list_a] != [llength $list_b] } {
300             verbose -log "Line count"
301             return 0
302         }
303         
304         if $differences<1 then {
305             return 1
306         }
307         
308         return 0
309     } else {
310         verbose -log "$exec_output"
311         return 0
312     }
313
314 }
315
316 #
317 # objdump_dymsymstuff
318 #       Dump dynamic symbol stuff and make sure that it is sane.
319 #
320 proc objdump_dynsymstuff { objdump object expectfile } {
321     global DOBJDUMP_FLAGS
322     global version_output
323     global diff
324     global tmpdir
325
326     if ![info exists DOBJDUMP_FLAGS] { set DOBJDUMP_FLAGS "" }
327
328     verbose -log "$objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p | sort | uniq  > $tmpdir/objdump.out"
329
330     catch "exec $objdump $DOBJDUMP_FLAGS $object | sed -n /VERS/p\\\;/show/p | sort | uniq  > $tmpdir/objdump.out" exec_output
331     set exec_output [prune_warnings $exec_output]
332     if [string match "" $exec_output] then {
333
334 # Now do a line-by-line comparison to effectively diff the darned things
335 # The stuff coming from the expectfile is actually a regex, so we can
336 # skip over the actual addresses and so forth.  This is currently very
337 # simpleminded - it expects a one-to-one correspondence in terms of line
338 # numbers.
339
340         if [file exists $expectfile] then {
341             set file_a [open $expectfile r]
342         } else {
343             warning "$expectfile doesn't exist"
344             return 0
345         }
346         
347         if [file exists $tmpdir/objdump.out] then {
348             set file_b [open $tmpdir/objdump.out r]
349         } else {
350             fail "$tmpdir/objdump.out doesn't exist"
351             return 0
352         }
353
354         verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
355
356         set eof -1
357         set differences 0
358
359         while { [gets $file_a line] != $eof } {
360             if [regexp "^#.*$" $line] then {
361                 continue
362             } else {
363                 lappend list_a $line
364             }
365         }
366         close $file_a
367
368         while { [gets $file_b line] != $eof } {
369             if [regexp "^#.*$" $line] then {
370                 continue
371             } else {
372                 lappend list_b $line
373             }
374         }
375         close $file_b
376         
377         # Support empty files.
378         if { ![info exists list_a] && ![info exists list_b] } then {
379             return 1
380         }
381
382         for { set i 0 } { $i < [llength $list_b] } { incr i } {
383             set line_b [lindex $list_b $i]
384             
385 # The tests are rigged so that we should never export a symbol with the
386 # word 'hide' in it.  Thus we just search for it, and bail if we find it.
387             if [regexp "hide" $line_b] then {
388                 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
389                 
390                 return 0
391             }
392
393             verbose "\t$expectfile: $i: $line_b" 3
394
395             # We can't assume that the sort is consistent across
396             # systems, so we must check each regexp.  When we find a
397             # regexp, we null it out, so we don't match it twice.
398             for { set j 0 } { $j < [llength $list_a] } { incr j } {
399                 set line_a [lindex $list_a $j]
400
401                 if [regexp $line_a $line_b] then {
402                     lreplace $list_a $j $j "CAN NOT MATCH"
403                     break
404                 }
405             }
406
407             if { $j >= [llength $list_a] } {
408                 verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
409                 
410                 return 0
411             }
412         }
413         
414         if { [llength $list_a] != [llength $list_b] } {
415             verbose -log "Line count"
416             return 0
417         }
418         
419         if $differences<1 then {
420             return 1
421         }
422         
423         return 0
424     } else {
425         verbose -log "$exec_output"
426         return 0
427     }
428
429 }
430
431 #
432 # objdump_versionstuff
433 #       Dump version definitions/references and make sure that it is sane.
434 #
435 proc objdump_versionstuff { objdump object expectfile } {
436     global VOBJDUMP_FLAGS
437     global version_output
438     global diff
439     global tmpdir
440
441     if {[which $objdump] == 0} then {
442         perror "$objdump does not exist"
443         return 0
444     }
445
446     if ![info exists VOBJDUMP_FLAGS] { set VOBJDUMP_FLAGS "" }
447
448     verbose -log "$objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p > $tmpdir/objdump.out"
449
450     catch "exec $objdump $VOBJDUMP_FLAGS $object | sed -n /Version/,\\\$p > $tmpdir/objdump.out" exec_output
451     set exec_output [prune_warnings $exec_output]
452     if [string match "" $exec_output] then {
453
454         # It's OK if there are extra lines in the actual output; they
455         # may come from version information in libc.  We require that
456         # every line in EXPECTFILE appear in the output in order.
457
458         set f1 [open $tmpdir/objdump.out r]
459         set f2 [open $expectfile r]
460         while { [gets $f2 l2] != -1 } {
461             if { ![regexp "^#.*$" $l2] } then {
462                 break
463             }
464         } 
465         while { [gets $f1 l1] != -1 } {
466             if { [string match $l2 $l1] } then {
467                 if { [gets $f2 l2] == -1 } then {
468                     close $f1
469                     close $f2
470                     return 1
471                 }
472             }
473         }
474
475         # We reached the end of the output without seeing the line we
476         # expected.  This is a test failure.
477
478         close $f1
479         close $f2
480
481         # Support empty expected file.
482         if [string match "" $l2] then {
483             return 1
484         }
485
486         verbose -log "Did not find \"$l2\""
487         set f1 [open $tmpdir/objdump.out r]
488         while { [gets $f1 l1] != -1 } {
489             verbose -log $l1
490         }
491
492         verbose -log "$exec_output"
493         return 0
494     } else {
495         verbose -log "$exec_output"
496         return 0
497     }
498 }
499
500 proc build_vers_lib { pic test source libname other mapfile verexp versymexp symexp } {
501     global ld
502     global srcdir
503     global subdir
504     global exec_output
505     global host_triplet
506     global tmpdir
507     global as
508     global objdump
509     global CC
510     global CFLAGS
511     global shared
512     global script
513
514     if ![ld_compile "$CC -S $pic $CFLAGS" $srcdir/$subdir/$source $tmpdir/$libname.s]     {
515         unresolved "$test"
516         return
517     }
518
519     if ![ld_assemble $as $tmpdir/$libname.s $tmpdir/$libname.o ]     {
520         unresolved "$test"
521         return
522     }
523
524     set other_lib ""
525     if ![string match "" $other] then {
526         foreach o $other {
527             set other_lib "$other_lib $tmpdir/$o"
528         }
529     }
530
531     if [string match "" $mapfile] then {
532         set script_arg ""
533     } else {
534         set script_arg "$script $srcdir/$subdir/$mapfile"
535     }
536
537     if {![ld_simple_link $ld $tmpdir/$libname.so "$shared $tmpdir/$libname.o $other_lib $script_arg"]}     {
538         fail "$test"
539         return
540     }
541
542     if {![objdump_versionstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$verexp ]}     {
543         fail "$test"
544         return
545     }
546
547     if {![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$versymexp ]}     {
548         fail "$test"
549         return
550     }
551
552     if [string match "" $symexp] then {
553         if {![objdump_emptysymstuff $objdump $tmpdir/$libname.o ]}     {
554             fail "$test"
555             return
556         }
557     } else {
558         if {![objdump_symstuff $objdump $tmpdir/$libname.o $srcdir/$subdir/$symexp ]}     {
559             fail "$test"
560             return
561         }
562     }
563
564     pass $test
565     
566 }
567
568 proc build_vers_lib_no_pic { test source libname other mapfile verexp versymexp symexp } {
569   build_vers_lib "" $test $source $libname $other $mapfile $verexp $versymexp $symexp 
570 }
571
572 proc build_vers_lib_pic { test source libname other mapfile verexp versymexp symexp } {
573   global picflag
574   build_vers_lib $picflag $test $source $libname $other $mapfile $verexp $versymexp $symexp 
575 }
576
577 proc test_ldfail { test flag source execname other mapfile whyfail } {
578     global ld
579     global srcdir
580     global subdir
581     global exec_output
582     global host_triplet
583     global tmpdir
584     global as
585     global objdump
586     global CC
587     global CFLAGS
588     global script
589
590     if [string match "" $other] then {
591         set other_lib ""
592     } else {
593         set other_lib $tmpdir/$other
594     }
595
596     if ![ld_compile "$CC -S $flag $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s]     {
597         unresolved "$test"
598         return
599     }
600
601     if ![ld_assemble $as $tmpdir/$execname.s $tmpdir/$execname.o ]     {
602         unresolved "$test"
603         return
604     }
605
606     verbose -log "This link should fail because of $whyfail"
607
608     if [string match "" $mapfile] then {
609         set script_arg ""
610     } else {
611         set script_arg "$script $srcdir/$subdir/$mapfile"
612     }
613
614     if {![ld_link $ld $tmpdir/$execname "$tmpdir/$execname.o $other_lib $script_arg"]}     {
615         pass "$test"
616         return
617     }
618     fail "$test"
619 }
620
621 proc test_asfail { test flag source execname whyfail } {
622     global srcdir
623     global subdir
624     global tmpdir
625     global as
626     global CC
627     global CFLAGS
628
629     if ![ld_compile "$CC -S $flag $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s]     {
630         unresolved "$test"
631         return
632     }
633
634     verbose -log "This assemble should fail because of $whyfail"
635     catch "exec $as -o $tmpdir/$execname.o $tmpdir/$execname.s" exec_output
636     set exec_output [prune_warnings $exec_output]
637     if [string match "" $exec_output] then {
638         fail "$test"
639         return
640     }
641     verbose -log "$exec_output"
642     pass "$test"
643 }
644
645 proc test_strip_vers_lib { test srclib libname verexp versymexp } {
646     global strip
647     global srcdir
648     global subdir
649     global exec_output
650     global host_triplet
651     global tmpdir
652     global objdump
653
654     verbose -log "cp $tmpdir/$srclib $tmpdir/$libname.so"
655     exec cp $tmpdir/$srclib $tmpdir/$libname.so
656
657     verbose -log "$strip $tmpdir/$libname.so"
658     catch "exec $strip $tmpdir/$libname.so" exec_output
659     if [string match "" $exec_output] then {
660
661 # If strip went OK, then run the usual tests on the thing to make sure that
662 # it is sane.
663         if {![objdump_versionstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$verexp ]}     {
664             fail "$test"
665             return
666         }
667         
668         if {![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$versymexp ]}     {
669             fail "$test"
670             return
671         }
672         
673     } else {
674         verbose -log "$exec_output"
675         fail "$test"
676         return
677     }
678     pass $test
679 }
680
681
682 proc build_exec { test source execname flags solibname verexp versymexp symexp } {
683     global ld
684     global srcdir
685     global subdir
686     global exec_output
687     global host_triplet
688     global tmpdir
689     global as
690     global objdump
691     global CC
692     global CFLAGS
693
694     set shared "--shared --no-undefined-version"
695     set script --version-script
696     if ![ld_compile "$CC -S $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s]     {
697         unresolved "$test"
698         return
699     }
700
701     if ![ld_assemble $as $tmpdir/$execname.s $tmpdir/$execname.o ]     {
702         unresolved "$test"
703         return
704     }
705
706     if [string match "" $solibname] then {
707         set solibname_lib ""
708     } else {
709         set solibname_lib $tmpdir/$solibname
710     }
711
712     if {![ld_link $ld $tmpdir/$execname "$flags $tmpdir/$execname.o $solibname_lib"]}     {
713         fail "$test"
714         return
715     }
716
717     if [string match "" $verexp] then {
718 #
719 # Make sure we get nothing back.
720 #
721         if {![objdump_emptyverstuff $objdump $tmpdir/$execname ]}     {
722             fail "$test"
723             return
724         }
725     } else {
726         if {![objdump_versionstuff $objdump $tmpdir/$execname $srcdir/$subdir/$verexp ]}     {
727             fail "$test"
728             return
729         }
730     }
731
732     if [string match "" $versymexp] then {
733         if {![objdump_emptydynsymstuff $objdump $tmpdir/$execname ]}     {
734             fail "$test"
735             return
736         }
737     } else {
738         if {![objdump_dynsymstuff $objdump $tmpdir/$execname $srcdir/$subdir/$versymexp ]}     {
739             fail "$test"
740             return
741         }
742     }
743
744     if [string match "" $symexp] then {
745         if {![objdump_emptysymstuff $objdump $tmpdir/$execname.o ]}     {
746             fail "$test"
747             return
748         }
749     } else {
750         if {![objdump_symstuff $objdump $tmpdir/$execname.o $srcdir/$subdir/$symexp ]}     {
751             fail "$test"
752             return
753         }
754     }
755
756     pass $test
757 }
758
759
760 #
761 # Basic test - build a library with versioned symbols.
762 #
763 build_vers_lib_no_pic "vers1" vers1.c vers1 "" vers1.map vers1.ver vers1.dsym vers1.sym
764
765
766 #
767 # Test #2 - build a library, and link it against the library we built in step
768 # 1.
769 #
770 if [istarget x86_64-*-linux*] {
771     # x86_64 doesn't like non-pic shared libraries
772     xfail "vers2"
773 } else {
774     build_vers_lib_no_pic "vers2" vers2.c vers2 vers1.so vers2.map vers2.ver vers2.dsym ""
775 }
776
777 #
778 # Test #3 - build an executable, and link it against vers1.so.
779 #
780 build_exec "vers3" vers3.c vers3 "" vers1.so vers3.ver vers3.dsym ""
781
782 #
783 # Test #4 - Make sure a version implicitly defined in an executable
784 # causes a version node to be created.  Verify this both with and without
785 # --export-dynamic.
786 #
787
788 # This test fails on MIPS.  On the MIPS we must put foo in the dynamic
789 # symbol table, which the test does not expect.
790 setup_xfail "mips*-*-*"
791 build_exec "vers4" vers4.c vers4 "" "" "" "" vers4.sym
792
793 build_exec "vers4a" vers4.c vers4a "-export-dynamic" "" vers4a.ver vers4a.dsym vers4a.sym
794
795
796 #
797 # Try multiple definitions foo@BAR and foo@@BAR and make sure the linker
798 # complains.
799 #
800 test_ldfail "vers5" "" vers5.c vers5 "" "" "multiple definition of foo@VERS_1.2"
801
802 #
803 #
804 # Now build a test that should reference a bunch of versioned symbols.
805 # All of them should be correctly referenced.
806 #
807 build_exec "vers6" vers6.c vers6 "" vers1.so vers6.ver vers6.dsym vers6.sym
808
809 #
810 # Another test to verify that something made local via 'local' is truly not
811 # accessible.
812 #
813 build_vers_lib_no_pic "vers7a" vers7a.c vers7a "" vers7.map vers7a.ver vers7a.dsym vers7a.sym
814
815 test_ldfail "vers7" "" vers7.c vers7 vers7a.so "" "undefined reference to hide_a"
816
817
818 #
819 # This test is designed to verify that we can pass a linker script on the
820 # command line as if it were a normal .o file.
821 #
822 catch "exec cp $srcdir/$subdir/vers8.map $tmpdir/" ignore_output
823 build_vers_lib_no_pic "vers8" vers1.c vers8 vers8.map "" vers8.ver vers1.dsym vers1.sym
824
825 #
826 # This test tries to make sure that version references to versioned symbols
827 # don't collide with default definitions with the same symbol.
828 #
829 build_exec "vers9" vers9.c vers9 "-export-dynamic" "" vers9.ver vers9.dsym vers9.sym
830
831
832 #
833 # Try and use a non-existant version node.  The linker should fail with
834 # an error message.
835 #
836 test_ldfail "vers10" "-DDO_TEST10" vers1.c vers10 "" "vers1.map --shared" "invalid version"
837
838 #
839 # Try and some things the assembler should complain about.
840 #
841 test_asfail "vers11" "-DDO_TEST11" vers1.c vers11 "no @ in symver"
842
843 test_asfail "vers12" "-DDO_TEST12" vers1.c vers12 "extern version definition"
844
845 #
846 # Put a shared library in an archive library, and make sure the global
847 # archive symbol table is sane.
848 #
849 test_ar "ar with versioned solib" vers13.a vers1.so vers13.asym
850
851 #
852 # Strip a shared library, and make sure we didn't screw something up in there.
853 #
854 test_strip_vers_lib "vers14" vers1.so vers14 vers1.ver vers1.dsym 
855
856
857 #
858 # Build another test with some versioned symbols.  Here we are going to 
859 # try and override something from the library, and we shouldn't get
860 # any errors.
861 #
862 build_exec "vers15" vers15.c vers15 "" vers1.so vers15.ver vers15.dsym vers15.sym
863
864 #
865 # Test that when we override a versioned symbol from the library this
866 # symbol appears in the dynamic symbol table of the executable.
867 #
868 build_vers_lib_no_pic "vers16a" vers16a.c vers16a "" vers16.map vers16a.ver vers16a.dsym ""
869 build_exec "vers16" vers16.c vers16 "" vers16a.so "" vers16.dsym ""
870
871 # Test a weak versioned symbol.
872 build_vers_lib_no_pic "vers17" vers17.c vers17 "" vers17.map vers17.ver vers17.dsym ""
873 build_vers_lib_no_pic "vers18" vers18.c vers18 vers17.so vers18.map vers18.ver vers18.dsym vers18.sym
874 build_exec "vers19" vers19.c vers19 "-rpath ." vers18.so vers19.ver vers19.dsym ""
875
876 build_vers_lib_no_pic "vers20a" vers20.c vers20a "" vers20.map vers20a.ver vers20.dsym ""
877 exec cp $tmpdir/vers20a.so $tmpdir/vers20b.so
878 build_vers_lib_no_pic "vers20" vers20.c vers20 "vers20a.so vers20b.so" vers20.map vers20.ver vers20.dsym ""
879
880 # Test .symver override.
881 build_vers_lib_no_pic "vers21" vers21.c vers21 "" vers21.map vers21.ver vers21.dsym vers21.sym
882
883 # Test moving default definition from one DSO to another.
884 build_vers_lib_no_pic "vers22a" vers22a.c vers22a "" vers22.map vers22a.ver vers22a.dsym vers22a.sym
885 build_vers_lib_no_pic "vers22b" vers22b.c vers22b "" vers22.map vers22b.ver vers22b.dsym ""
886 build_vers_lib_no_pic "vers22" vers22.c vers22 "vers22a.so vers22b.so" "" vers22.ver vers22.dsym ""
887
888 # Test versioned definitions in different files.
889 build_vers_lib_no_pic "vers23a" vers23a.c vers23a "" vers23a.map vers23a.ver vers23a.dsym vers23a.sym
890 build_vers_lib_no_pic "vers23b" vers23b.c vers23b "" vers23b.map vers23b.ver vers23b.dsym ""
891 build_vers_lib_no_pic "vers23c" vers23b.c vers23c "vers23a.so" vers23b.map vers23c.ver vers23b.dsym ""
892 build_exec "vers23d" vers23.c vers23d "tmpdir/vers23a.so tmpdir/vers23c.so" "" vers23.ver vers23d.dsym ""
893 build_exec "vers23" vers23.c vers23 "tmpdir/vers23a.so tmpdir/vers23b.o tmpdir/vers23b.so" "" vers23.ver vers23.dsym ""
894
895 # Test .symver x,x@VERS.0
896 set as_pic_flags ""
897 if [istarget sparc*-*-*] {
898   set as_pic_flags "-K PIC"
899 }
900 run_ld_link_tests [list "\"vers24a\"
901                          \"-shared --version-script $srcdir/$subdir/vers24.map\"
902                          \"$as_pic_flags\" {vers24a.c vers24b.c} { { readelf -Wrs vers24.rd } }
903                          \"libvers24a.so\" \"-fpic\""]
904 run_ld_link_tests [list "\"vers24b\"
905                          \"-shared --version-script $srcdir/$subdir/vers24.map\"
906                          \"$as_pic_flags\" {vers24b.c vers24a.c} { { readelf -Wrs vers24.rd } }
907                          \"libvers24b.so\" \"-fpic\""]
908 run_ld_link_tests [list "\"vers24c\"
909                          \"-shared --version-script $srcdir/$subdir/vers24.map\"
910                          \"$as_pic_flags\" {vers24c.c} { { readelf -Wrs vers24.rd } }
911                          \"libvers24c.so\" \"-fpic\""]
912
913 # Test versioned definition vs. normal definition in different files.
914 build_vers_lib_no_pic "vers25a" vers25a.c vers25a "" vers25a.map vers25a.ver vers25a.dsym ""
915 build_vers_lib_no_pic "vers25b1" vers25b.c vers25b1 "vers25a.o vers25a.so" "" vers25b.ver vers25b.dsym ""
916 build_vers_lib_no_pic "vers25b2" vers25b.c vers25b2 "vers25a.so vers25a.o" "" vers25b.ver vers25b.dsym ""
917 build_vers_lib_pic "vers26a" vers26a.c vers26a "" vers26a.map vers26a.ver vers26a.dsym ""
918 build_vers_lib_pic "vers26b1" vers26b.c vers26b1 "" "" vers26b.ver vers26b.dsym ""
919 build_vers_lib_pic "vers26b2" vers26b.c vers26b2 "vers26a.so vers26b1.so vers26a.o" "" vers26b.ver vers26b.dsym ""
920 if [istarget x86_64-*-linux*] {
921     # x86_64 doesn't like non-pic shared libraries
922     xfail "vers26b3"
923 } else {
924     build_vers_lib_no_pic "vers26b3" vers26b.c vers26b3 "vers26a.so vers26b1.so vers26a.o" "" vers26b.ver vers26b.dsym ""
925 }
926
927 # Test versioned definition vs. hidden definition in different files.
928 build_vers_lib_no_pic "vers27a" vers27a.c vers27a "" vers27a.map vers27a.ver vers27a.dsym ""
929 build_vers_lib_no_pic "vers27b" vers27b.c vers27b "" "" vers27b.ver vers27b.dsym ""
930 build_vers_lib_no_pic "vers27c1" vers27c.c vers27c1 "vers27b.o vers27a.so" "" vers27c.ver vers27c.dsym ""
931 build_vers_lib_no_pic "vers27c2" vers27c.c vers27c2 "vers27a.so vers27b.o" "" vers27c.ver vers27c.dsym ""