RISC-V: Clarify the addends of pc-relative access.
[deliverable/binutils-gdb.git] / ld / testsuite / ld-riscv-elf / ld-riscv-elf.exp
CommitLineData
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
22proc riscv_choose_ilp32_emul {} {
23 if { [istarget "riscvbe-*"] \
24 || [istarget "riscv32be-*"] \
25 || [istarget "riscv64be-*"] } {
26 return "elf32briscv"
27 }
28 return "elf32lriscv"
29}
30
31proc 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)
42proc 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 81if [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"
75f03fa7
NC
88 run_dump_test "pcrel-lo-addend-2a"
89 run_dump_test "pcrel-lo-addend-2b"
50331d64
NC
90 run_dump_test "pcrel-lo-addend-3a"
91 run_dump_test "pcrel-lo-addend-3b"
92 run_dump_test "pcrel-lo-addend-3c"
ebdcad3f 93 run_dump_test "restart-relax"
7d7a7d7c
JW
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"
41285764
NC
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"
7d7a7d7c 106 run_dump_test "attr-merge-arch-failed-01"
32f0ce4d 107 run_dump_test "attr-merge-arch-failed-02"
7d7a7d7c 108 run_dump_test "attr-merge-stack-align-failed"
41285764
NC
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"
f36ce378
MC
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"]]
da02107a 122
7615ca1d
JW
123 # The following tests require shared library support.
124 if ![check_shared_lib_support] {
125 return
126 }
127
ef9d2565
NC
128 run_dump_test "relro-relax-lui"
129 run_dump_test "relro-relax-pcrel"
130
f36ce378 131 set abis [list rv32gc ilp32 [riscv_choose_ilp32_emul] rv64gc lp64 [riscv_choose_lp64_emul]]
da02107a 132 foreach { arch abi emul } $abis {
0527614a
JW
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.
da02107a
JW
136 set suff64 [string map {ilp32 "" lp64 -64} $abi]
137 run_ld_link_tests [list \
0527614a 138 [list "gp test ($abi shared library)" \
da02107a
JW
139 "-m$emul -shared" "" \
140 "-march=$arch -mabi=$abi -fpic" \
0527614a
JW
141 { gp-test.s } \
142 [list "readelf --syms gp-test-lib.sd"] \
143 "gp-test-lib-${abi}.so"] \
144 [list "gp test ($abi executable)" \
145 "-m$emul" "" \
da02107a 146 "-march=$arch -mabi=$abi" \
0527614a
JW
147 { gp-test.s } \
148 [list "readelf --syms gp-test.sd"] \
149 "gp-test-${abi}"]]
da02107a 150 }
330a6637
JW
151
152 run_ld_link_tests {
153 { "Link non-pic code into a shared library (setup)"
154 "-shared" "" "" {lib-nopic-01a.s}
155 {} "lib-nopic-01a.so" }
156 }
157 run_dump_test "lib-nopic-01b"
02dd9d25
NC
158
159 # IFUNC testcases.
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
51a8a7c2
NC
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
02dd9d25
NC
211
212 # Setup shared libraries.
213 run_ld_link_tests {
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" }
223 }
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"
3342be5d 235}
This page took 0.2126 seconds and 4 git commands to generate.