1 # Expect script for RISC-V ELF linker tests
2 # Copyright (C) 2017-2021 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 proc riscv_choose_ilp32_emul {} {
23 if { [istarget "riscvbe-*"] \
24 || [istarget "riscv32be-*"] \
25 || [istarget "riscv64be-*"] } {
31 proc riscv_choose_lp64_emul {} {
32 if { [istarget "riscvbe-*"] \
33 || [istarget "riscv32be-*"] \
34 || [istarget "riscv64be-*"] } {
40 # target: rv32 or rv64.
41 # output: Which output you want? (exe, pie, .so)
42 proc run_dump_test_ifunc { name target output} {
44 set ldflags "-z nocombreloc"
52 set ldflags "$ldflags -pie"
56 set ldflags "$ldflags -shared"
62 set asflags "$asflags -march=rv32i -mabi=ilp32"
63 set ldflags "$ldflags -m[riscv_choose_ilp32_emul]"
66 set asflags "$asflags -march=rv64i -mabi=lp64 -defsym __64_bit__=1"
67 set ldflags "$ldflags -m[riscv_choose_lp64_emul]"
71 run_ld_link_tests [list \
72 [list "$name ($target-$output)" \
76 [concat [list "readelf -rW $name-$output.rd"] \
77 [list "objdump -dw $name.d"]] \
78 "$name-$target.$ext"]]
81 if [istarget "riscv*-*-*"] {
82 run_dump_test "call-relax"
83 run_dump_test "pcgp-relax"
85 run_dump_test "c-lui-2"
86 run_dump_test "disas-jalr"
87 run_dump_test "pcrel-lo-addend"
88 run_dump_test "pcrel-lo-addend-2a"
89 run_dump_test "pcrel-lo-addend-2b"
90 run_dump_test "pcrel-lo-addend-3a"
91 run_dump_test "pcrel-lo-addend-3b"
92 run_dump_test "pcrel-lo-addend-3c"
93 run_dump_test "restart-relax"
94 run_dump_test "attr-merge-arch-01"
95 run_dump_test "attr-merge-arch-02"
96 run_dump_test "attr-merge-arch-03"
97 run_dump_test "attr-merge-strict-align-01"
98 run_dump_test "attr-merge-strict-align-02"
99 run_dump_test "attr-merge-strict-align-03"
100 run_dump_test "attr-merge-strict-align-04"
101 run_dump_test "attr-merge-strict-align-05"
102 run_dump_test "attr-merge-stack-align"
103 run_dump_test "attr-merge-priv-spec-01"
104 run_dump_test "attr-merge-priv-spec-02"
105 run_dump_test "attr-merge-priv-spec-03"
106 run_dump_test "attr-merge-arch-failed-01"
107 run_dump_test "attr-merge-arch-failed-02"
108 run_dump_test "attr-merge-stack-align-failed"
109 run_dump_test "attr-merge-priv-spec-failed-01"
110 run_dump_test "attr-merge-priv-spec-failed-02"
111 run_dump_test "attr-merge-priv-spec-failed-03"
112 run_dump_test "attr-merge-priv-spec-failed-04"
113 run_dump_test "attr-merge-priv-spec-failed-05"
114 run_dump_test "attr-merge-priv-spec-failed-06"
115 run_ld_link_tests [list \
116 [list "Weak reference 32" "-T weakref.ld -m[riscv_choose_ilp32_emul]" "" \
117 "-march=rv32i -mabi=ilp32" {weakref32.s} \
118 {{objdump -d weakref32.d}} "weakref32"] \
119 [list "Weak reference 64" "-T weakref.ld -m[riscv_choose_lp64_emul]" "" \
120 "-march=rv64i -mabi=lp64" {weakref64.s} \
121 {{objdump -d weakref64.d}} "weakref64"]]
123 # The following tests require shared library support.
124 if ![check_shared_lib_support] {
128 run_dump_test "relro-relax-lui"
129 run_dump_test "relro-relax-pcrel"
131 set abis [list rv32gc ilp32 [riscv_choose_ilp32_emul] rv64gc lp64 [riscv_choose_lp64_emul]]
132 foreach { arch abi emul } $abis {
133 # This checks whether our linker scripts handle __global_pointer$
134 # correctly. It should be defined in executables and PIE, but not
135 # in shared libraries.
136 set suff64 [string map {ilp32 "" lp64 -64} $abi]
137 run_ld_link_tests [list \
138 [list "gp test ($abi shared library)" \
139 "-m$emul -shared" "" \
140 "-march=$arch -mabi=$abi -fpic" \
142 [list "readelf --syms gp-test-lib.sd"] \
143 "gp-test-lib-${abi}.so"] \
144 [list "gp test ($abi executable)" \
146 "-march=$arch -mabi=$abi" \
148 [list "readelf --syms gp-test.sd"] \
153 { "Link non-pic code into a shared library (setup)"
154 "-shared" "" "" {lib-nopic-01a.s}
155 {} "lib-nopic-01a.so" }
157 run_dump_test "lib-nopic-01b"
160 # Check IFUNC by single type relocs.
161 run_dump_test_ifunc "ifunc-reloc-call-01" rv32 exe
162 run_dump_test_ifunc "ifunc-reloc-call-01" rv32 pie
163 run_dump_test_ifunc "ifunc-reloc-call-01" rv32 pic
164 run_dump_test_ifunc "ifunc-reloc-call-02" rv32 exe
165 run_dump_test_ifunc "ifunc-reloc-call-02" rv32 pie
166 run_dump_test_ifunc "ifunc-reloc-call-02" rv32 pic
167 run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 exe
168 run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 pie
169 run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 pic
170 run_dump_test_ifunc "ifunc-reloc-data" rv32 exe
171 run_dump_test_ifunc "ifunc-reloc-data" rv32 pie
172 run_dump_test_ifunc "ifunc-reloc-data" rv32 pic
173 run_dump_test_ifunc "ifunc-reloc-got" rv32 exe
174 run_dump_test_ifunc "ifunc-reloc-got" rv32 pie
175 run_dump_test_ifunc "ifunc-reloc-got" rv32 pic
176 run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 exe
177 run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 pie
178 run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 pic
179 run_dump_test_ifunc "ifunc-reloc-data" rv64 exe
180 run_dump_test_ifunc "ifunc-reloc-data" rv64 pie
181 run_dump_test_ifunc "ifunc-reloc-data" rv64 pic
182 run_dump_test_ifunc "ifunc-reloc-got" rv64 exe
183 run_dump_test_ifunc "ifunc-reloc-got" rv64 pie
184 run_dump_test_ifunc "ifunc-reloc-got" rv64 pic
185 # Check the IFUNC PLT and non-PLT relocs.
186 run_dump_test_ifunc "ifunc-nonplt" rv32 exe
187 run_dump_test_ifunc "ifunc-nonplt" rv32 pie
188 run_dump_test_ifunc "ifunc-nonplt" rv32 pic
189 run_dump_test_ifunc "ifunc-plt-01" rv32 exe
190 run_dump_test_ifunc "ifunc-plt-01" rv32 pie
191 run_dump_test_ifunc "ifunc-plt-01" rv32 pic
192 run_dump_test_ifunc "ifunc-plt-02" rv32 exe
193 run_dump_test_ifunc "ifunc-plt-02" rv32 pie
194 run_dump_test_ifunc "ifunc-plt-02" rv32 pic
195 run_dump_test_ifunc "ifunc-nonplt" rv64 exe
196 run_dump_test_ifunc "ifunc-nonplt" rv64 pie
197 run_dump_test_ifunc "ifunc-nonplt" rv64 pic
198 run_dump_test_ifunc "ifunc-plt-01" rv64 exe
199 run_dump_test_ifunc "ifunc-plt-01" rv64 pie
200 run_dump_test_ifunc "ifunc-plt-01" rv64 pic
201 run_dump_test_ifunc "ifunc-plt-02" rv64 exe
202 run_dump_test_ifunc "ifunc-plt-02" rv64 pie
203 run_dump_test_ifunc "ifunc-plt-02" rv64 pic
204 # Check the .rela.iplt overwrite issue.
205 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 exe
206 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 pie
207 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 pic
208 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 exe
209 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 pie
210 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 pic
212 # Setup shared libraries.
214 { "Build shared library for IFUNC non-PLT caller"
215 "-shared" "" "" {ifunc-seperate-caller-nonplt.s}
216 {} "ifunc-seperate-caller.so" }
217 { "Build shared library for IFUNC PLT caller"
218 "-shared" "" "" {ifunc-seperate-caller-plt.s}
219 {} "ifunc-seperate-caller.so" }
220 { "Build shared library for IFUNC resolver"
221 "-shared" "" "" {ifunc-seperate-resolver.s}
222 {} "ifunc-seperate-resolver.so" }
224 # The IFUNC resolver and caller are in the seperate modules.
225 # If IFUNC resolver and caller are linked to the same module,
226 # then the result are the same as the run_dump_test_ifunc.
227 run_dump_test "ifunc-seperate-nonplt-exe"
228 run_dump_test "ifunc-seperate-nonplt-pie"
229 run_dump_test "ifunc-seperate-nonplt-pic"
230 run_dump_test "ifunc-seperate-plt-exe"
231 run_dump_test "ifunc-seperate-plt-pie"
232 run_dump_test "ifunc-seperate-plt-pic"
233 run_dump_test "ifunc-seperate-pcrel-pie"
234 run_dump_test "ifunc-seperate-pcrel-pic"