1 # Expect script for ld-i386 tests
2 # Copyright (C) 2000, 2001, 2002 Free Software Foundation
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.
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.
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.
19 # Test i386 linking; all types of relocs. This tests the assembler and
20 # tools like objdump as well as the linker.
22 if ![istarget i?86-*-*] {
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]
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
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).
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}}
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}}
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"}
59 # FIXME: Generalize and move this to ld-lib.exp
61 proc run_ld_link_tests { ldtests } {
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]
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"
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
94 if ![ld_assemble $as "$as_options $srcdir/$subdir/$as_file" $objfile] {
100 # Catch assembler errors.
101 if { $is_unresolved != 0 } {
106 if ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] {
110 foreach actionlist $actions {
111 set action [lindex $actionlist 0]
112 set progopts [lindex $actionlist 1]
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.
120 { set dump_prog $objdump }
122 { set dump_prog $nm }
124 { set dump_prog $readelf }
127 perror "Unrecognized action $action"
133 if { $dump_prog != "" } {
134 set dumpfile [lindex $actionlist 2]
135 set binary $dump_prog
137 # Ensure consistent sorting of symbols
138 if {[info exists env(LC_ALL)]} {
139 set old_lc_all $env(LC_ALL)
142 set cmd "$binary $progopts $binfile > dump.out"
144 catch "exec $cmd" comp_output
145 if {[info exists old_lc_all]} {
146 set env(LC_ALL) $old_lc_all
150 set comp_output [prune_warnings $comp_output]
152 if ![string match "" $comp_output] then {
153 send_log "$comp_output\n"
158 if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then {
159 verbose "output is [file_contents "dump.out"]" 2
166 if { $failed != 0 } {
168 } else { if { $is_unresolved == 0 } {
173 # Catch action errors.
174 if { $is_unresolved != 0 } {
181 run_ld_link_tests $i386tests