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-*-elf*"]
23 || ([istarget "i?86-*-linux*"]
24 && ![istarget "*-*-*aout*"]
25 && ![istarget "*-*-*oldld*"])) } {
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]
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
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).
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}}
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}}
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"}
62 # FIXME: Generalize and move this to ld-lib.exp
64 proc run_ld_link_tests { ldtests } {
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]
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"
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
97 if ![ld_assemble $as "$as_options $srcdir/$subdir/$as_file" $objfile] {
103 # Catch assembler errors.
104 if { $is_unresolved != 0 } {
109 if ![ld_simple_link $ld $binfile "-L$srcdir/$subdir $ld_options $objfiles"] {
113 foreach actionlist $actions {
114 set action [lindex $actionlist 0]
115 set progopts [lindex $actionlist 1]
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.
123 { set dump_prog $objdump }
125 { set dump_prog $nm }
127 { set dump_prog $readelf }
130 perror "Unrecognized action $action"
136 if { $dump_prog != "" } {
137 set dumpfile [lindex $actionlist 2]
138 set binary $dump_prog
140 # Ensure consistent sorting of symbols
141 if {[info exists env(LC_ALL)]} {
142 set old_lc_all $env(LC_ALL)
145 set cmd "$binary $progopts $binfile > dump.out"
147 catch "exec $cmd" comp_output
148 if {[info exists old_lc_all]} {
149 set env(LC_ALL) $old_lc_all
153 set comp_output [prune_warnings $comp_output]
155 if ![string match "" $comp_output] then {
156 send_log "$comp_output\n"
161 if { [regexp_diff "dump.out" "$srcdir/$subdir/$dumpfile"] } then {
162 verbose "output is [file_contents "dump.out"]" 2
169 if { $failed != 0 } {
171 } else { if { $is_unresolved == 0 } {
176 # Catch action errors.
177 if { $is_unresolved != 0 } {
184 run_ld_link_tests $i386tests