]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp
Add libctf to update-copyright.py
[thirdparty/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-2020 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 # target: rv32 or rv64.
23 # output: Which output you want? (exe, pie, .so)
24 proc run_dump_test_ifunc { name target output} {
25 set asflags ""
26 set ldflags "-z nocombreloc"
27
28 switch -- $output {
29 exe {
30 set ext "exe"
31 }
32 pie {
33 set ext "pie"
34 set ldflags "$ldflags -pie"
35 }
36 pic {
37 set ext "so"
38 set ldflags "$ldflags -shared"
39 }
40 }
41
42 switch -- $target {
43 rv32 {
44 set asflags "$asflags -march=rv32i -mabi=ilp32"
45 set ldflags "$ldflags -melf32lriscv"
46 }
47 rv64 {
48 set asflags "$asflags -march=rv64i -mabi=lp64 -defsym __64_bit__=1"
49 set ldflags "$ldflags -melf64lriscv"
50 }
51 }
52
53 run_ld_link_tests [list \
54 [list "$name ($target-$output)" \
55 "$ldflags" "" \
56 "$asflags" \
57 [list "$name.s"] \
58 [concat [list "readelf -rW $name-$output.rd"] \
59 [list "objdump -dw $name.d"]] \
60 "$name-$target.$ext"]]
61 }
62
63 if [istarget "riscv*-*-*"] {
64 run_dump_test "call-relax"
65 run_dump_test "pcgp-relax"
66 run_dump_test "c-lui"
67 run_dump_test "c-lui-2"
68 run_dump_test "disas-jalr"
69 run_dump_test "pcrel-lo-addend"
70 run_dump_test "pcrel-lo-addend-2"
71 run_dump_test "attr-merge-arch-01"
72 run_dump_test "attr-merge-arch-02"
73 run_dump_test "attr-merge-arch-03"
74 run_dump_test "attr-merge-strict-align-01"
75 run_dump_test "attr-merge-strict-align-02"
76 run_dump_test "attr-merge-strict-align-03"
77 run_dump_test "attr-merge-strict-align-04"
78 run_dump_test "attr-merge-strict-align-05"
79 run_dump_test "attr-merge-stack-align"
80 run_dump_test "attr-merge-priv-spec-01"
81 run_dump_test "attr-merge-priv-spec-02"
82 run_dump_test "attr-merge-priv-spec-03"
83 run_dump_test "attr-merge-arch-failed-01"
84 run_dump_test "attr-merge-arch-failed-02"
85 run_dump_test "attr-merge-stack-align-failed"
86 run_dump_test "attr-merge-priv-spec-failed-01"
87 run_dump_test "attr-merge-priv-spec-failed-02"
88 run_dump_test "attr-merge-priv-spec-failed-03"
89 run_dump_test "attr-merge-priv-spec-failed-04"
90 run_dump_test "attr-merge-priv-spec-failed-05"
91 run_dump_test "attr-merge-priv-spec-failed-06"
92 run_ld_link_tests {
93 { "Weak reference 32" "-T weakref.ld -melf32lriscv" ""
94 "-march=rv32i -mabi=ilp32" {weakref32.s}
95 {{objdump -d weakref32.d}} "weakref32"}
96 { "Weak reference 64" "-T weakref.ld -melf64lriscv" ""
97 "-march=rv64i -mabi=lp64" {weakref64.s}
98 {{objdump -d weakref64.d}} "weakref64"}
99 }
100
101 # The following tests require shared library support.
102 if ![check_shared_lib_support] {
103 return
104 }
105
106 set abis { rv32gc ilp32 elf32lriscv rv64gc lp64 elf64lriscv }
107 foreach { arch abi emul } $abis {
108 # This checks whether our linker scripts handle __global_pointer$
109 # correctly. It should be defined in executables and PIE, but not
110 # in shared libraries.
111 set suff64 [string map {ilp32 "" lp64 -64} $abi]
112 run_ld_link_tests [list \
113 [list "gp test ($abi shared library)" \
114 "-m$emul -shared" "" \
115 "-march=$arch -mabi=$abi -fpic" \
116 { gp-test.s } \
117 [list "readelf --syms gp-test-lib.sd"] \
118 "gp-test-lib-${abi}.so"] \
119 [list "gp test ($abi executable)" \
120 "-m$emul" "" \
121 "-march=$arch -mabi=$abi" \
122 { gp-test.s } \
123 [list "readelf --syms gp-test.sd"] \
124 "gp-test-${abi}"]]
125 }
126
127 run_ld_link_tests {
128 { "Link non-pic code into a shared library (setup)"
129 "-shared" "" "" {lib-nopic-01a.s}
130 {} "lib-nopic-01a.so" }
131 }
132 run_dump_test "lib-nopic-01b"
133
134 # IFUNC testcases.
135 # Check IFUNC by single type relocs.
136 run_dump_test_ifunc "ifunc-reloc-call-01" rv32 exe
137 run_dump_test_ifunc "ifunc-reloc-call-01" rv32 pie
138 run_dump_test_ifunc "ifunc-reloc-call-01" rv32 pic
139 run_dump_test_ifunc "ifunc-reloc-call-02" rv32 exe
140 run_dump_test_ifunc "ifunc-reloc-call-02" rv32 pie
141 run_dump_test_ifunc "ifunc-reloc-call-02" rv32 pic
142 run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 exe
143 run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 pie
144 run_dump_test_ifunc "ifunc-reloc-pcrel" rv32 pic
145 run_dump_test_ifunc "ifunc-reloc-data" rv32 exe
146 run_dump_test_ifunc "ifunc-reloc-data" rv32 pie
147 run_dump_test_ifunc "ifunc-reloc-data" rv32 pic
148 run_dump_test_ifunc "ifunc-reloc-got" rv32 exe
149 run_dump_test_ifunc "ifunc-reloc-got" rv32 pie
150 run_dump_test_ifunc "ifunc-reloc-got" rv32 pic
151 run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 exe
152 run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 pie
153 run_dump_test_ifunc "ifunc-reloc-pcrel" rv64 pic
154 run_dump_test_ifunc "ifunc-reloc-data" rv64 exe
155 run_dump_test_ifunc "ifunc-reloc-data" rv64 pie
156 run_dump_test_ifunc "ifunc-reloc-data" rv64 pic
157 run_dump_test_ifunc "ifunc-reloc-got" rv64 exe
158 run_dump_test_ifunc "ifunc-reloc-got" rv64 pie
159 run_dump_test_ifunc "ifunc-reloc-got" rv64 pic
160 # Check the IFUNC PLT and non-PLT relocs.
161 run_dump_test_ifunc "ifunc-nonplt" rv32 exe
162 run_dump_test_ifunc "ifunc-nonplt" rv32 pie
163 run_dump_test_ifunc "ifunc-nonplt" rv32 pic
164 run_dump_test_ifunc "ifunc-plt-01" rv32 exe
165 run_dump_test_ifunc "ifunc-plt-01" rv32 pie
166 run_dump_test_ifunc "ifunc-plt-01" rv32 pic
167 run_dump_test_ifunc "ifunc-plt-02" rv32 exe
168 run_dump_test_ifunc "ifunc-plt-02" rv32 pie
169 run_dump_test_ifunc "ifunc-plt-02" rv32 pic
170 run_dump_test_ifunc "ifunc-nonplt" rv64 exe
171 run_dump_test_ifunc "ifunc-nonplt" rv64 pie
172 run_dump_test_ifunc "ifunc-nonplt" rv64 pic
173 run_dump_test_ifunc "ifunc-plt-01" rv64 exe
174 run_dump_test_ifunc "ifunc-plt-01" rv64 pie
175 run_dump_test_ifunc "ifunc-plt-01" rv64 pic
176 run_dump_test_ifunc "ifunc-plt-02" rv64 exe
177 run_dump_test_ifunc "ifunc-plt-02" rv64 pie
178 run_dump_test_ifunc "ifunc-plt-02" rv64 pic
179 # Check the .rela.iplt overwrite issue.
180 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 exe
181 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 pie
182 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv32 pic
183 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 exe
184 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 pie
185 run_dump_test_ifunc "ifunc-plt-got-overwrite" rv64 pic
186
187 # Setup shared libraries.
188 run_ld_link_tests {
189 { "Build shared library for IFUNC non-PLT caller"
190 "-shared" "" "" {ifunc-seperate-caller-nonplt.s}
191 {} "ifunc-seperate-caller.so" }
192 { "Build shared library for IFUNC PLT caller"
193 "-shared" "" "" {ifunc-seperate-caller-plt.s}
194 {} "ifunc-seperate-caller.so" }
195 { "Build shared library for IFUNC resolver"
196 "-shared" "" "" {ifunc-seperate-resolver.s}
197 {} "ifunc-seperate-resolver.so" }
198 }
199 # The IFUNC resolver and caller are in the seperate modules.
200 # If IFUNC resolver and caller are linked to the same module,
201 # then the result are the same as the run_dump_test_ifunc.
202 run_dump_test "ifunc-seperate-nonplt-exe"
203 run_dump_test "ifunc-seperate-nonplt-pie"
204 run_dump_test "ifunc-seperate-nonplt-pic"
205 run_dump_test "ifunc-seperate-plt-exe"
206 run_dump_test "ifunc-seperate-plt-pie"
207 run_dump_test "ifunc-seperate-plt-pic"
208 run_dump_test "ifunc-seperate-pcrel-pie"
209 run_dump_test "ifunc-seperate-pcrel-pic"
210 }