319ac7e2b836ee0cdc10a2bb08f8f538df9395a7
[deliverable/binutils-gdb.git] / ld / testsuite / ld-riscv-elf / ld-riscv-elf.exp
1 # Expect script for RISC-V ELF linker tests
2 # Copyright (C) 2017-2021 Free Software Foundation, Inc.
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
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
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"
63 set ldflags "$ldflags -m[riscv_choose_ilp32_emul]"
64 }
65 rv64 {
66 set asflags "$asflags -march=rv64i -mabi=lp64 -defsym __64_bit__=1"
67 set ldflags "$ldflags -m[riscv_choose_lp64_emul]"
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
81 if [istarget "riscv*-*-*"] {
82 run_dump_test "call-relax"
83 run_dump_test "pcgp-relax"
84 run_dump_test "c-lui"
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 "restart-relax"
91 run_dump_test "attr-merge-arch-01"
92 run_dump_test "attr-merge-arch-02"
93 run_dump_test "attr-merge-arch-03"
94 run_dump_test "attr-merge-strict-align-01"
95 run_dump_test "attr-merge-strict-align-02"
96 run_dump_test "attr-merge-strict-align-03"
97 run_dump_test "attr-merge-strict-align-04"
98 run_dump_test "attr-merge-strict-align-05"
99 run_dump_test "attr-merge-stack-align"
100 run_dump_test "attr-merge-priv-spec-01"
101 run_dump_test "attr-merge-priv-spec-02"
102 run_dump_test "attr-merge-priv-spec-03"
103 run_dump_test "attr-merge-arch-failed-01"
104 run_dump_test "attr-merge-arch-failed-02"
105 run_dump_test "attr-merge-stack-align-failed"
106 run_dump_test "attr-merge-priv-spec-failed-01"
107 run_dump_test "attr-merge-priv-spec-failed-02"
108 run_dump_test "attr-merge-priv-spec-failed-03"
109 run_dump_test "attr-merge-priv-spec-failed-04"
110 run_dump_test "attr-merge-priv-spec-failed-05"
111 run_dump_test "attr-merge-priv-spec-failed-06"
112 run_ld_link_tests [list \
113 [list "Weak reference 32" "-T weakref.ld -m[riscv_choose_ilp32_emul]" "" \
114 "-march=rv32i -mabi=ilp32" {weakref32.s} \
115 {{objdump -d weakref32.d}} "weakref32"] \
116 [list "Weak reference 64" "-T weakref.ld -m[riscv_choose_lp64_emul]" "" \
117 "-march=rv64i -mabi=lp64" {weakref64.s} \
118 {{objdump -d weakref64.d}} "weakref64"]]
119
120 # The following tests require shared library support.
121 if ![check_shared_lib_support] {
122 return
123 }
124
125 set abis [list rv32gc ilp32 [riscv_choose_ilp32_emul] rv64gc lp64 [riscv_choose_lp64_emul]]
126 foreach { arch abi emul } $abis {
127 # This checks whether our linker scripts handle __global_pointer$
128 # correctly. It should be defined in executables and PIE, but not
129 # in shared libraries.
130 set suff64 [string map {ilp32 "" lp64 -64} $abi]
131 run_ld_link_tests [list \
132 [list "gp test ($abi shared library)" \
133 "-m$emul -shared" "" \
134 "-march=$arch -mabi=$abi -fpic" \
135 { gp-test.s } \
136 [list "readelf --syms gp-test-lib.sd"] \
137 "gp-test-lib-${abi}.so"] \
138 [list "gp test ($abi executable)" \
139 "-m$emul" "" \
140 "-march=$arch -mabi=$abi" \
141 { gp-test.s } \
142 [list "readelf --syms gp-test.sd"] \
143 "gp-test-${abi}"]]
144 }
145
146 run_ld_link_tests {
147 { "Link non-pic code into a shared library (setup)"
148 "-shared" "" "" {lib-nopic-01a.s}
149 {} "lib-nopic-01a.so" }
150 }
151 run_dump_test "lib-nopic-01b"
152
153 # IFUNC testcases.
154 # Check IFUNC by single type relocs.
155 run_dump_test_ifunc "ifunc-reloc-call-01" rv32 exe
156 run_dump_test_ifunc "ifunc-reloc-call-01" rv32 pie
157 run_dump_test_ifunc "ifunc-reloc-call-01" rv32 pic
158 run_dump_test_ifunc "ifunc-reloc-call-02" rv32 exe
159 run_dump_test_ifunc "ifunc-reloc-call-02" rv32 pie
160 run_dump_test_ifunc "ifunc-reloc-call-02" rv32 pic
161 run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 exe
162 run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 pie
163 run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 pic
164 run_dump_test_ifunc "ifunc-reloc-data" rv32 exe
165 run_dump_test_ifunc "ifunc-reloc-data" rv32 pie
166 run_dump_test_ifunc "ifunc-reloc-data" rv32 pic
167 run_dump_test_ifunc "ifunc-reloc-got" rv32 exe
168 run_dump_test_ifunc "ifunc-reloc-got" rv32 pie
169 run_dump_test_ifunc "ifunc-reloc-got" rv32 pic
170 run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 exe
171 run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 pie
172 run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 pic
173 run_dump_test_ifunc "ifunc-reloc-data" rv64 exe
174 run_dump_test_ifunc "ifunc-reloc-data" rv64 pie
175 run_dump_test_ifunc "ifunc-reloc-data" rv64 pic
176 run_dump_test_ifunc "ifunc-reloc-got" rv64 exe
177 run_dump_test_ifunc "ifunc-reloc-got" rv64 pie
178 run_dump_test_ifunc "ifunc-reloc-got" rv64 pic
179 # Check the IFUNC PLT and non-PLT relocs.
180 run_dump_test_ifunc "ifunc-nonplt" rv32 exe
181 run_dump_test_ifunc "ifunc-nonplt" rv32 pie
182 run_dump_test_ifunc "ifunc-nonplt" rv32 pic
183 run_dump_test_ifunc "ifunc-plt-01" rv32 exe
184 run_dump_test_ifunc "ifunc-plt-01" rv32 pie
185 run_dump_test_ifunc "ifunc-plt-01" rv32 pic
186 run_dump_test_ifunc "ifunc-plt-02" rv32 exe
187 run_dump_test_ifunc "ifunc-plt-02" rv32 pie
188 run_dump_test_ifunc "ifunc-plt-02" rv32 pic
189 run_dump_test_ifunc "ifunc-nonplt" rv64 exe
190 run_dump_test_ifunc "ifunc-nonplt" rv64 pie
191 run_dump_test_ifunc "ifunc-nonplt" rv64 pic
192 run_dump_test_ifunc "ifunc-plt-01" rv64 exe
193 run_dump_test_ifunc "ifunc-plt-01" rv64 pie
194 run_dump_test_ifunc "ifunc-plt-01" rv64 pic
195 run_dump_test_ifunc "ifunc-plt-02" rv64 exe
196 run_dump_test_ifunc "ifunc-plt-02" rv64 pie
197 run_dump_test_ifunc "ifunc-plt-02" rv64 pic
198 # Check the .rela.iplt overwrite issue.
199 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 exe
200 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 pie
201 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 pic
202 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 exe
203 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 pie
204 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 pic
205
206 # Setup shared libraries.
207 run_ld_link_tests {
208 { "Build shared library for IFUNC non-PLT caller"
209 "-shared" "" "" {ifunc-seperate-caller-nonplt.s}
210 {} "ifunc-seperate-caller.so" }
211 { "Build shared library for IFUNC PLT caller"
212 "-shared" "" "" {ifunc-seperate-caller-plt.s}
213 {} "ifunc-seperate-caller.so" }
214 { "Build shared library for IFUNC resolver"
215 "-shared" "" "" {ifunc-seperate-resolver.s}
216 {} "ifunc-seperate-resolver.so" }
217 }
218 # The IFUNC resolver and caller are in the seperate modules.
219 # If IFUNC resolver and caller are linked to the same module,
220 # then the result are the same as the run_dump_test_ifunc.
221 run_dump_test "ifunc-seperate-nonplt-exe"
222 run_dump_test "ifunc-seperate-nonplt-pie"
223 run_dump_test "ifunc-seperate-nonplt-pic"
224 run_dump_test "ifunc-seperate-plt-exe"
225 run_dump_test "ifunc-seperate-plt-pie"
226 run_dump_test "ifunc-seperate-plt-pic"
227 run_dump_test "ifunc-seperate-pcrel-pie"
228 run_dump_test "ifunc-seperate-pcrel-pic"
229 }
This page took 0.033394 seconds and 4 git commands to generate.