1194178Sed# Expect script for AIX 5.2+ tests
2194178Sed#   Copyright (C) 2009-2020 Free Software Foundation, Inc.
3194178Sed#
4194178Sed# This file is part of the GNU Binutils.
5194178Sed#
6194178Sed# This program is free software; you can redistribute it and/or modify
7194178Sed# it under the terms of the GNU General Public License as published by
8194178Sed# the Free Software Foundation; either version 3 of the License, or
9194178Sed# (at your option) any later version.
10194178Sed#
11194178Sed# This program is distributed in the hope that it will be useful,
12194178Sed# but WITHOUT ANY WARRANTY; without even the implied warranty of
13194178Sed# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14194178Sed# GNU General Public License for more details.
15194178Sed#
16194178Sed# You should have received a copy of the GNU General Public License
17194178Sed# along with this program; if not, write to the Free Software
18194178Sed# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19194178Sed# MA 02110-1301, USA.
20194178Sed#
21194178Sed
22194178Sedif { ![istarget "powerpc*-*-aix\[5-9\]*"] && ![istarget "rs6000-*-aix\[5-9\]*"]
23194612Sed     || [istarget "*-*-aix5.\[01\]*"] } {
24194178Sed    return
25194178Sed}
26194178Sed
27194612Sed# Run a run_link_tests-style test for AIX.  SIZE selects the target size
28194612Sed# (32 or 64).  The other arguments are elements of a run_link_tests test.
29194178Sed#
30198892Srdivacky# Make the following changes before running the test:
31194178Sed#
32194178Sed#    - Mention SIZE in the test name.
33212904Sdim#    - Add "-aSIZE --defsym size=SIZE" to the assembler options.
34194178Sed#    - Add the source directory to any "-bI:" and "-bE:" linker options.
35194178Sed#    - Add "-bSIZE" to the linker options.
36194178Sed#    - Add "-XSIZE" to the archiver options.
37194178Sed#    - Replace "SIZE" with SIZE in TOOLS.
38194178Sed#    - When testing 64-bit targets:
39194178Sed#      - Turn tmpdir/aix-* into tmpdir/aix64-*.
40194178Sed#      - Turn tmpdir/libaix-* into tmpdir/libaix64-*.
41194178Sed#      - Turn -laix* into -laix64*, to compensate for the above.
42194178Sedproc run_aix_test { size name ldopts asopts sources tools output } {
43212904Sdim    global srcdir subdir
44212904Sdim
45194178Sed    if { $size == 64 } {
46194178Sed	regsub -all {tmpdir/aix-} $ldopts {tmpdir/aix64-} ldopts
47194178Sed	regsub {^aix} $output {aix64} output
48194178Sed
49194178Sed	regsub -all -- {-laix-} $ldopts {-laix64-} ldopts
50194178Sed	regsub {^libaix} $output {libaix64} output
51198090Srdivacky    }
52198090Srdivacky    if { [regexp {.a$} $output] } {
53194178Sed	append ldopts " -X$size"
54194178Sed    } else {
55194178Sed	regsub -all {(-b[IE]):} $ldopts "\\1:$srcdir/$subdir/" ldopts
56194178Sed	append ldopts " -b$size"
57194178Sed    }
58194178Sed    regsub -all {SIZE} $tools $size tools
59194178Sed    run_ld_link_tests [list [list "$name ($size-bit)" \
60194178Sed				 $ldopts "" \
61194178Sed				 "$asopts -a$size --defsym size=$size" \
62194178Sed				 $sources \
63194178Sed				 $tools \
64194178Sed				 $output]]
65194178Sed}
66194178Sed
67194178Sedforeach file { "aix-lineno-1.txt" } {
68194178Sed    remote_upload host "$srcdir/$subdir/$file" "tmpdir/$file"
69194178Sed}
70210299Sed
71212904Sdimset aix52tests {
72212904Sdim    {"Absolute branch test 1"
73194178Sed     "-shared -bI:aix-abs-branch-1.im -bE:aix-abs-branch-1.ex"
74194178Sed     "" {aix-abs-branch-1.s}
75210299Sed     {{objdump {-dR} aix-abs-branch-1.dd} {nm {} aix-abs-branch-1-SIZE.nd}}
76210299Sed     "aix-abs-branch-1.so"}
77210299Sed
78194178Sed    {"Relocations against absolute symbols 1"
79194178Sed     "-shared -bI:aix-abs-reloc-1.im -bE:aix-abs-reloc-1.ex"
80194178Sed     {} {aix-abs-reloc-1.s}
81194178Sed     {{objdump -sRj.data aix-abs-reloc-1-SIZE.od}
82194178Sed      {nm {} aix-abs-reloc-1-SIZE.nd}}
83194178Sed     "aix-abs-reloc-1.so"}
84194178Sed
85194178Sed    {"Core sections test 1" "-shared -bE:aix-core-sec-1.ex"
86194178Sed     "" {aix-core-sec-1.s}
87194178Sed     {{objdump -h aix-core-sec-1.hd}}
88194178Sed     "aix-core-sec-1.so"}
89194178Sed
90194178Sed    {"Core sections test 2" "-shared -bE:aix-core-sec-2.ex"
91194178Sed     "" {aix-core-sec-2.s}
92194178Sed     {{objdump -h aix-core-sec-2.hd}}
93194178Sed     "aix-core-sec-2.so"}
94194178Sed
95194178Sed    {"Core sections test 3" "-shared -bE:aix-core-sec-3.ex"
96194178Sed     "" {aix-core-sec-3.s}
97194178Sed     {{objdump -h aix-core-sec-3.hd}}
98194178Sed     "aix-core-sec-3.so"}
99194178Sed
100194178Sed    {"Duplicate symbol check 1 (rel)" "-r"
101194178Sed     "" {aix-no-dup-syms-1a.s aix-no-dup-syms-1b.s}
102194178Sed     {{nm {} aix-no-dup-syms-1-rel.nd} {objdump -r aix-no-dup-syms-1-rel.rd}}
103194178Sed     "aix-no-dup-syms-1.o"}
104194178Sed
105194178Sed    {"Duplicate symbol check 1 (shared)"
106194178Sed     "-shared --allow-multiple-definition -bI:aix-no-dup-syms-1.im -bE:aix-no-dup-syms-1.ex"
107194178Sed     "" {aix-no-dup-syms-1a.s aix-no-dup-syms-1b.s}
108194178Sed     {{nm {} aix-no-dup-syms-1-dso-SIZE.nd}
109194178Sed      {objdump -r aix-no-dup-syms-1-dso-SIZE.rd}
110194178Sed      {nm -D aix-no-dup-syms-1-dso-SIZE.dnd}
111194178Sed      {objdump -R aix-no-dup-syms-1-dso-SIZE.drd}}
112194178Sed     "aix-no-dup-syms-1.so"}
113194178Sed
114194178Sed    {"Export test 1 (archive)" ""
115194178Sed      "" {aix-export-1a.s}
116194178Sed      {} "libaix-export-1.a"}
117194178Sed
118194178Sed    {"Export test 1 (object)" "-r"
119194178Sed      "" {aix-export-1b.s}
120194178Sed      {} "aix-export-1.o"}
121194178Sed
122203954Srdivacky    {"Export test 1 (-bexpall)"
123194178Sed     "-shared -bexpall tmpdir/aix-export-1.o -Ltmpdir -laix-export-1"
124194178Sed     "" {}
125207618Srdivacky     {{objdump -dj.data aix-export-1-all-SIZE.dd}}
126207618Srdivacky     "aix-export-1-all.so"}
127194178Sed
128194178Sed    {"Export test 1 (-bexpfull)"
129194178Sed     "-shared -bexpfull tmpdir/aix-export-1.o -Ltmpdir -laix-export-1"
130194178Sed     "" {}
131194178Sed     {{objdump -dj.data aix-export-1-full-SIZE.dd}}
132207618Srdivacky     "aix-export-1-full.so"}
133207618Srdivacky
134207618Srdivacky    {"Export test 2" "-shared -bexpall"
135207618Srdivacky     {} {aix-export-2.s}
136194178Sed     {{nm -D aix-export-2-SIZE.nd}} "aix-export-2.so"}
137194178Sed
138194178Sed    {"Garbage collection test 1"
139194178Sed     "-shared -binitfini:init_function:fini_function -bE:aix-gc-1.ex"
140194178Sed     "" {aix-gc-1.s}
141194178Sed     {{objdump {-dz -j.text -j.data} aix-gc-1-SIZE.dd}
142194612Sed      {nm {} aix-gc-1-SIZE.nd}}
143194612Sed     "aix-gc-1.so"}
144194178Sed
145194178Sed    {"Glink test 1"
146194178Sed     "-shared -bE:aix-glink-1.ex --unresolved-symbols=ignore-all"
147194178Sed     "" {aix-glink-1.s}
148194178Sed     {{objdump {-D -j.text -j.data} aix-glink-1-SIZE.dd}}
149194178Sed     "aix-glink-1.so"}
150194178Sed
151194178Sed    {"Glink test 2 (part a)" "-shared -bE:aix-glink-2a.ex"
152202375Srdivacky     "" {aix-glink-2a.s}
153194178Sed     {}
154194178Sed     "aix-glink-2a.so"}
155194178Sed
156194178Sed    {"Glink test 2 (part b)" "-r"
157194178Sed     "" {aix-glink-2b.s}
158194178Sed     {}
159194178Sed     "aix-glink-2b.ro"}
160194178Sed
161194178Sed    {"Glink test 2 (part c)" "-shared -bE:aix-glink-2c.ex"
162194178Sed     "" {aix-glink-2c.s}
163194178Sed     {}
164212904Sdim     "aix-glink-2c.so"}
165194178Sed
166194178Sed    {"Glink test 2"
167194178Sed     "-e.main tmpdir/aix-glink-2a.so tmpdir/aix-glink-2b.ro tmpdir/aix-glink-2c.so"
168194178Sed     "" {aix-glink-2d.s}
169194178Sed     {{objdump -d aix-glink-2-SIZE.dd}}
170194178Sed     "aix-glink-2"}
171194178Sed
172194178Sed    {"Glink test 3 (shared library a)"
173194178Sed     "-shared -bexpall"
174194178Sed     "" {aix-glink-3a.s}
175194178Sed     {} "aix-glink-3a.so"}
176194178Sed
177194178Sed    {"Glink test 3 (shared library b)"
178194178Sed     "-shared -bexpall"
179194178Sed     "" {aix-glink-3b.s}
180195340Sed     {} "aix-glink-3b.so"}
181
182    {"Glink test 3 (main test)"
183     "-bnoautoimp tmpdir/aix-glink-3b.so tmpdir/aix-glink-3a.so"
184     "" {aix-glink-3.s}
185     {{objdump -d aix-glink-3-SIZE.dd}}
186     "aix-glink-3"}
187
188    {"Line number test 1 (no discards)" "-e.main"
189     "" {aix-lineno-1.s}
190     {{objdump -dS aix-lineno-1a-SIZE.dd} {nm {} aix-lineno-1a-SIZE.nd}}
191     "aix-lineno-1a.exe"}
192
193    {"Line number test 1 (discard locals)" "-e.main -x"
194     "" {aix-lineno-1.s}
195     {{objdump -dS aix-lineno-1b-SIZE.dd} {nm {} aix-lineno-1b-SIZE.nd}}
196     "aix-lineno-1b.exe"}
197
198    {"Relocatable test 1" "-r"
199     "" {aix-rel-1.s}
200     {{objdump -hr aix-rel-1.od}} "aix-rel-1.ro"}
201
202    {".ref test 1" "-efoo1"
203     "" {aix-ref-1.s}
204     {{objdump -dr aix-ref-1-SIZE.od}}
205     "aix-ref-1"}
206
207    {"Weak test 1 (rel)" "-r"
208     "" {aix-weak-1a.s aix-weak-1b.s}
209     {{nm {} aix-weak-1-rel.nd} {objdump -h aix-weak-1-rel.hd}}
210     "aix-weak-1.o"}
211
212    {"Weak test 1 (shared, nogc)" "-shared -bE:aix-weak-1.ex -bnogc"
213     "" {aix-weak-1a.s aix-weak-1b.s}
214     {{nm {} aix-weak-1-dso-SIZE.nd} {objdump -h aix-weak-1-dso-SIZE.hd}
215      {nm -D aix-weak-1-dso-SIZE.dnd}}
216     "aix-weak-1-nogc.so"}
217
218    {"Weak test 1 (shared, gc)" "-shared -bE:aix-weak-1.ex"
219     "" {aix-weak-1a.s aix-weak-1b.s}
220     {{nm {} aix-weak-1-gcdso-SIZE.nd} {objdump -h aix-weak-1-gcdso-SIZE.hd}
221      {nm -D aix-weak-1-gcdso-SIZE.dnd}}
222     "aix-weak-1-gc.so"}
223
224    {"Weak test 2 (library 1)" "-shared -bE:aix-weak-2a.ex"
225     "" {aix-weak-2a.s}
226     {{nm -D aix-weak-2a-SIZE.nd}}
227     "aix-weak-2a.so"}
228
229    {"Weak test 2 (library 2)" "-shared -bE:aix-weak-2a.ex"
230     "" {aix-weak-2b.s}
231     {{nm -D aix-weak-2b-SIZE.nd}}
232     "aix-weak-2b.so"}
233
234    {"Weak test 2 (main library)"
235     "-shared -bE:aix-weak-2c.ex tmpdir/aix-weak-2a.so tmpdir/aix-weak-2b.so"
236     "" {aix-weak-2c.s}
237     {{nm {} aix-weak-2c-SIZE.nd} {objdump {-sj.data -R} aix-weak-2c-SIZE.od}}
238     "aix-weak-2c.so"}
239
240    {"Weak test 3 (library)" "-shared -bE:aix-weak-3a.ex"
241     "" {aix-weak-3a.s}
242     {}
243     "aix-weak-3a.so"}
244
245    {"Weak test 3 (main, dynamic)" "-e.main tmpdir/aix-weak-3a.so"
246     "" {aix-weak-3b.s}
247     {{objdump -Dzrj.data aix-weak-3-SIZE.dd}}
248     "aix-weak-3"}
249
250    {"TOC test 1" "-shared -bE:aix-toc-1.ex"
251     "" {aix-toc-1a.s aix-toc-1b.s}
252     {{objdump -dr aix-toc-1-SIZE.dd}}
253     "aix-toc-1.so"}
254}
255
256foreach test $aix52tests {
257    foreach { name ldopts asopts sources tools output } $test {
258	run_aix_test 32 $name $ldopts $asopts $sources $tools $output
259	run_aix_test 64 $name $ldopts $asopts $sources $tools $output
260    }
261}
262
263run_dump_test "aix-glink-1-32"
264run_dump_test "aix-glink-1-64"
265run_dump_test "aix-glink-3-32"
266run_dump_test "aix-glink-3-64"
267run_dump_test "aix-weak-3-32"
268run_dump_test "aix-weak-3-64"
269