1# Expect script for complex PE tests that require a C compiler
2# in addition to the just-built binutils.
3#   Copyright 2009
4#   Free Software Foundation, Inc.
5#
6# This file is part of the GNU Binutils.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21# MA 02110-1301, USA.
22#
23
24# These tests can only be run on PE/COFF platforms.
25if {![is_pecoff_format]} {
26    return
27}
28
29# No compiler, no test.
30if { [which $CC] == 0 } {
31    untested "PE version scripts"
32    untested "aligned common tests"
33    # Add more "untested" directives here when adding more tests below.
34    return
35}
36
37proc build_basefile1_o {} {
38    global CC
39    global CFLAGS
40    global srcdir
41    global subdir
42
43    # Compile the object file.
44    if ![ld_compile "$CC $CFLAGS" $srcdir/$subdir/basefile1.s tmpdir/basefile1.o] {
45	fail "compiling basefile1 object"
46    }
47}
48
49proc run_basefile_test { testname } {
50    global LD
51    global DLLTOOL
52    global srcdir
53    global subdir
54    global verbose
55
56    if ![ld_simple_link "$LD -e start \
57	    --base-file=tmpdir/$testname.base \
58	    --export-all-symbols" tmpdir/$testname.dll \
59	    "tmpdir/basefile1.o"] {
60	fail "linking DLL"
61	return
62    }
63
64    if { $verbose > 2 } then { verbose "output is [file_contents tmpdir/$testname.base]" 3 }
65
66    catch "exec wc -c tmpdir/$testname.base" err
67
68    if ![string match "0 tmpdir/$testname.base" [string trim $err]] then {
69      send_log "$err\n"
70      if { $verbose == 2 } then { verbose "$err" 2 }
71      fail $testname
72      return
73    }
74
75    pass "$testname"
76}
77
78proc build_vers_script_dll_o {} {
79    global CC
80    global CFLAGS
81    global srcdir
82    global subdir
83
84    # Compile the object file.
85    if ![ld_compile "$CC $CFLAGS -shared" $srcdir/$subdir/vers-script-dll.c tmpdir/vers-script-dll.o] {
86	fail "compiling shared lib object"
87    }
88}
89
90proc run_ver_script_test { testname } {
91    global CC
92    global srcdir
93    global subdir
94    global verbose
95
96    if ![ld_simple_link "$CC -shared \
97	    -Wl,--version-script,$srcdir/$subdir/$testname.ver \
98	    -Wl,--output-def,tmpdir/$testname.def" tmpdir/$testname.dll \
99	    "tmpdir/vers-script-dll.o"] {
100	fail "linking DLL"
101    }
102
103    if { $verbose > 2 } then { verbose "output is [file_contents tmpdir/$testname.def]" 3 }
104    if { [regexp_diff tmpdir/$testname.def $srcdir/$subdir/$testname.d] } then {
105	fail $testname
106	if { $verbose == 2 } then { verbose "output is [file_contents tmpdir/$testname.def]" 2 }
107	return
108    }
109
110    pass "$testname"
111}
112
113
114build_vers_script_dll_o
115
116run_ver_script_test "vers-script-1"
117run_ver_script_test "vers-script-2"
118run_ver_script_test "vers-script-3"
119run_ver_script_test "vers-script-4"
120
121if {[istarget i*86-*-cygwin*]
122    || [istarget i*86-*-pe]
123    || [istarget i*86-*-mingw*]
124    || [istarget x86_64-*-mingw*] } {
125
126   build_basefile1_o
127   run_basefile_test "basefile-secrel"
128 } else {
129    untested "PE basefile test"
130 }
131
132set align_tests {
133  {"aligned common 1" "" "" {aligncomm-1.c}
134   {{nm -C aligncomm.d}} "aligncomm-1.x"}
135  {"aligned common 2" "" "" {aligncomm-2.c}
136   {{nm -C aligncomm.d}} "aligncomm-2.x"}
137  {"aligned common 3" "" "" {aligncomm-3.c}
138   {{nm -C aligncomm.d}} "aligncomm-3.x"}
139  {"aligned common 4" "" "" {aligncomm-4.c}
140   {{nm -C aligncomm.d}} "aligncomm-4.x"}
141}
142
143run_ld_link_tests $align_tests
144