]>
Commit | Line | Data |
---|---|---|
3342be5d | 1 | # Expect script for RISC-V ELF linker tests |
250d07de | 2 | # Copyright (C) 2017-2021 Free Software Foundation, Inc. |
3342be5d AW |
3 | # |
4 | # This file is part of the GNU Binutils. | |
5 | # | |
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. | |
10 | # | |
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. | |
15 | # | |
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, | |
19 | # MA 02110-1301, USA. | |
20 | # | |
21 | ||
f36ce378 MC |
22 | proc riscv_choose_ilp32_emul {} { |
23 | if { [istarget "riscvbe-*"] \ | |
24 | || [istarget "riscv32be-*"] \ | |
25 | || [istarget "riscv64be-*"] } { | |
26 | return "elf32briscv" | |
27 | } | |
28 | return "elf32lriscv" | |
29 | } | |
30 | ||
31 | proc riscv_choose_lp64_emul {} { | |
32 | if { [istarget "riscvbe-*"] \ | |
33 | || [istarget "riscv32be-*"] \ | |
34 | || [istarget "riscv64be-*"] } { | |
35 | return "elf64briscv" | |
36 | } | |
37 | return "elf64lriscv" | |
38 | } | |
39 | ||
02dd9d25 NC |
40 | # target: rv32 or rv64. |
41 | # output: Which output you want? (exe, pie, .so) | |
42 | proc run_dump_test_ifunc { name target output} { | |
43 | set asflags "" | |
44 | set ldflags "-z nocombreloc" | |
45 | ||
46 | switch -- $output { | |
47 | exe { | |
48 | set ext "exe" | |
49 | } | |
50 | pie { | |
51 | set ext "pie" | |
52 | set ldflags "$ldflags -pie" | |
53 | } | |
54 | pic { | |
55 | set ext "so" | |
56 | set ldflags "$ldflags -shared" | |
57 | } | |
58 | } | |
59 | ||
60 | switch -- $target { | |
61 | rv32 { | |
62 | set asflags "$asflags -march=rv32i -mabi=ilp32" | |
f36ce378 | 63 | set ldflags "$ldflags -m[riscv_choose_ilp32_emul]" |
02dd9d25 NC |
64 | } |
65 | rv64 { | |
66 | set asflags "$asflags -march=rv64i -mabi=lp64 -defsym __64_bit__=1" | |
f36ce378 | 67 | set ldflags "$ldflags -m[riscv_choose_lp64_emul]" |
02dd9d25 NC |
68 | } |
69 | } | |
70 | ||
71 | run_ld_link_tests [list \ | |
72 | [list "$name ($target-$output)" \ | |
73 | "$ldflags" "" \ | |
74 | "$asflags" \ | |
75 | [list "$name.s"] \ | |
76 | [concat [list "readelf -rW $name-$output.rd"] \ | |
77 | [list "objdump -dw $name.d"]] \ | |
78 | "$name-$target.$ext"]] | |
79 | } | |
80 | ||
da02107a | 81 | if [istarget "riscv*-*-*"] { |
c6261a00 | 82 | run_dump_test "call-relax" |
abd20cb6 | 83 | run_dump_test "pcgp-relax" |
3342be5d | 84 | run_dump_test "c-lui" |
080a4883 | 85 | run_dump_test "c-lui-2" |
35eeb78f | 86 | run_dump_test "disas-jalr" |
2a0d9853 | 87 | run_dump_test "pcrel-lo-addend" |
551703cf | 88 | run_dump_test "pcrel-lo-addend-2" |
7d7a7d7c JW |
89 | run_dump_test "attr-merge-arch-01" |
90 | run_dump_test "attr-merge-arch-02" | |
91 | run_dump_test "attr-merge-arch-03" | |
92 | run_dump_test "attr-merge-strict-align-01" | |
93 | run_dump_test "attr-merge-strict-align-02" | |
94 | run_dump_test "attr-merge-strict-align-03" | |
95 | run_dump_test "attr-merge-strict-align-04" | |
96 | run_dump_test "attr-merge-strict-align-05" | |
97 | run_dump_test "attr-merge-stack-align" | |
41285764 NC |
98 | run_dump_test "attr-merge-priv-spec-01" |
99 | run_dump_test "attr-merge-priv-spec-02" | |
100 | run_dump_test "attr-merge-priv-spec-03" | |
7d7a7d7c | 101 | run_dump_test "attr-merge-arch-failed-01" |
32f0ce4d | 102 | run_dump_test "attr-merge-arch-failed-02" |
7d7a7d7c | 103 | run_dump_test "attr-merge-stack-align-failed" |
41285764 NC |
104 | run_dump_test "attr-merge-priv-spec-failed-01" |
105 | run_dump_test "attr-merge-priv-spec-failed-02" | |
106 | run_dump_test "attr-merge-priv-spec-failed-03" | |
107 | run_dump_test "attr-merge-priv-spec-failed-04" | |
108 | run_dump_test "attr-merge-priv-spec-failed-05" | |
109 | run_dump_test "attr-merge-priv-spec-failed-06" | |
f36ce378 MC |
110 | run_ld_link_tests [list \ |
111 | [list "Weak reference 32" "-T weakref.ld -m[riscv_choose_ilp32_emul]" "" \ | |
112 | "-march=rv32i -mabi=ilp32" {weakref32.s} \ | |
113 | {{objdump -d weakref32.d}} "weakref32"] \ | |
114 | [list "Weak reference 64" "-T weakref.ld -m[riscv_choose_lp64_emul]" "" \ | |
115 | "-march=rv64i -mabi=lp64" {weakref64.s} \ | |
116 | {{objdump -d weakref64.d}} "weakref64"]] | |
da02107a | 117 | |
7615ca1d JW |
118 | # The following tests require shared library support. |
119 | if ![check_shared_lib_support] { | |
120 | return | |
121 | } | |
122 | ||
f36ce378 | 123 | set abis [list rv32gc ilp32 [riscv_choose_ilp32_emul] rv64gc lp64 [riscv_choose_lp64_emul]] |
da02107a | 124 | foreach { arch abi emul } $abis { |
0527614a JW |
125 | # This checks whether our linker scripts handle __global_pointer$ |
126 | # correctly. It should be defined in executables and PIE, but not | |
127 | # in shared libraries. | |
da02107a JW |
128 | set suff64 [string map {ilp32 "" lp64 -64} $abi] |
129 | run_ld_link_tests [list \ | |
0527614a | 130 | [list "gp test ($abi shared library)" \ |
da02107a JW |
131 | "-m$emul -shared" "" \ |
132 | "-march=$arch -mabi=$abi -fpic" \ | |
0527614a JW |
133 | { gp-test.s } \ |
134 | [list "readelf --syms gp-test-lib.sd"] \ | |
135 | "gp-test-lib-${abi}.so"] \ | |
136 | [list "gp test ($abi executable)" \ | |
137 | "-m$emul" "" \ | |
da02107a | 138 | "-march=$arch -mabi=$abi" \ |
0527614a JW |
139 | { gp-test.s } \ |
140 | [list "readelf --syms gp-test.sd"] \ | |
141 | "gp-test-${abi}"]] | |
da02107a | 142 | } |
330a6637 JW |
143 | |
144 | run_ld_link_tests { | |
145 | { "Link non-pic code into a shared library (setup)" | |
146 | "-shared" "" "" {lib-nopic-01a.s} | |
147 | {} "lib-nopic-01a.so" } | |
148 | } | |
149 | run_dump_test "lib-nopic-01b" | |
02dd9d25 NC |
150 | |
151 | # IFUNC testcases. | |
152 | # Check IFUNC by single type relocs. | |
153 | run_dump_test_ifunc "ifunc-reloc-call-01" rv32 exe | |
154 | run_dump_test_ifunc "ifunc-reloc-call-01" rv32 pie | |
155 | run_dump_test_ifunc "ifunc-reloc-call-01" rv32 pic | |
156 | run_dump_test_ifunc "ifunc-reloc-call-02" rv32 exe | |
157 | run_dump_test_ifunc "ifunc-reloc-call-02" rv32 pie | |
158 | run_dump_test_ifunc "ifunc-reloc-call-02" rv32 pic | |
159 | run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 exe | |
160 | run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 pie | |
161 | run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 pic | |
162 | run_dump_test_ifunc "ifunc-reloc-data" rv32 exe | |
163 | run_dump_test_ifunc "ifunc-reloc-data" rv32 pie | |
164 | run_dump_test_ifunc "ifunc-reloc-data" rv32 pic | |
165 | run_dump_test_ifunc "ifunc-reloc-got" rv32 exe | |
166 | run_dump_test_ifunc "ifunc-reloc-got" rv32 pie | |
167 | run_dump_test_ifunc "ifunc-reloc-got" rv32 pic | |
168 | run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 exe | |
169 | run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 pie | |
170 | run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 pic | |
171 | run_dump_test_ifunc "ifunc-reloc-data" rv64 exe | |
172 | run_dump_test_ifunc "ifunc-reloc-data" rv64 pie | |
173 | run_dump_test_ifunc "ifunc-reloc-data" rv64 pic | |
174 | run_dump_test_ifunc "ifunc-reloc-got" rv64 exe | |
175 | run_dump_test_ifunc "ifunc-reloc-got" rv64 pie | |
176 | run_dump_test_ifunc "ifunc-reloc-got" rv64 pic | |
177 | # Check the IFUNC PLT and non-PLT relocs. | |
178 | run_dump_test_ifunc "ifunc-nonplt" rv32 exe | |
179 | run_dump_test_ifunc "ifunc-nonplt" rv32 pie | |
180 | run_dump_test_ifunc "ifunc-nonplt" rv32 pic | |
181 | run_dump_test_ifunc "ifunc-plt-01" rv32 exe | |
182 | run_dump_test_ifunc "ifunc-plt-01" rv32 pie | |
183 | run_dump_test_ifunc "ifunc-plt-01" rv32 pic | |
184 | run_dump_test_ifunc "ifunc-plt-02" rv32 exe | |
185 | run_dump_test_ifunc "ifunc-plt-02" rv32 pie | |
186 | run_dump_test_ifunc "ifunc-plt-02" rv32 pic | |
187 | run_dump_test_ifunc "ifunc-nonplt" rv64 exe | |
188 | run_dump_test_ifunc "ifunc-nonplt" rv64 pie | |
189 | run_dump_test_ifunc "ifunc-nonplt" rv64 pic | |
190 | run_dump_test_ifunc "ifunc-plt-01" rv64 exe | |
191 | run_dump_test_ifunc "ifunc-plt-01" rv64 pie | |
192 | run_dump_test_ifunc "ifunc-plt-01" rv64 pic | |
193 | run_dump_test_ifunc "ifunc-plt-02" rv64 exe | |
194 | run_dump_test_ifunc "ifunc-plt-02" rv64 pie | |
195 | run_dump_test_ifunc "ifunc-plt-02" rv64 pic | |
51a8a7c2 NC |
196 | # Check the .rela.iplt overwrite issue. |
197 | run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 exe | |
198 | run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 pie | |
199 | run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 pic | |
200 | run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 exe | |
201 | run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 pie | |
202 | run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 pic | |
02dd9d25 NC |
203 | |
204 | # Setup shared libraries. | |
205 | run_ld_link_tests { | |
206 | { "Build shared library for IFUNC non-PLT caller" | |
207 | "-shared" "" "" {ifunc-seperate-caller-nonplt.s} | |
208 | {} "ifunc-seperate-caller.so" } | |
209 | { "Build shared library for IFUNC PLT caller" | |
210 | "-shared" "" "" {ifunc-seperate-caller-plt.s} | |
211 | {} "ifunc-seperate-caller.so" } | |
212 | { "Build shared library for IFUNC resolver" | |
213 | "-shared" "" "" {ifunc-seperate-resolver.s} | |
214 | {} "ifunc-seperate-resolver.so" } | |
215 | } | |
216 | # The IFUNC resolver and caller are in the seperate modules. | |
217 | # If IFUNC resolver and caller are linked to the same module, | |
218 | # then the result are the same as the run_dump_test_ifunc. | |
219 | run_dump_test "ifunc-seperate-nonplt-exe" | |
220 | run_dump_test "ifunc-seperate-nonplt-pie" | |
221 | run_dump_test "ifunc-seperate-nonplt-pic" | |
222 | run_dump_test "ifunc-seperate-plt-exe" | |
223 | run_dump_test "ifunc-seperate-plt-pie" | |
224 | run_dump_test "ifunc-seperate-plt-pic" | |
225 | run_dump_test "ifunc-seperate-pcrel-pie" | |
226 | run_dump_test "ifunc-seperate-pcrel-pic" | |
3342be5d | 227 | } |