1 # Expect script for LoongArch ELF linker tests
2 # Copyright (C) 2022-2024 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 if [istarget loongarch64-*-*] {
24 if [isbuild loongarch64-*-*] {
25 set testname "loongarch relax .exe build"
26 set pre_builds [list \
37 run_cc_link_tests $pre_builds
39 if [file exist "tmpdir/relax"] {
40 set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax"]
41 if { [ regexp ".*pcaddi.*pcaddi.*" $objdump_output] } {
42 pass "loongarch relax .exe"
44 fail "loongarch relax .exe"
48 set testname "loongarch ld --no-relax build"
49 set pre_builds [list \
60 run_cc_link_tests $pre_builds
62 if [file exist "tmpdir/norelax"] {
63 set objdump_output [run_host_cmd "objdump" "-d tmpdir/norelax"]
64 if { [ regexp ".*pcaddi.*" $objdump_output] } {
65 fail "loongarch ld --no-relax"
67 pass "loongarch ld --no-relax"
71 if [check_shared_lib_support] {
75 "loongarch relax .so build" \
85 if [file exist "tmpdir/relax-so"] {
86 set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-so"]
87 if { [ regexp ".*pcaddi.*" $objdump_output] } {
88 pass "loongarch relax .so"
90 fail "loongarch relax .so"
97 "loongarch tls le relax .exe build" \
106 if [file exist "tmpdir/relax-tls-le"] {
107 set objdump_output1 [run_host_cmd "objdump" "-d tmpdir/relax-tls-le -M no-aliases"]
108 if { [ regexp ".addi.*st.*" $objdump_output1] } {
109 pass "loongarch relax success"
111 fail "loongarch relax fail"
118 "loongarch tls le no relax .exe build" \
127 if [file exist "tmpdir/no-relax-tls-le"] {
128 set objdump_output2 [run_host_cmd "objdump" "-d tmpdir/no-relax-tls-le -M no-aliases"]
129 if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output2] } {
130 pass "loongarch no-relax success"
132 fail "loongarch no-relax fail"
139 "loongarch old tls le .exe build" \
148 if [file exist "tmpdir/old-tls-le"] {
149 set objdump_output3 [run_host_cmd "objdump" "-d tmpdir/old-tls-le -M no-aliases"]
150 if { [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output3] } {
151 pass "loongarch old tls le success"
153 fail "loongarch old tls le fail"
160 "loongarch tls le realx compatible .exe build" \
163 {tls-relax-compatible-check-new.s tls-relax-compatible-check-old.s} \
169 if [file exist "tmpdir/realx-compatible"] {
170 set objdump_output4 [run_host_cmd "objdump" "-d tmpdir/realx-compatible -M no-aliases"]
171 if { [ regexp ".addi.*st.*" $objdump_output4] && \
172 [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output4] } {
173 pass "loongarch tls le relax compatible check success"
175 fail "loongarch tls le relax compatible check fail"
182 "loongarch tls le no realx compatible .exe build" \
185 {tls-relax-compatible-check-new.s tls-relax-compatible-check-old.s} \
187 "no-realx-compatible" \
190 if [file exist "tmpdir/no-realx-compatible"] {
191 set objdump_output4 [run_host_cmd "objdump" "-d tmpdir/no-realx-compatible -M no-aliases"]
192 if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output4] && \
193 [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output4] } {
194 pass "loongarch tls le no-relax compatible check success"
196 fail "loongarch tls le no-relax compatible check fail"
203 "loongarch tls le realx bound-check .exe build" \
206 {relax-bound-check-tls-le.s} \
208 "relax-bound-check-tls-le" \
212 if [file exist "tmpdir/relax-bound-check-tls-le"] {
213 set objdump_output5 [run_host_cmd "objdump" "-d tmpdir/relax-bound-check-tls-le -M no-aliases"]
214 if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output5] && \
215 [ regexp ".addi.*st.*" $objdump_output5] } {
216 pass "loongarch no-relax success"
218 fail "loongarch no-relax fail"
225 "loongarch tls le no realx bound-check .exe build" \
228 {relax-bound-check-tls-le.s} \
230 "no-relax-bound-check-tls-le" \
234 if [file exist "tmpdir/no-relax-bound-check-tls-le"] {
235 set objdump_output5 [run_host_cmd "objdump" "-d tmpdir/no-relax-bound-check-tls-le -M no-aliases"]
236 if { [ regexp ".*addi.*st.*" $objdump_output5] } {
237 pass "loongarch no-relax success"
239 fail "loongarch no-relax fail"
243 # If symbol in data segment, offset need to sub segment align to prevent
245 if [check_pie_support] {
249 "loongarch relax segment alignment min" \
250 "-e0 -Ttext 0x120004000 -pie -z relro" "" \
252 {relax-segment-min.s} \
254 "relax-segment-min" \
261 "loongarch relax segment alignment max" \
262 "-e0 -Ttext 0x120004000 -pie -z relro" "" \
264 {relax-segment-max.s} \
266 "relax-segment-max" \
274 "loongarch relax section align overflow" \
275 "-e0 -Ttext 0x120000000" "" \
277 {relax-section-align-overflow.s} \
279 "relax-section-align-overflow" \
284 if [check_shared_lib_support] {
288 "loongarch relax-align" \
289 "-e 0x0 -z relro" "" \
293 [list objdump -d relax-align.dd] \
300 set objdump_flags "-s -j .data"
304 "loongarch uleb128" \
309 [list objdump $objdump_flags uleb128.dd] \