aboutsummaryrefslogtreecommitdiff
path: root/ld/testsuite/ld-loongarch-elf/relax.exp
blob: 6c65318a120445366727fa8070e6041f7a7056ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# Expect script for LoongArch ELF linker tests
#   Copyright (C) 2022 Free Software Foundation, Inc.
#
# This file is part of the GNU Binutils.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
# MA 02110-1301, USA.
#

if [istarget loongarch64-*-*] {

  if [isbuild loongarch64-*-*] {
    set testname "loongarch relax .exe build"
    set pre_builds [list \
      [list \
	"$testname" \
	"" \
	"" \
	{relax.s} \
	{} \
	"relax" \
      ] \
    ]
    set tls_relax_builds [list \
      [list \
	"tls_relax_builds" \
	"" \
	"" \
	{relax-tls-le.s} \
	{}        \
	"relax-tls-le" \
      ] \
    ]
    set tls_no_relax_builds [list \
      [list \
	"tls_no_relax_builds" \
	"-Wl,--no-relax" \
	"" \
	{relax-tls-le.s} \
	{}        \
	"no-relax-tls-le" \
      ] \
    ]

    set relax_bound_check [list \
      [list \
	"relax_bound_check" \
	"" \
	"" \
	{relax-bound-check-tls-le.s} \
	{}        \
	"relax-bound-check-tls-le" \
      ] \
    ]
    set no_relax_bound_check [list \
      [list \
	"no_relax_bound_check" \
	"-Wl,--no-relax" \
	"" \
	{relax-bound-check-tls-le.s} \
	{}        \
	"no-relax-bound-check-tls-le" \
      ] \
    ]

    set old_tls_le [list \
      [list \
	"old_tls_le" \
	"" \
	"" \
	{old-tls-le.s} \
	{}        \
	"old-tls-le" \
      ] \
    ]

     set relax_compatible [list \
      [list \
	"relax_compatible" \
	"" \
	"" \
	{tls-relax-compatible-check-new.s tls-relax-compatible-check-old.s} \
	{}        \
	"realx-compatible" \
      ] \
    ]

    set no_relax_compatible [list \
      [list \
	"no_relax_compatible" \
	"-Wl,--no-relax" \
	"" \
	{tls-relax-compatible-check-new.s tls-relax-compatible-check-old.s} \
	{}        \
	"no-realx-compatible" \
      ] \
    ]


    run_cc_link_tests $pre_builds
    run_cc_link_tests $tls_relax_builds
    run_cc_link_tests $tls_no_relax_builds
    run_cc_link_tests $relax_bound_check
    run_cc_link_tests $no_relax_bound_check
    run_cc_link_tests $old_tls_le
    run_cc_link_tests $relax_compatible
    run_cc_link_tests $no_relax_compatible

    if [file exist "tmpdir/relax"] {
      set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax"]
      if { [ regexp ".*pcaddi.*pcaddi.*" $objdump_output] } {
	pass "loongarch relax .exe"
      } {
	fail "loongarch relax .exe"
      }
    }

    set testname "loongarch ld --no-relax build"
    set pre_builds [list \
      [list \
	"$testname" \
	"-Wl,--no-relax" \
	"" \
	{relax.s} \
	{} \
	"norelax" \
      ] \
    ]

    run_cc_link_tests $pre_builds

    if [file exist "tmpdir/norelax"] {
      set objdump_output [run_host_cmd "objdump" "-d tmpdir/norelax"]
      if { [ regexp ".*pcaddi.*" $objdump_output] } {
	fail "loongarch ld --no-relax"
      } {
	pass "loongarch ld --no-relax"
      }
    }

    if [check_shared_lib_support] {
      run_ld_link_tests \
	  [list \
	      [list \
		  "loongarch relax .so build" \
		  "-shared -e 0x0" "" \
		  "" \
		  {relax-so.s} \
		  {} \
		  "relax-so" \
	      ] \
	  ]
    }

      if [file exist "tmpdir/relax-so"] {
	set objdump_output [run_host_cmd "objdump" "-d tmpdir/relax-so"]
	if { [ regexp ".*pcaddi.*" $objdump_output] } {
	  pass "loongarch relax .so"
	} {
	  fail "loongarch relax .so"
	}
      }

    # If symbol in data segment, offset need to sub segment align to prevent
    # overflow.
    if [check_pie_support] {
      run_ld_link_tests \
	  [list \
	      [list \
		  "loongarch relax segment alignment min" \
		  "-e0 -Ttext 0x120004000 -pie -z relro" "" \
		  "" \
		  {relax-segment-min.s} \
		  {} \
		  "relax-segment-min" \
	      ] \
	  ]

      run_ld_link_tests \
	  [list \
	      [list \
		  "loongarch relax segment alignment max" \
		  "-e0 -Ttext 0x120004000 -pie -z relro" "" \
		  "" \
		  {relax-segment-max.s} \
		  {} \
		  "relax-segment-max" \
	      ] \
	  ]
    }

    if [file exist "tmpdir/relax-tls-le"] {
      set objdump_output1 [run_host_cmd "objdump" "-d tmpdir/relax-tls-le"]
      if { [ regexp ".addi.*st.*" $objdump_output1] } {
	pass "loongarch relax success"
      } {
	fail "loongarch relax fail"
      }
    }
    if [file exist "tmpdir/no-relax-tls-le"] {
      set objdump_output2 [run_host_cmd "objdump" "-d tmpdir/no-relax-tls-le"]
      if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output2] } {
	pass "loongarch no-relax success"
      } {
	fail "loongarch no-relax fail"
      }

    }
    if [file exist "tmpdir/old-tls-le"] {
      set objdump_output3 [run_host_cmd "objdump" "-d tmpdir/old-tls-le"]
      if { [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output3] } {
	pass "loongarch old tls le success"
      } {
	fail "loongarch old tls le fail"
      }

    }

    if [file exist "tmpdir/realx-compatible"] {
      set objdump_output4 [run_host_cmd "objdump" "-d tmpdir/realx-compatible"]
      if { [ regexp ".addi.*st.*" $objdump_output4] && \
	   [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output4] } {
	pass "loongarch tls le relax compatible check success"
      } {
	fail "loongarch tls le relax compatible check fail"
      }
    }

    if [file exist "tmpdir/no-realx-compatible"] {
      set objdump_output4 [run_host_cmd "objdump" "-d tmpdir/realx-compatible"]
      if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output4] && \
	   [ regexp ".*lu12i.*ori.*add.*addi.*stptr.*" $objdump_output4] } {
	pass "loongarch tls le no-relax compatible check success"
      } {
	fail "loongarch tls le no-relax compatible check fail"
      }
    }


    if [file exist "tmpdir/relax-bound-check-tls-le"] {
      set objdump_output5 [run_host_cmd "objdump" "-d tmpdir/relax-bound-check-tls-le"]
      if { [ regexp ".*lu12i.*add.*addi.*st.*" $objdump_output5] && \
	   [ regexp ".addi.*st.*" $objdump_output5] } {
	pass "loongarch no-relax success"
      } {
	fail "loongarch no-relax fail"
      }

    }
    if [file exist "tmpdir/no-relax-bound-check-tls-le"] {
      set objdump_output5 [run_host_cmd "objdump" "-d tmpdir/no-relax-bound-check-tls-le"]
      if { [ regexp ".*addi.*st.*" $objdump_output5] } {
	pass "loongarch no-relax success"
      } {
	fail "loongarch no-relax fail"
      }
    }

  }

  if [check_shared_lib_support] {
    run_ld_link_tests \
	[list \
	    [list \
		"loongarch relax-align" \
		"-e 0x0 -z relro" "" \
		"--no-warn" \
		{relax-align.s} \
		[list \
		    [list objdump -d relax-align.dd] \
		] \
		"relax-align" \
	    ] \
	]
  }

  set objdump_flags "-s -j .data"
  run_ld_link_tests \
      [list \
	  [list \
	      "loongarch uleb128" \
	      "-e 0x0" "" \
	      "" \
	      {uleb128.s} \
	      [list \
		  [list objdump $objdump_flags uleb128.dd] \
	      ] \
	      "uleb128" \
	  ] \
      ]
}