2003-05-07 H.J. Lu <hongjiu.lu@intel.com>
[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_binary { shared 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 script
512
513     if ![ld_compile "$CC -S $pic $CFLAGS" $srcdir/$subdir/$source $tmpdir/$libname.s]     {
514         unresolved "$test"
515         return
516     }
517
518     if ![ld_assemble $as $tmpdir/$libname.s $tmpdir/$libname.o ]     {
519         unresolved "$test"
520         return
521     }
522
523     set other_lib ""
524     if ![string match "" $other] then {
525         foreach o $other {
526             set other_lib "$other_lib $tmpdir/$o"
527         }
528     }
529
530     if [string match "" $mapfile] then {
531         set script_arg ""
532     } else {
533         set script_arg "$script $srcdir/$subdir/$mapfile"
534     }
535
536     if {![ld_simple_link $ld $tmpdir/$libname.so "$shared $tmpdir/$libname.o $other_lib $script_arg"]}     {
537         fail "$test"
538         return
539     }
540
541     if {![objdump_versionstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$verexp ]}     {
542         fail "$test"
543         return
544     }
545
546     if {![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$versymexp ]}     {
547         fail "$test"
548         return
549     }
550
551     if [string match "" $symexp] then {
552         if {![objdump_emptysymstuff $objdump $tmpdir/$libname.o ]}     {
553             fail "$test"
554             return
555         }
556     } else {
557         if {![objdump_symstuff $objdump $tmpdir/$libname.o $srcdir/$subdir/$symexp ]}     {
558             fail "$test"
559             return
560         }
561     }
562
563     pass $test
564     
565 }
566
567 proc build_executable { test source libname other mapfile verexp versymexp symexp } {
568   build_binary "" "" $test $source $libname $other $mapfile $verexp $versymexp $symexp 
569 }
570
571 proc build_vers_lib_no_pic { test source libname other mapfile verexp versymexp symexp } {
572   global shared
573   build_binary $shared "" $test $source $libname $other $mapfile $verexp $versymexp $symexp 
574 }
575
576 proc build_vers_lib_pic { test source libname other mapfile verexp versymexp symexp } {
577   global picflag
578   global shared
579   build_binary $shared $picflag $test $source $libname $other $mapfile $verexp $versymexp $symexp 
580 }
581
582 proc test_ldfail { test flag source execname other mapfile whyfail } {
583     global ld
584     global srcdir
585     global subdir
586     global exec_output
587     global host_triplet
588     global tmpdir
589     global as
590     global objdump
591     global CC
592     global CFLAGS
593     global script
594
595     if [string match "" $other] then {
596         set other_lib ""
597     } else {
598         set other_lib $tmpdir/$other
599     }
600
601     if ![ld_compile "$CC -S $flag $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s]     {
602         unresolved "$test"
603         return
604     }
605
606     if ![ld_assemble $as $tmpdir/$execname.s $tmpdir/$execname.o ]     {
607         unresolved "$test"
608         return
609     }
610
611     verbose -log "This link should fail because of $whyfail"
612
613     if [string match "" $mapfile] then {
614         set script_arg ""
615     } else {
616         set script_arg "$script $srcdir/$subdir/$mapfile"
617     }
618
619     if {![ld_link $ld $tmpdir/$execname "$tmpdir/$execname.o $other_lib $script_arg"]}     {
620         pass "$test"
621         return
622     }
623     fail "$test"
624 }
625
626 proc test_asfail { test flag source execname whyfail } {
627     global srcdir
628     global subdir
629     global tmpdir
630     global as
631     global CC
632     global CFLAGS
633
634     if ![ld_compile "$CC -S $flag $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s]     {
635         unresolved "$test"
636         return
637     }
638
639     verbose -log "This assemble should fail because of $whyfail"
640     catch "exec $as -o $tmpdir/$execname.o $tmpdir/$execname.s" exec_output
641     set exec_output [prune_warnings $exec_output]
642     if [string match "" $exec_output] then {
643         fail "$test"
644         return
645     }
646     verbose -log "$exec_output"
647     pass "$test"
648 }
649
650 proc test_strip_vers_lib { test srclib libname verexp versymexp } {
651     global strip
652     global srcdir
653     global subdir
654     global exec_output
655     global host_triplet
656     global tmpdir
657     global objdump
658
659     verbose -log "cp $tmpdir/$srclib $tmpdir/$libname.so"
660     exec cp $tmpdir/$srclib $tmpdir/$libname.so
661
662     verbose -log "$strip $tmpdir/$libname.so"
663     catch "exec $strip $tmpdir/$libname.so" exec_output
664     if [string match "" $exec_output] then {
665
666 # If strip went OK, then run the usual tests on the thing to make sure that
667 # it is sane.
668         if {![objdump_versionstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$verexp ]}     {
669             fail "$test"
670             return
671         }
672         
673         if {![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$versymexp ]}     {
674             fail "$test"
675             return
676         }
677         
678     } else {
679         verbose -log "$exec_output"
680         fail "$test"
681         return
682     }
683     pass $test
684 }
685
686
687 proc build_exec { test source execname flags solibname verexp versymexp symexp } {
688     global ld
689     global srcdir
690     global subdir
691     global exec_output
692     global host_triplet
693     global tmpdir
694     global as
695     global objdump
696     global CC
697     global CFLAGS
698
699     set shared "--shared --no-undefined-version"
700     set script --version-script
701     if ![ld_compile "$CC -S $CFLAGS" $srcdir/$subdir/$source $tmpdir/$execname.s]     {
702         unresolved "$test"
703         return
704     }
705
706     if ![ld_assemble $as $tmpdir/$execname.s $tmpdir/$execname.o ]     {
707         unresolved "$test"
708         return
709     }
710
711     if [string match "" $solibname] then {
712         set solibname_lib ""
713     } else {
714         set solibname_lib $tmpdir/$solibname
715     }
716
717     if {![ld_link $ld $tmpdir/$execname "$flags $tmpdir/$execname.o $solibname_lib"]}     {
718         fail "$test"
719         return
720     }
721
722     if [string match "" $verexp] then {
723 #
724 # Make sure we get nothing back.
725 #
726         if {![objdump_emptyverstuff $objdump $tmpdir/$execname ]}     {
727             fail "$test"
728             return
729         }
730     } else {
731         if {![objdump_versionstuff $objdump $tmpdir/$execname $srcdir/$subdir/$verexp ]}     {
732             fail "$test"
733             return
734         }
735     }
736
737     if [string match "" $versymexp] then {
738         if {![objdump_emptydynsymstuff $objdump $tmpdir/$execname ]}     {
739             fail "$test"
740             return
741         }
742     } else {
743         if {![objdump_dynsymstuff $objdump $tmpdir/$execname $srcdir/$subdir/$versymexp ]}     {
744             fail "$test"
745             return
746         }
747     }
748
749     if [string match "" $symexp] then {
750         if {![objdump_emptysymstuff $objdump $tmpdir/$execname.o ]}     {
751             fail "$test"
752             return
753         }
754     } else {
755         if {![objdump_symstuff $objdump $tmpdir/$execname.o $srcdir/$subdir/$symexp ]}     {
756             fail "$test"
757             return
758         }
759     }
760
761     pass $test
762 }
763
764
765 #
766 # Basic test - build a library with versioned symbols.
767 #
768 build_vers_lib_no_pic "vers1" vers1.c vers1 "" vers1.map vers1.ver vers1.dsym vers1.sym
769
770
771 #
772 # Test #2 - build a library, and link it against the library we built in step
773 # 1.
774 #
775 if [istarget x86_64-*-linux*] {
776     # x86_64 doesn't like non-pic shared libraries
777     xfail "vers2"
778 } else {
779     build_vers_lib_no_pic "vers2" vers2.c vers2 vers1.so vers2.map vers2.ver vers2.dsym ""
780 }
781
782 #
783 # Test #3 - build an executable, and link it against vers1.so.
784 #
785 build_exec "vers3" vers3.c vers3 "" vers1.so vers3.ver vers3.dsym ""
786
787 #
788 # Test #4 - Make sure a version implicitly defined in an executable
789 # causes a version node to be created.  Verify this both with and without
790 # --export-dynamic.
791 #
792
793 # This test fails on MIPS.  On the MIPS we must put foo in the dynamic
794 # symbol table, which the test does not expect.
795 setup_xfail "mips*-*-*"
796 build_exec "vers4" vers4.c vers4 "" "" "" "" vers4.sym
797
798 build_exec "vers4a" vers4.c vers4a "-export-dynamic" "" vers4a.ver vers4a.dsym vers4a.sym
799
800
801 #
802 # Try multiple definitions foo@BAR and foo@@BAR and make sure the linker
803 # complains.
804 #
805 test_ldfail "vers5" "" vers5.c vers5 "" "" "multiple definition of foo@VERS_1.2"
806
807 #
808 #
809 # Now build a test that should reference a bunch of versioned symbols.
810 # All of them should be correctly referenced.
811 #
812 build_exec "vers6" vers6.c vers6 "" vers1.so vers6.ver vers6.dsym vers6.sym
813
814 #
815 # Another test to verify that something made local via 'local' is truly not
816 # accessible.
817 #
818 build_vers_lib_no_pic "vers7a" vers7a.c vers7a "" vers7.map vers7a.ver vers7a.dsym vers7a.sym
819
820 test_ldfail "vers7" "" vers7.c vers7 vers7a.so "" "undefined reference to hide_a"
821
822
823 #
824 # This test is designed to verify that we can pass a linker script on the
825 # command line as if it were a normal .o file.
826 #
827 catch "exec cp $srcdir/$subdir/vers8.map $tmpdir/" ignore_output
828 build_vers_lib_no_pic "vers8" vers1.c vers8 vers8.map "" vers8.ver vers1.dsym vers1.sym
829
830 #
831 # This test tries to make sure that version references to versioned symbols
832 # don't collide with default definitions with the same symbol.
833 #
834 build_exec "vers9" vers9.c vers9 "-export-dynamic" "" vers9.ver vers9.dsym vers9.sym
835
836
837 #
838 # Try and use a non-existant version node.  The linker should fail with
839 # an error message.
840 #
841 test_ldfail "vers10" "-DDO_TEST10" vers1.c vers10 "" "vers1.map --shared" "invalid version"
842
843 #
844 # Try and some things the assembler should complain about.
845 #
846 test_asfail "vers11" "-DDO_TEST11" vers1.c vers11 "no @ in symver"
847
848 test_asfail "vers12" "-DDO_TEST12" vers1.c vers12 "extern version definition"
849
850 #
851 # Put a shared library in an archive library, and make sure the global
852 # archive symbol table is sane.
853 #
854 test_ar "ar with versioned solib" vers13.a vers1.so vers13.asym
855
856 #
857 # Strip a shared library, and make sure we didn't screw something up in there.
858 #
859 test_strip_vers_lib "vers14" vers1.so vers14 vers1.ver vers1.dsym 
860
861
862 #
863 # Build another test with some versioned symbols.  Here we are going to 
864 # try and override something from the library, and we shouldn't get
865 # any errors.
866 #
867 build_exec "vers15" vers15.c vers15 "" vers1.so vers15.ver vers15.dsym vers15.sym
868
869 #
870 # Test that when we override a versioned symbol from the library this
871 # symbol appears in the dynamic symbol table of the executable.
872 #
873 build_vers_lib_no_pic "vers16a" vers16a.c vers16a "" vers16.map vers16a.ver vers16a.dsym ""
874 build_exec "vers16" vers16.c vers16 "" vers16a.so "" vers16.dsym ""
875
876 # Test a weak versioned symbol.
877 build_vers_lib_no_pic "vers17" vers17.c vers17 "" vers17.map vers17.ver vers17.dsym ""
878 build_vers_lib_no_pic "vers18" vers18.c vers18 vers17.so vers18.map vers18.ver vers18.dsym vers18.sym
879 build_exec "vers19" vers19.c vers19 "-rpath ." vers18.so vers19.ver vers19.dsym ""
880
881 build_vers_lib_no_pic "vers20a" vers20.c vers20a "" vers20.map vers20a.ver vers20.dsym ""
882 exec cp $tmpdir/vers20a.so $tmpdir/vers20b.so
883 build_vers_lib_no_pic "vers20" vers20.c vers20 "vers20a.so vers20b.so" vers20.map vers20.ver vers20.dsym ""
884
885 # Test .symver override.
886 build_vers_lib_no_pic "vers21" vers21.c vers21 "" vers21.map vers21.ver vers21.dsym vers21.sym
887
888 # Test moving default definition from one DSO to another.
889 build_vers_lib_no_pic "vers22a" vers22a.c vers22a "" vers22.map vers22a.ver vers22a.dsym vers22a.sym
890 build_vers_lib_no_pic "vers22b" vers22b.c vers22b "" vers22.map vers22b.ver vers22b.dsym ""
891 build_vers_lib_no_pic "vers22" vers22.c vers22 "vers22a.so vers22b.so" "" vers22.ver vers22.dsym ""
892
893 # Test versioned definitions in different files.
894 build_vers_lib_no_pic "vers23a" vers23a.c vers23a "" vers23a.map vers23a.ver vers23a.dsym vers23a.sym
895 build_vers_lib_no_pic "vers23b" vers23b.c vers23b "" vers23b.map vers23b.ver vers23b.dsym ""
896 build_vers_lib_no_pic "vers23c" vers23b.c vers23c "vers23a.so" vers23b.map vers23c.ver vers23b.dsym ""
897 build_exec "vers23d" vers23.c vers23d "tmpdir/vers23a.so tmpdir/vers23c.so" "" vers23.ver vers23d.dsym ""
898 build_exec "vers23" vers23.c vers23 "tmpdir/vers23a.so tmpdir/vers23b.o tmpdir/vers23b.so" "" vers23.ver vers23.dsym ""
899
900 # Test .symver x,x@VERS.0
901 set as_pic_flags ""
902 if [istarget sparc*-*-*] {
903   set as_pic_flags "-K PIC"
904 }
905 run_ld_link_tests [list "\"vers24a\"
906                          \"-shared --version-script $srcdir/$subdir/vers24.map\"
907                          \"$as_pic_flags\" {vers24a.c vers24b.c} { { readelf -Wrs vers24.rd } }
908                          \"libvers24a.so\" \"-fpic\""]
909 run_ld_link_tests [list "\"vers24b\"
910                          \"-shared --version-script $srcdir/$subdir/vers24.map\"
911                          \"$as_pic_flags\" {vers24b.c vers24a.c} { { readelf -Wrs vers24.rd } }
912                          \"libvers24b.so\" \"-fpic\""]
913 run_ld_link_tests [list "\"vers24c\"
914                          \"-shared --version-script $srcdir/$subdir/vers24.map\"
915                          \"$as_pic_flags\" {vers24c.c} { { readelf -Wrs vers24.rd } }
916                          \"libvers24c.so\" \"-fpic\""]
917
918 # Test versioned definition vs. normal definition in different files.
919 build_vers_lib_no_pic "vers25a" vers25a.c vers25a "" vers25a.map vers25a.ver vers25a.dsym ""
920 build_vers_lib_no_pic "vers25b1" vers25b.c vers25b1 "vers25a.o vers25a.so" "" vers25b.ver vers25b.dsym ""
921 build_vers_lib_no_pic "vers25b2" vers25b.c vers25b2 "vers25a.so vers25a.o" "" vers25b.ver vers25b.dsym ""
922 build_vers_lib_pic "vers26a" vers26a.c vers26a "" vers26a.map vers26a.ver vers26a.dsym ""
923 build_vers_lib_pic "vers26b1" vers26b.c vers26b1 "" "" vers26b.ver vers26b.dsym ""
924 build_vers_lib_pic "vers26b2" vers26b.c vers26b2 "vers26a.so vers26b1.so vers26a.o" "" vers26b.ver vers26b.dsym ""
925 if [istarget x86_64-*-linux*] {
926     # x86_64 doesn't like non-pic shared libraries
927     xfail "vers26b3"
928 } else {
929     build_vers_lib_no_pic "vers26b3" vers26b.c vers26b3 "vers26a.so vers26b1.so vers26a.o" "" vers26b.ver vers26b.dsym ""
930 }
931
932 # Test versioned definition vs. hidden definition in different files.
933 build_vers_lib_no_pic "vers27a" vers27a.c vers27a "" vers27a.map vers27a.ver vers27a.dsym ""
934 build_vers_lib_no_pic "vers27b" vers27b.c vers27b "" "" vers27b.ver vers27b.dsym ""
935 build_vers_lib_no_pic "vers27c1" vers27c.c vers27c1 "vers27b.o vers27a.so" "" vers27c.ver vers27c.dsym ""
936 build_vers_lib_no_pic "vers27c2" vers27c.c vers27c2 "vers27a.so vers27b.o" "" vers27c.ver vers27c.dsym ""
937 build_vers_lib_pic "vers27d1" vers27d1.c vers27d1 "" vers27a.map vers27d.ver vers27d.dsym vers27d.sym
938 build_vers_lib_pic "vers27d2" vers27d2.c vers27d2 "" "" vers27b.ver vers27b.dsym ""
939 build_executable "vers27d3" vers27d3.c vers27d3 "vers27b.o vers27d2.so vers27d1.so" "" vers27b.ver vers27b.dsym ""