1*56bb7041Schristos# Expect script for symbol export classes, MIPS variation.
2*56bb7041Schristos#
3*56bb7041Schristos# Copyright (C) 2012-2020 Free Software Foundation, Inc.
4*56bb7041Schristos#
5*56bb7041Schristos# This file is part of the GNU Binutils.
6*56bb7041Schristos#
7*56bb7041Schristos# This program is free software; you can redistribute it and/or modify
8*56bb7041Schristos# it under the terms of the GNU General Public License as published by
9*56bb7041Schristos# the Free Software Foundation; either version 3 of the License, or
10*56bb7041Schristos# (at your option) any later version.
11*56bb7041Schristos#
12*56bb7041Schristos# This program is distributed in the hope that it will be useful,
13*56bb7041Schristos# but WITHOUT ANY WARRANTY; without even the implied warranty of
14*56bb7041Schristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*56bb7041Schristos# GNU General Public License for more details.
16*56bb7041Schristos#
17*56bb7041Schristos# You should have received a copy of the GNU General Public License
18*56bb7041Schristos# along with this program; if not, write to the Free Software
19*56bb7041Schristos# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20*56bb7041Schristos# MA 02110-1301, USA.
21*56bb7041Schristos#
22*56bb7041Schristos
23*56bb7041Schristos#
24*56bb7041Schristos# Written by Maciej W. Rozycki <macro@codesourcery.com>
25*56bb7041Schristos#
26*56bb7041Schristos
27*56bb7041Schristos# Exclude non-Linux targets; feel free to include your favorite one
28*56bb7041Schristos# if you like.
29*56bb7041Schristosif { ![istarget mips*-*-linux*] } {
30*56bb7041Schristos    return
31*56bb7041Schristos}
32*56bb7041Schristos
33*56bb7041Schristosproc mips_export_class_test { abi flag emul } {
34*56bb7041Schristos
35*56bb7041Schristos    set testname "MIPS $abi symbol export class test"
36*56bb7041Schristos
37*56bb7041Schristos    set dump [string map {o32 32 n32 32 n64 64} $abi]
38*56bb7041Schristos
39*56bb7041Schristos    set AFLAGS "$flag -EB"
40*56bb7041Schristos    set LDFLAGS "-m$emul"
41*56bb7041Schristos
42*56bb7041Schristos    # Build an auxiliary shared object with conflicting versioned symbol
43*56bb7041Schristos    # definitions.
44*56bb7041Schristos    run_ld_link_tests [list \
45*56bb7041Schristos	[list \
46*56bb7041Schristos	    "$testname (auxiliary shared object)" \
47*56bb7041Schristos	    "$LDFLAGS -shared -version-script ../ld-elf/export-class-lib.ver" "" \
48*56bb7041Schristos	    "$AFLAGS" \
49*56bb7041Schristos	    { ../ld-elf/export-class-lib.s } \
50*56bb7041Schristos	    {} \
51*56bb7041Schristos	    "mips-$abi-export-class-lib.so" \
52*56bb7041Schristos	] \
53*56bb7041Schristos    ]
54*56bb7041Schristos
55*56bb7041Schristos    # Build a static object that pulls symbol definitions.  It has to come
56*56bb7041Schristos    # first before the auxiliary shared object and other static objects on
57*56bb7041Schristos    # the linker's command line and hence we need to build it separately.
58*56bb7041Schristos    run_ld_link_tests [list \
59*56bb7041Schristos	[list \
60*56bb7041Schristos	    "$testname (initial static object)" \
61*56bb7041Schristos	    "$LDFLAGS -r" "" \
62*56bb7041Schristos	    "$AFLAGS" \
63*56bb7041Schristos	    { ../ld-elf/export-class-ref.s } \
64*56bb7041Schristos	    {} \
65*56bb7041Schristos	    "mips-$abi-export-class-ref-r.o" \
66*56bb7041Schristos	] \
67*56bb7041Schristos    ]
68*56bb7041Schristos
69*56bb7041Schristos    # Build static objects that satisfy symbol dependencies and preempt
70*56bb7041Schristos    # shared-object symbol definitions, and link all the objects built into
71*56bb7041Schristos    # the final shared object.  The command-line order of objects linked is
72*56bb7041Schristos    # important to make sure the linker correctly preempts versioned symbols
73*56bb7041Schristos    # from the auxiliary shared object and is as follows: ref, lib, dep, def.
74*56bb7041Schristos    # Get a dump to make sure symbol dependencies are resolved internally.
75*56bb7041Schristos    run_ld_link_tests [list \
76*56bb7041Schristos	[list \
77*56bb7041Schristos	    "$testname (final shared object)" \
78*56bb7041Schristos	    "$LDFLAGS -shared -Tdata=0x12340000 tmpdir/mips-$abi-export-class-ref-r.o tmpdir/mips-$abi-export-class-lib.so" "" \
79*56bb7041Schristos	    "$AFLAGS" \
80*56bb7041Schristos	    { ../ld-elf/export-class-dep.s ../ld-elf/export-class-def.s } \
81*56bb7041Schristos	    [list \
82*56bb7041Schristos		[list readelf -r mips-$dump-export-class.rd] \
83*56bb7041Schristos		[list readelf "-x .data" mips-$dump-export-class.xd] \
84*56bb7041Schristos	    ] \
85*56bb7041Schristos	    "mips-$abi-export-class.so" \
86*56bb7041Schristos	] \
87*56bb7041Schristos    ]
88*56bb7041Schristos}
89*56bb7041Schristos
90*56bb7041Schristos# For targets that default to a specific ISA (instead of "from-abi"),
91*56bb7041Schristos# the 64-bit -march option is required to override it, like for
92*56bb7041Schristos# "mipsisa32r2el-*-*".
93*56bb7041Schristosset abis { o32 -32 elf32btsmip n32 "-n32 -march=mips3" elf32btsmipn32 n64 "-64 -march=mips3" elf64btsmip }
94*56bb7041Schristosforeach { abi flag emul } $abis {
95*56bb7041Schristos    mips_export_class_test $abi $flag $emul
96*56bb7041Schristos}
97