LoongArch: Fix some test failures about TLS desc and TLS relaxation
[binutils-gdb.git] / ld / testsuite / ld-loongarch-elf / relax.exp
blobf421e8af8dd6bbef261a61b381ebf1d1cab44946
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,
19 # MA 02110-1301, USA.
22 if [istarget loongarch64-*-*] {
24   if [isbuild loongarch64-*-*] {
25     set testname "loongarch relax .exe build"
26     set pre_builds [list \
27       [list \
28         "$testname" \
29         "" \
30         "" \
31         {relax.s} \
32         {} \
33         "relax" \
34       ] \
35     ]
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"
43       } {
44         fail "loongarch relax .exe"
45       }
46     }
48     set testname "loongarch ld --no-relax build"
49     set pre_builds [list \
50       [list \
51         "$testname" \
52         "-Wl,--no-relax" \
53         "" \
54         {relax.s} \
55         {} \
56         "norelax" \
57       ] \
58     ]
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"
66       } {
67         pass "loongarch ld --no-relax"
68       }
69     }
71     if [check_shared_lib_support] {
72       run_ld_link_tests \
73           [list \
74               [list \
75                   "loongarch relax .so build" \
76                   "-shared -e 0x0" "" \
77                   "" \
78                   {relax-so.s} \
79                   {} \
80                   "relax-so" \
81               ] \
82           ]
83     }
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"
89       } {
90         fail "loongarch relax .so"
91       }
92     }
94     run_ld_link_tests \
95         [list \
96             [list \
97                 "loongarch tls le relax .exe build" \
98                 "" "" \
99                 "" \
100                 {relax-tls-le.s} \
101                 {} \
102                 "relax-tls-le" \
103             ] \
104         ]
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"
110         } {
111           fail "loongarch relax fail"
112         }
113       }
115     run_ld_link_tests \
116         [list \
117             [list \
118                 "loongarch tls le no relax .exe build" \
119                 "--no-relax" "" \
120                 "" \
121                 {relax-tls-le.s} \
122                 {} \
123                 "no-relax-tls-le" \
124             ] \
125         ]
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"
131         } {
132           fail "loongarch no-relax fail"
133         }
134       }
136     run_ld_link_tests \
137         [list \
138             [list \
139                 "loongarch old tls le .exe build" \
140                 "" "" \
141                 "" \
142                 {old-tls-le.s} \
143                 {} \
144                 "old-tls-le" \
145             ] \
146         ]
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"
152         } {
153           fail "loongarch old tls le fail"
154         }
155       }
157     run_ld_link_tests \
158         [list \
159             [list \
160                 "loongarch tls le realx compatible .exe build" \
161                 "" "" \
162                 "" \
163                 {tls-relax-compatible-check-new.s tls-relax-compatible-check-old.s} \
164                 {} \
165                 "realx-compatible" \
166             ] \
167         ]
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"
174         } {
175           fail "loongarch tls le relax compatible check fail"
176         }
177       }
179     run_ld_link_tests \
180         [list \
181             [list \
182                 "loongarch tls le no realx compatible .exe build" \
183                 "--no-relax" "" \
184                 "" \
185                 {tls-relax-compatible-check-new.s tls-relax-compatible-check-old.s} \
186                 {} \
187                 "no-realx-compatible" \
188             ] \
189         ]
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"
195         } {
196           fail "loongarch tls le no-relax compatible check fail"
197         }
198       }
200     run_ld_link_tests \
201         [list \
202             [list \
203                 "loongarch tls le realx bound-check .exe build" \
204                 "" "" \
205                 "" \
206                 {relax-bound-check-tls-le.s} \
207                 {} \
208                 "relax-bound-check-tls-le" \
209             ] \
210         ]
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"
217         } {
218           fail "loongarch no-relax fail"
219         }
220       }
222     run_ld_link_tests \
223         [list \
224             [list \
225                 "loongarch tls le no realx bound-check .exe build" \
226                 "--no-relax" "" \
227                 "" \
228                 {relax-bound-check-tls-le.s} \
229                 {} \
230                 "no-relax-bound-check-tls-le" \
231             ] \
232         ]
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"
238         } {
239           fail "loongarch no-relax fail"
240         }
241       }
243     # If symbol in data segment, offset need to sub segment align to prevent
244     # overflow.
245     if [check_pie_support] {
246       run_ld_link_tests \
247           [list \
248               [list \
249                   "loongarch relax segment alignment min" \
250                   "-e0 -Ttext 0x120004000 -pie -z relro" "" \
251                   "" \
252                   {relax-segment-min.s} \
253                   {} \
254                   "relax-segment-min" \
255               ] \
256           ]
258       run_ld_link_tests \
259           [list \
260               [list \
261                   "loongarch relax segment alignment max" \
262                   "-e0 -Ttext 0x120004000 -pie -z relro" "" \
263                   "" \
264                   {relax-segment-max.s} \
265                   {} \
266                   "relax-segment-max" \
267               ] \
268           ]
269     }
271     run_ld_link_tests \
272         [list \
273             [list \
274                 "loongarch relax section align overflow" \
275                 "-e0 -Ttext 0x120000000" "" \
276                 "" \
277                 {relax-section-align-overflow.s} \
278                 {} \
279                 "relax-section-align-overflow" \
280             ] \
281         ]
282   }
284   if [check_shared_lib_support] {
285     run_ld_link_tests \
286         [list \
287             [list \
288                 "loongarch relax-align" \
289                 "-e 0x0 -z relro" "" \
290                 "--no-warn" \
291                 {relax-align.s} \
292                 [list \
293                     [list objdump -d relax-align.dd] \
294                 ] \
295                 "relax-align" \
296             ] \
297         ]
298   }
300   set objdump_flags "-s -j .data"
301   run_ld_link_tests \
302       [list \
303           [list \
304               "loongarch uleb128" \
305               "-e 0x0" "" \
306               "" \
307               {uleb128.s} \
308               [list \
309                   [list objdump $objdump_flags uleb128.dd] \
310               ] \
311               "uleb128" \
312           ] \
313       ]