1*56bb7041Schristos# Expect script for ld-weak tests
2*56bb7041Schristos#   Copyright (C) 2001-2020 Free Software Foundation, Inc.
3*56bb7041Schristos#
4*56bb7041Schristos# This file is part of the GNU Binutils.
5*56bb7041Schristos#
6*56bb7041Schristos# This program is free software; you can redistribute it and/or modify
7*56bb7041Schristos# it under the terms of the GNU General Public License as published by
8*56bb7041Schristos# the Free Software Foundation; either version 3 of the License, or
9*56bb7041Schristos# (at your option) any later version.
10*56bb7041Schristos#
11*56bb7041Schristos# This program is distributed in the hope that it will be useful,
12*56bb7041Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
13*56bb7041Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14*56bb7041Schristos# GNU General Public License for more details.
15*56bb7041Schristos#
16*56bb7041Schristos# You should have received a copy of the GNU General Public License
17*56bb7041Schristos# along with this program; if not, write to the Free Software
18*56bb7041Schristos# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19*56bb7041Schristos# MA 02110-1301, USA.
20*56bb7041Schristos#
21*56bb7041Schristos# Written by H.J. Lu (hjl@gnu.org)
22*56bb7041Schristos#	     Eric Youngdale (eric@andante.jic.com)
23*56bb7041Schristos#
24*56bb7041Schristos
25*56bb7041Schristos# Check to see if the C compiler works
26*56bb7041Schristosif { ![check_compiler_available] } {
27*56bb7041Schristos    return
28*56bb7041Schristos}
29*56bb7041Schristos
30*56bb7041Schristos# This test can only be run on a couple of ELF platforms.
31*56bb7041Schristos# Square bracket expressions seem to confuse istarget.
32*56bb7041Schristos# This is similar to the test that is used in ld-shared, BTW.
33*56bb7041Schristosif {    ![istarget alpha*-*-linux*]
34*56bb7041Schristos     && ![istarget arm*-*-linux*]
35*56bb7041Schristos     && ![istarget hppa*64*-*-hpux*]
36*56bb7041Schristos     && ![istarget hppa*-*-linux*]
37*56bb7041Schristos     && ![istarget i?86-*-sysv4*]
38*56bb7041Schristos     && ![istarget i?86-*-unixware]
39*56bb7041Schristos     && ![istarget i?86-*-elf*]
40*56bb7041Schristos     && ![istarget i?86-*-linux*]
41*56bb7041Schristos     && ![istarget i?86-*-gnu*]
42*56bb7041Schristos     && ![istarget ia64-*-elf*]
43*56bb7041Schristos     && ![istarget ia64-*-linux*]
44*56bb7041Schristos     && ![istarget m68k-*-linux*]
45*56bb7041Schristos     && ![istarget mips*-*-irix5*]
46*56bb7041Schristos     && ![istarget mips*-*-linux*]
47*56bb7041Schristos     && ![istarget powerpc*-*-elf*]
48*56bb7041Schristos     && ![istarget powerpc*-*-linux*]
49*56bb7041Schristos     && ![istarget powerpc*-*-sysv4*]
50*56bb7041Schristos     && ![istarget sh\[34\]*-*-linux*]
51*56bb7041Schristos     && ![istarget sparc*-*-elf]
52*56bb7041Schristos     && ![istarget sparc*-*-solaris2*]
53*56bb7041Schristos     && ![istarget sparc*-*-linux*]
54*56bb7041Schristos     && ![istarget x86_64-*-linux*]
55*56bb7041Schristos     && ![istarget *-*-nacl*] } {
56*56bb7041Schristos    return
57*56bb7041Schristos}
58*56bb7041Schristos
59*56bb7041Schristosset diff diff
60*56bb7041Schristosset tmpdir tmpdir
61*56bb7041Schristosset DOBJDUMP_FLAGS --dynamic-syms
62*56bb7041Schristosset SOBJDUMP_FLAGS --syms
63*56bb7041Schristosset shared "--shared -Wl,--no-as-needed"
64*56bb7041Schristos
65*56bb7041Schristos#
66*56bb7041Schristos# objdump_symstuff
67*56bb7041Schristos#	Dump non-dynamic symbol stuff and make sure that it is sane.
68*56bb7041Schristos#
69*56bb7041Schristosproc objdump_symstuff { objdump object expectfile } {
70*56bb7041Schristos    global SOBJDUMP_FLAGS
71*56bb7041Schristos    global version_output
72*56bb7041Schristos    global diff
73*56bb7041Schristos    global tmpdir
74*56bb7041Schristos
75*56bb7041Schristos    if ![info exists SOBJDUMP_FLAGS] { set SOBJDUMP_FLAGS "" }
76*56bb7041Schristos
77*56bb7041Schristos    set cmd "$objdump $SOBJDUMP_FLAGS $object | sed -n {s/^\\(\[0-9a-f\]* *\\)\\(\[gw\]\\)\\( *\\)\\(\[FO\]\\)/\\1\\2\\4\\3/;/foo$/p} > $tmpdir/objdump.out"
78*56bb7041Schristos    verbose -log $cmd
79*56bb7041Schristos    catch "exec $cmd" exec_output
80*56bb7041Schristos    set exec_output [prune_warnings $exec_output]
81*56bb7041Schristos    if [string match "" $exec_output] then {
82*56bb7041Schristos
83*56bb7041Schristos# Now do a line-by-line comparison to effectively diff the darned things
84*56bb7041Schristos# The stuff coming from the expectfile is actually a regex, so we can
85*56bb7041Schristos# skip over the actual addresses and so forth.  This is currently very
86*56bb7041Schristos# simpleminded - it expects a one-to-one correspondence in terms of line
87*56bb7041Schristos# numbers.
88*56bb7041Schristos
89*56bb7041Schristos	if [file exists $expectfile] then {
90*56bb7041Schristos	    set file_a [open $expectfile r]
91*56bb7041Schristos	} else {
92*56bb7041Schristos	    perror "$expectfile doesn't exist"
93*56bb7041Schristos	    return 0
94*56bb7041Schristos	}
95*56bb7041Schristos
96*56bb7041Schristos	if [file exists $tmpdir/objdump.out] then {
97*56bb7041Schristos	    set file_b [open $tmpdir/objdump.out r]
98*56bb7041Schristos	} else {
99*56bb7041Schristos	    perror "$tmpdir/objdump.out doesn't exist"
100*56bb7041Schristos	    return 0
101*56bb7041Schristos	}
102*56bb7041Schristos
103*56bb7041Schristos	verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
104*56bb7041Schristos
105*56bb7041Schristos	set eof -1
106*56bb7041Schristos	set list_a {}
107*56bb7041Schristos	set list_b {}
108*56bb7041Schristos
109*56bb7041Schristos	while { [gets $file_a line] != $eof } {
110*56bb7041Schristos	    if [regexp "^#.*$" $line] then {
111*56bb7041Schristos		continue
112*56bb7041Schristos	    } else {
113*56bb7041Schristos		lappend list_a $line
114*56bb7041Schristos	    }
115*56bb7041Schristos	}
116*56bb7041Schristos	close $file_a
117*56bb7041Schristos
118*56bb7041Schristos	while { [gets $file_b line] != $eof } {
119*56bb7041Schristos	    if [regexp {\.text.* \.[^ ]*$} $line] then {
120*56bb7041Schristos		# Discard defined powerpc64 dot-symbols
121*56bb7041Schristos		continue
122*56bb7041Schristos	    } else {
123*56bb7041Schristos		lappend list_b $line
124*56bb7041Schristos	    }
125*56bb7041Schristos	}
126*56bb7041Schristos	close $file_b
127*56bb7041Schristos
128*56bb7041Schristos	for { set i 0 } { $i < [llength $list_a] } { incr i } {
129*56bb7041Schristos	    set line_a [lindex $list_a $i]
130*56bb7041Schristos	    set line_b [lindex $list_b $i]
131*56bb7041Schristos
132*56bb7041Schristos	    verbose "\t$expectfile: $i: $line_a" 3
133*56bb7041Schristos	    verbose "\t/tmp/objdump.out: $i: $line_b" 3
134*56bb7041Schristos	    if [regexp $line_a $line_b] then {
135*56bb7041Schristos		continue
136*56bb7041Schristos	    } else {
137*56bb7041Schristos		verbose -log "\t$expectfile: $i: $line_a"
138*56bb7041Schristos		verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
139*56bb7041Schristos
140*56bb7041Schristos		return 0
141*56bb7041Schristos	    }
142*56bb7041Schristos	}
143*56bb7041Schristos
144*56bb7041Schristos	if { [llength $list_a] != [llength $list_b] } {
145*56bb7041Schristos	    verbose -log "Line count"
146*56bb7041Schristos	    return 0
147*56bb7041Schristos	}
148*56bb7041Schristos	return 1
149*56bb7041Schristos
150*56bb7041Schristos    } else {
151*56bb7041Schristos	verbose -log "$exec_output"
152*56bb7041Schristos	return 0
153*56bb7041Schristos    }
154*56bb7041Schristos}
155*56bb7041Schristos
156*56bb7041Schristos#
157*56bb7041Schristos# objdump_dymsymstuff
158*56bb7041Schristos#	Dump dynamic symbol stuff and make sure that it is sane.
159*56bb7041Schristos#
160*56bb7041Schristosproc objdump_dynsymstuff { objdump object expectfile } {
161*56bb7041Schristos    global DOBJDUMP_FLAGS
162*56bb7041Schristos    global version_output
163*56bb7041Schristos    global diff
164*56bb7041Schristos    global tmpdir
165*56bb7041Schristos
166*56bb7041Schristos    if ![info exists DOBJDUMP_FLAGS] { set DOBJDUMP_FLAGS "" }
167*56bb7041Schristos
168*56bb7041Schristos    set cmd "$objdump $DOBJDUMP_FLAGS $object | grep foo$ > $tmpdir/objdump.out"
169*56bb7041Schristos    verbose -log $cmd
170*56bb7041Schristos    catch "exec $cmd" exec_output
171*56bb7041Schristos    set exec_output [prune_warnings $exec_output]
172*56bb7041Schristos    if [string match "" $exec_output] then {
173*56bb7041Schristos
174*56bb7041Schristos# Now do a line-by-line comparison to effectively diff the darned things
175*56bb7041Schristos# The stuff coming from the expectfile is actually a regex, so we can
176*56bb7041Schristos# skip over the actual addresses and so forth.  This is currently very
177*56bb7041Schristos# simpleminded - it expects a one-to-one correspondence in terms of line
178*56bb7041Schristos# numbers.
179*56bb7041Schristos
180*56bb7041Schristos	if [file exists $expectfile] then {
181*56bb7041Schristos	    set file_a [open $expectfile r]
182*56bb7041Schristos	} else {
183*56bb7041Schristos	    warning "$expectfile doesn't exist"
184*56bb7041Schristos	    return 0
185*56bb7041Schristos	}
186*56bb7041Schristos
187*56bb7041Schristos	if [file exists $tmpdir/objdump.out] then {
188*56bb7041Schristos	    set file_b [open $tmpdir/objdump.out r]
189*56bb7041Schristos	} else {
190*56bb7041Schristos	    fail "$tmpdir/objdump.out doesn't exist"
191*56bb7041Schristos	    return 0
192*56bb7041Schristos	}
193*56bb7041Schristos
194*56bb7041Schristos	verbose "# Diff'ing: $expectfile $tmpdir/objdump.out" 2
195*56bb7041Schristos
196*56bb7041Schristos	set eof -1
197*56bb7041Schristos	set list_a {}
198*56bb7041Schristos	set list_b {}
199*56bb7041Schristos
200*56bb7041Schristos	while { [gets $file_a line] != $eof } {
201*56bb7041Schristos	    if [regexp "^#.*$" $line] then {
202*56bb7041Schristos		continue
203*56bb7041Schristos	    } else {
204*56bb7041Schristos		lappend list_a $line
205*56bb7041Schristos	    }
206*56bb7041Schristos	}
207*56bb7041Schristos	close $file_a
208*56bb7041Schristos
209*56bb7041Schristos	while { [gets $file_b line] != $eof } {
210*56bb7041Schristos	    if [regexp {\.text.* \.[^ ]*$} $line] then {
211*56bb7041Schristos		# Discard defined powerpc64 dot-symbols
212*56bb7041Schristos		continue
213*56bb7041Schristos	    } else {
214*56bb7041Schristos		lappend list_b $line
215*56bb7041Schristos	    }
216*56bb7041Schristos	}
217*56bb7041Schristos	close $file_b
218*56bb7041Schristos
219*56bb7041Schristos	for { set i 0 } { $i < [llength $list_b] } { incr i } {
220*56bb7041Schristos	    set line_b [lindex $list_b $i]
221*56bb7041Schristos
222*56bb7041Schristos# The tests are rigged so that we should never export a symbol with the
223*56bb7041Schristos# word 'hide' in it.  Thus we just search for it, and bail if we find it.
224*56bb7041Schristos	    if [regexp "hide" $line_b] then {
225*56bb7041Schristos		verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
226*56bb7041Schristos
227*56bb7041Schristos		return 0
228*56bb7041Schristos	    }
229*56bb7041Schristos
230*56bb7041Schristos	    verbose "\t$expectfile: $i: $line_b" 3
231*56bb7041Schristos
232*56bb7041Schristos	    # We can't assume that the sort is consistent across
233*56bb7041Schristos	    # systems, so we must check each regexp.  When we find a
234*56bb7041Schristos	    # regexp, we null it out, so we don't match it twice.
235*56bb7041Schristos	    for { set j 0 } { $j < [llength $list_a] } { incr j } {
236*56bb7041Schristos		set line_a [lindex $list_a $j]
237*56bb7041Schristos
238*56bb7041Schristos		if [regexp $line_a $line_b] then {
239*56bb7041Schristos		    lreplace $list_a $j $j "CAN NOT MATCH"
240*56bb7041Schristos		    break
241*56bb7041Schristos		}
242*56bb7041Schristos	    }
243*56bb7041Schristos
244*56bb7041Schristos	    if { $j >= [llength $list_a] } {
245*56bb7041Schristos		verbose -log "\t$tmpdir/objdump.out: $i: $line_b"
246*56bb7041Schristos
247*56bb7041Schristos		return 0
248*56bb7041Schristos	    }
249*56bb7041Schristos	}
250*56bb7041Schristos
251*56bb7041Schristos	if { [llength $list_a] != [llength $list_b] } {
252*56bb7041Schristos	    verbose -log "Line count"
253*56bb7041Schristos	    return 0
254*56bb7041Schristos	}
255*56bb7041Schristos	return 1
256*56bb7041Schristos
257*56bb7041Schristos    } else {
258*56bb7041Schristos	verbose -log "$exec_output"
259*56bb7041Schristos	return 0
260*56bb7041Schristos    }
261*56bb7041Schristos}
262*56bb7041Schristos
263*56bb7041Schristosproc build_lib {test libname objs dynsymexp} {
264*56bb7041Schristos    global CC
265*56bb7041Schristos    global objdump
266*56bb7041Schristos    global tmpdir
267*56bb7041Schristos    global shared
268*56bb7041Schristos    global srcdir
269*56bb7041Schristos    global subdir
270*56bb7041Schristos    global NOSANITIZE_CFLAGS
271*56bb7041Schristos
272*56bb7041Schristos    set files ""
273*56bb7041Schristos    foreach obj $objs {
274*56bb7041Schristos      set files "$files $tmpdir/$obj"
275*56bb7041Schristos    }
276*56bb7041Schristos
277*56bb7041Schristos    if {![ld_link "$CC $NOSANITIZE_CFLAGS" $tmpdir/$libname.so "$shared $files"]} {
278*56bb7041Schristos	fail $test
279*56bb7041Schristos	return
280*56bb7041Schristos    }
281*56bb7041Schristos
282*56bb7041Schristos    if {![string match "" $dynsymexp]
283*56bb7041Schristos	&& ![objdump_dynsymstuff $objdump $tmpdir/$libname.so $srcdir/$subdir/$dynsymexp]} {
284*56bb7041Schristos	fail $test
285*56bb7041Schristos	return
286*56bb7041Schristos    }
287*56bb7041Schristos    pass $test
288*56bb7041Schristos}
289*56bb7041Schristos
290*56bb7041Schristosproc build_exec { test execname objs flags dat dynsymexp symexp} {
291*56bb7041Schristos    global CC
292*56bb7041Schristos    global objdump
293*56bb7041Schristos    global tmpdir
294*56bb7041Schristos    global srcdir
295*56bb7041Schristos    global subdir
296*56bb7041Schristos    global exec_output
297*56bb7041Schristos    global NOSANITIZE_CFLAGS
298*56bb7041Schristos
299*56bb7041Schristos    set files ""
300*56bb7041Schristos    foreach obj $objs {
301*56bb7041Schristos      set files "$files $tmpdir/$obj"
302*56bb7041Schristos    }
303*56bb7041Schristos
304*56bb7041Schristos    if {![ld_link $CC $tmpdir/$execname "$flags $NOSANITIZE_CFLAGS $files"]} {
305*56bb7041Schristos	fail "$test"
306*56bb7041Schristos	return
307*56bb7041Schristos    }
308*56bb7041Schristos
309*56bb7041Schristos    if {![string match "" $dynsymexp]} then {
310*56bb7041Schristos        if {![objdump_dynsymstuff $objdump $tmpdir/$execname $srcdir/$subdir/$dynsymexp]} {
311*56bb7041Schristos	    fail $test
312*56bb7041Schristos	    return
313*56bb7041Schristos	}
314*56bb7041Schristos    }
315*56bb7041Schristos
316*56bb7041Schristos    if {![string match "" $symexp]} then {
317*56bb7041Schristos        if {![objdump_symstuff $objdump $tmpdir/$execname $srcdir/$subdir/$symexp]} {
318*56bb7041Schristos	    fail $test
319*56bb7041Schristos	    return
320*56bb7041Schristos	}
321*56bb7041Schristos    }
322*56bb7041Schristos
323*56bb7041Schristos    if ![isnative] {
324*56bb7041Schristos	unsupported $test
325*56bb7041Schristos	return
326*56bb7041Schristos    }
327*56bb7041Schristos    # Run the resulting program
328*56bb7041Schristos    send_log "$tmpdir/$execname >$tmpdir/$execname.out\n"
329*56bb7041Schristos    verbose "$tmpdir/$execname >$tmpdir/$execname.out"
330*56bb7041Schristos    catch "exec $tmpdir/$execname >$tmpdir/$execname.out" exec_output
331*56bb7041Schristos    if ![string match "" $exec_output] then {
332*56bb7041Schristos	send_log "$exec_output\n"
333*56bb7041Schristos	verbose "$exec_output"
334*56bb7041Schristos	fail $test
335*56bb7041Schristos	return
336*56bb7041Schristos    }
337*56bb7041Schristos
338*56bb7041Schristos    send_log "diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat\n"
339*56bb7041Schristos    verbose "diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat"
340*56bb7041Schristos    catch "exec diff $tmpdir/$execname.out $srcdir/$subdir/$dat.dat" exec_output
341*56bb7041Schristos    set exec_output [prune_warnings $exec_output]
342*56bb7041Schristos
343*56bb7041Schristos    if {![string match "" $exec_output]} then {
344*56bb7041Schristos	send_log "$exec_output\n"
345*56bb7041Schristos	verbose "$exec_output"
346*56bb7041Schristos	fail $test
347*56bb7041Schristos        return
348*56bb7041Schristos    }
349*56bb7041Schristos
350*56bb7041Schristos    pass $test
351*56bb7041Schristos}
352*56bb7041Schristos
353*56bb7041Schristos# Disable LTO for these tests.
354*56bb7041Schristosset cc_cmd "$CC"
355*56bb7041Schristosif {[check_lto_available]} {
356*56bb7041Schristos   append cc_cmd " -fno-lto"
357*56bb7041Schristos}
358*56bb7041Schristos
359*56bb7041Schristos# Disable all sanitizers.
360*56bb7041Schristosappend cc_cmd " $NOSANITIZE_CFLAGS"
361*56bb7041Schristos
362*56bb7041Schristos# Old version of GCC for MIPS default to enabling -fpic
363*56bb7041Schristos# and get confused if it is used on the command line.
364*56bb7041Schristosif { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then {
365*56bb7041Schristos    set picflag ""
366*56bb7041Schristos} else {
367*56bb7041Schristos    # Unfortunately, the gcc argument is -fpic and the cc argument is
368*56bb7041Schristos    # -KPIC.  We have to try both.
369*56bb7041Schristos    set picflag "-fpic"
370*56bb7041Schristos    send_log "$CC $picflag\n"
371*56bb7041Schristos    verbose "$CC $picflag"
372*56bb7041Schristos    catch "exec $CC $picflag" exec_output
373*56bb7041Schristos    send_log "$exec_output\n"
374*56bb7041Schristos    verbose "--" "$exec_output"
375*56bb7041Schristos    if { [string match "*illegal option*" $exec_output]
376*56bb7041Schristos	 || [string match "*option ignored*" $exec_output]
377*56bb7041Schristos	 || [string match "*unrecognized option*" $exec_output]
378*56bb7041Schristos	 || [string match "*passed to ld*" $exec_output] } {
379*56bb7041Schristos	set picflag "-KPIC"
380*56bb7041Schristos    }
381*56bb7041Schristos}
382*56bb7041Schristosverbose "Using $picflag to compile PIC code"
383*56bb7041Schristos
384*56bb7041Schristosif {![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/foo.c $tmpdir/foo.o]
385*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/bar.c $tmpdir/bar.o]
386*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS" $srcdir/$subdir/main.c $tmpdir/main.o]
387*56bb7041Schristos    || ![ld_link $cc_cmd $tmpdir/libbar.so "$shared $tmpdir/bar.o"]
388*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/foo1a.c $tmpdir/foo1a.o]
389*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/foo1b.c $tmpdir/foo1b.o]
390*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/bar1a.c $tmpdir/bar1a.o]
391*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/bar1b.c $tmpdir/bar1b.o]
392*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/bar1c.c $tmpdir/bar1c.o]
393*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/main1.c $tmpdir/main1.o]} then {
394*56bb7041Schristos    unresolved "ELF weak"
395*56bb7041Schristos} elseif {![ld_link $cc_cmd $tmpdir/libfoo1a.so "$shared $tmpdir/foo1a.o"]
396*56bb7041Schristos	  || ![ld_link $cc_cmd $tmpdir/libfoo1b.so "$shared $tmpdir/foo1b.o"]
397*56bb7041Schristos	  || ![ld_link $cc_cmd $tmpdir/libbar1a.so "$shared $tmpdir/bar1a.o $tmpdir/libfoo1a.so"]} then {
398*56bb7041Schristos    fail "ELF weak"
399*56bb7041Schristos} else {
400*56bb7041Schristos    build_lib "ELF DSO weak func first" libfoo "foo.o bar.o" dso.dsym
401*56bb7041Schristos    build_lib "ELF DSO weak func last" libfoo "bar.o foo.o" dso.dsym
402*56bb7041Schristos    build_lib "ELF DSO weak func first DSO" libfoo "foo.o libbar.so" dsow.dsym
403*56bb7041Schristos    build_lib "ELF DSO weak func last DSO" libfoo "libbar.so foo.o" dsow.dsym
404*56bb7041Schristos    build_exec "ELF weak func first" foo "main.o bar.o" "" strong "" strong.sym
405*56bb7041Schristos    build_exec "ELF weak func last" foo "bar.o main.o" "" strong "" strong.sym
406*56bb7041Schristos    build_exec "ELF weak func first DSO" foo "main.o libbar.so" "-Wl,-rpath,.,--no-as-needed" weak weak.dsym ""
407*56bb7041Schristos    build_exec "ELF weak func last DSO" foo "libbar.so main.o" "-Wl,-rpath,.,--no-as-needed" weak weak.dsym ""
408*56bb7041Schristos    build_lib "ELF DSO weak data first" libfoo "bar1a.o foo1a.o" dsodata.dsym
409*56bb7041Schristos    build_lib "ELF DSO weak data last" libfoo "foo1a.o bar1a.o" dsodata.dsym
410*56bb7041Schristos    build_lib "ELF DSO weak data first DSO" libfoo "main1.o libfoo1a.so" dsowdata.dsym
411*56bb7041Schristos    build_lib "ELF DSO weak data last DSO" libfoo "libfoo1a.so main1.o" dsowdata.dsym
412*56bb7041Schristos    build_lib "ELF DSO weak data first DSO common" libfoo "main1.o libfoo1b.so" dsowdata.dsym
413*56bb7041Schristos    build_lib "ELF DSO weak data last DSO common" libfoo "libfoo1b.so main1.o" dsowdata.dsym
414*56bb7041Schristos    build_exec "ELF weak data first" foo "main1.o bar1a.o foo1a.o" "" strongdata "" strongdata.sym
415*56bb7041Schristos    build_exec "ELF weak data last" foo "foo1a.o main1.o bar1a.o" "" strongdata "" strongdata.sym
416*56bb7041Schristos    build_exec "ELF weak data first common" foo "main1.o bar1a.o foo1b.o" "" strongdata "" strongcomm.sym
417*56bb7041Schristos    build_exec "ELF weak data last common" foo "foo1b.o main1.o bar1a.o" "" strongdata "" strongcomm.sym
418*56bb7041Schristos    build_exec "ELF weak data first DSO" foo "main1.o libbar1a.so libfoo1a.so" "-Wl,-rpath,.,--no-as-needed" weakdata weakdata.dsym ""
419*56bb7041Schristos    build_exec "ELF weak data last DSO" foo "libfoo1a.so main1.o libbar1a.so" "-Wl,-rpath,.,--no-as-needed" weakdata weakdata.dsym ""
420*56bb7041Schristos    build_exec "ELF weak data first DSO common" foo "main1.o libbar1a.so libfoo1b.so" "-Wl,--no-as-needed,-rpath,.,-rpath-link,." weakdata weakdata.dsym ""
421*56bb7041Schristos    build_exec "ELF weak data last DSO common" foo "libfoo1b.so main1.o libbar1a.so" "-Wl,--no-as-needed,-rpath,.,-rpath-link,." weakdata weakdata.dsym ""
422*56bb7041Schristos}
423*56bb7041Schristos
424*56bb7041Schristosif {![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/size_foo.c $tmpdir/size_foo.o]
425*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/size_bar.c $tmpdir/size_bar_s.o]
426*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $picflag -DSIZE_BIG" $srcdir/$subdir/size_bar.c $tmpdir/size_bar.o]
427*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS" $srcdir/$subdir/size_main.c $tmpdir/size_main.o]} then {
428*56bb7041Schristos    unresolved "ELF weak (size)"
429*56bb7041Schristos} else {
430*56bb7041Schristos    build_lib "ELF DSO small bar (size)" libsize_bar_s "size_bar_s.o" ""
431*56bb7041Schristos    build_lib "ELF DSO foo with small bar (size)" libsize_foo "size_foo.o libsize_bar_s.so" ""
432*56bb7041Schristos    build_lib "ELF DSO big bar (size)" libsize_bar "size_bar.o" ""
433*56bb7041Schristos    build_exec "ELF weak size" size_main "size_main.o libsize_foo.so libsize_bar.so" "-Wl,-rpath=.,-rpath-link=.,--no-as-needed" size "" ""
434*56bb7041Schristos}
435*56bb7041Schristos
436*56bb7041Schristosverbose "size2"
437*56bb7041Schristosrun_dump_test $srcdir/$subdir/size2
438*56bb7041Schristos
439*56bb7041Schristosif {![ld_compile "$cc_cmd $CFLAGS $picflag" $srcdir/$subdir/alias.c $tmpdir/alias.o]
440*56bb7041Schristos    || ![ld_link $cc_cmd $tmpdir/alias.so "$shared $tmpdir/alias.o"]
441*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS $NOSANITIZE_CFLAGS" $srcdir/$subdir/aliasmain.c $tmpdir/aliasmain.o]
442*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS" $srcdir/$subdir/weakref1.c $tmpdir/weakref1.o]
443*56bb7041Schristos    || ![ld_compile "$cc_cmd $CFLAGS" $srcdir/$subdir/weakref2.c $tmpdir/weakref2.o]} then {
444*56bb7041Schristos    unresolved "ELF weak (alias)"
445*56bb7041Schristos} else {
446*56bb7041Schristos    build_exec "ELF weak (alias)" alias "aliasmain.o weakref1.o weakref2.o alias.so" "-Wl,-rpath=.,--no-as-needed" alias "" ""
447*56bb7041Schristos}
448