* ld-i386/i386.exp: Only run tests on ELF targets.
[external/binutils.git] / ld / testsuite / ld-i386 / i386.exp
1 # Expect script for ld-i386 tests
2 #   Copyright (C) 2000, 2001, 2002 Free Software Foundation
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
19 # Test i386 linking; all types of relocs.  This tests the assembler and
20 # tools like objdump as well as the linker.
21
22 if { !([istarget "i?86-*-elf*"]         
23        || ([istarget "i?86-*-linux*"]
24            && ![istarget "*-*-*aout*"]
25            && ![istarget "*-*-*oldld*"])) } {
26     return
27 }
28
29 # FIXME: This isn't set by testsuite/config/default.exp; make it.
30 if ![info exists readelf] then {
31     set readelf [findfile $base_dir/../binutils/readelf]
32 }
33
34 # List contains test-items with 3 items followed by 2 lists:
35 # 0:name 1:ld options 2:assembler options
36 # 3:filenames of assembler files 4: action and options. 5: name of output file
37
38 # Actions:
39 # objdump: Apply objdump options on result.  Compare with regex (last arg).
40 # nm: Apply nm options on result.  Compare with regex (last arg).
41 # readelf: Apply readelf options on result.  Compare with regex (last arg).
42
43 set i386tests {
44     {"TLS -fpic -shared transitions" "-shared -melf_i386"
45      "--32" {tlspic1.s tlspic2.s}
46      {{readelf -Ssrl tlspic.rd} {objdump -drj.text tlspic.dd}
47       {objdump -sj.got tlspic.sd} {objdump -sj.tdata tlspic.td}}
48       "libtlspic.so"}
49     {"Helper shared library" "-shared -melf_i386"
50      "--32" {tlslib.s} {} "libtlslib.so"}
51     {"TLS -fpic and -fno-pic exec transitions"
52      "-melf_i386 tmpdir/libtlslib.so" "--32" {tlsbinpic.s tlsbin.s}
53      {{readelf -Ssrl tlsbin.rd} {objdump -drj.text tlsbin.dd}
54       {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}}
55       "tlsbin"}
56     {"TLS -fno-pic -shared" "-shared -melf_i386"
57      "--32" {tlsnopic1.s tlsnopic2.s}
58      {{readelf -Ssrl tlsnopic.rd} {objdump -drj.text tlsnopic.dd}
59       {objdump -sj.got tlsnopic.sd}} "libtlsnopic.so"}
60 }
61
62 # FIXME: Generalize and move this to ld-lib.exp
63
64 proc run_ld_link_tests { ldtests } {
65     global ld
66     global as
67     global nm
68     global objdump
69     global readelf
70     global srcdir
71     global subdir
72     global env
73
74     foreach testitem $ldtests {
75         set testname [lindex $testitem 0]
76         set ld_options [lindex $testitem 1]
77         set as_options [lindex $testitem 2]
78         set as_files  [lindex $testitem 3]
79         set actions [lindex $testitem 4]
80         set binfile tmpdir/[lindex $testitem 5]
81         set objfiles {}
82         set is_unresolved 0
83         set failed 0
84
85 #       verbose -log "Testname is $testname"
86 #       verbose -log "ld_options is $ld_options"
87 #       verbose -log "as_options is $as_options"
88 #       verbose -log "as_files is $as_files"
89 #       verbose -log "actions is $actions"
90 #       verbose -log "binfile is $binfile"
91
92         # Assemble each file in the test.
93         foreach as_file $as_files {
94             set objfile "tmpdir/[file rootname $as_file].o"
95             lappend objfiles $objfile
96
97             if ![ld_assemble $as "$as_options $srcdir/$subdir/$as_file" $objfile] {
98                 set is_unresolved 1
99                 break
100             }
101         }
102
103         # Catch assembler errors.
104         if { $is_unresolved != 0 } {
105             unresolved $testname
106             continue
107         }
108
109         if ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] {
110             fail $testname
111         } else {
112             set failed 0
113             foreach actionlist $actions {
114                 set action [lindex $actionlist 0]
115                 set progopts [lindex $actionlist 1]
116
117                 # There are actions where we run regexp_diff on the
118                 # output, and there are other actions (presumably).
119                 # Handling of the former look the same.
120                 set dump_prog ""
121                 switch -- $action {
122                     objdump
123                         { set dump_prog $objdump }
124                     nm
125                         { set dump_prog $nm }
126                     readelf
127                         { set dump_prog $readelf }
128                     default
129                         {
130                             perror "Unrecognized action $action"
131                             set is_unresolved 1
132                             break
133                         }
134                     }
135
136                 if { $dump_prog != "" } {
137                     set dumpfile [lindex $actionlist 2]
138                     set binary $dump_prog
139
140                     # Ensure consistent sorting of symbols
141                     if {[info exists env(LC_ALL)]} {
142                         set old_lc_all $env(LC_ALL)
143                     }
144                     set env(LC_ALL) "C"
145                     set cmd "$binary $progopts $binfile > dump.out"
146                     send_log "$cmd\n"
147                     catch "exec $cmd" comp_output
148                     if {[info exists old_lc_all]} {
149                         set env(LC_ALL) $old_lc_all
150                     } else {
151                         unset env(LC_ALL)
152                     }
153                     set comp_output [prune_warnings $comp_output]
154
155                     if ![string match "" $comp_output] then {
156                         send_log "$comp_output\n"
157                         set failed 1
158                         break
159                     }
160
161                     if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then {
162                         verbose "output is [file_contents "dump.out"]" 2
163                         set failed 1
164                         break
165                     }
166                 }
167             }
168
169             if { $failed != 0 } {
170                 fail $testname
171             } else { if { $is_unresolved == 0 } {
172                 pass $testname
173             } }
174         }
175
176         # Catch action errors.
177         if { $is_unresolved != 0 } {
178             unresolved $testname
179             continue
180         }
181     }
182 }
183
184 run_ld_link_tests $i386tests