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