Skip to content

Commit 1c729b7

Browse files
loongson-cailululzshhxx
authored andcommitted
LoongArch: Fix some macro that cannot be expanded properly
Suppose we want to use la.got to generate 32 pcrel and 32 abs instruction sequences respectively. According to the existing conditions, to generate 32 pcrel sequences use -mabi=ilp32*, and to generate 32 abs use -mabi=ilp32* and -mla-global-with-abs. Due to the fact that the conditions for generating 32 abs also satisfy 32 pcrel, using -mabi=ilp32* and -mla-global-with-abs will result in only generating instruction sequences of 32 pcrel. By modifying the conditions for macro expansion and adjusting the matching order of macro instructions, it is ensured that the correct sequence of instructions can be generated.
1 parent 3fc4f11 commit 1c729b7

File tree

8 files changed

+108
-126
lines changed

8 files changed

+108
-126
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#as: -mla-global-with-abs -mla-local-with-abs
2+
#objdump: -dr
3+
#skip: loongarch32-*-*
4+
5+
.*: file format .*
6+
7+
8+
Disassembly of section .text:
9+
10+
0+ <.L1>:
11+
0: 14000004 lu12i.w \$a0, 0
12+
0: R_LARCH_MARK_LA \*ABS\*
13+
0: R_LARCH_ABS_HI20 .L1
14+
4: 03800084 ori \$a0, \$a0, 0x0
15+
4: R_LARCH_ABS_LO12 .L1
16+
8: 16000004 lu32i.d \$a0, 0
17+
8: R_LARCH_ABS64_LO20 .L1
18+
c: 03000084 lu52i.d \$a0, \$a0, 0
19+
c: R_LARCH_ABS64_HI12 .L1
20+
10: 14000004 lu12i.w \$a0, 0
21+
10: R_LARCH_MARK_LA \*ABS\*
22+
10: R_LARCH_ABS_HI20 .L1
23+
14: 03800084 ori \$a0, \$a0, 0x0
24+
14: R_LARCH_ABS_LO12 .L1
25+
18: 16000004 lu32i.d \$a0, 0
26+
18: R_LARCH_ABS64_LO20 .L1
27+
1c: 03000084 lu52i.d \$a0, \$a0, 0
28+
1c: R_LARCH_ABS64_HI12 .L1
29+
20: 1a000004 pcalau12i \$a0, 0
30+
20: R_LARCH_PCALA_HI20 .L1
31+
20: R_LARCH_RELAX \*ABS\*
32+
24: 02c00084 addi.d \$a0, \$a0, 0
33+
24: R_LARCH_PCALA_LO12 .L1
34+
24: R_LARCH_RELAX \*ABS\*
35+
28: 14000004 lu12i.w \$a0, 0
36+
28: R_LARCH_GOT_HI20 .L1
37+
2c: 03800084 ori \$a0, \$a0, 0x0
38+
2c: R_LARCH_GOT_LO12 .L1
39+
30: 16000004 lu32i.d \$a0, 0
40+
30: R_LARCH_GOT64_LO20 .L1
41+
34: 03000084 lu52i.d \$a0, \$a0, 0
42+
34: R_LARCH_GOT64_HI12 .L1
43+
38: 28c00084 ld.d \$a0, \$a0, 0
44+
3c: 14000004 lu12i.w \$a0, 0
45+
3c: R_LARCH_TLS_LE_HI20 TLS1
46+
40: 03800084 ori \$a0, \$a0, 0x0
47+
40: R_LARCH_TLS_LE_LO12 TLS1
48+
44: 14000004 lu12i.w \$a0, 0
49+
44: R_LARCH_TLS_IE_HI20 TLS1
50+
48: 03800084 ori \$a0, \$a0, 0x0
51+
48: R_LARCH_TLS_IE_LO12 TLS1
52+
4c: 16000004 lu32i.d \$a0, 0
53+
4c: R_LARCH_TLS_IE64_LO20 TLS1
54+
50: 03000084 lu52i.d \$a0, \$a0, 0
55+
50: R_LARCH_TLS_IE64_HI12 TLS1
56+
54: 28c00084 ld.d \$a0, \$a0, 0
57+
58: 14000004 lu12i.w \$a0, 0
58+
58: R_LARCH_TLS_LD_HI20 TLS1
59+
5c: 03800084 ori \$a0, \$a0, 0x0
60+
5c: R_LARCH_GOT_LO12 TLS1
61+
60: 16000004 lu32i.d \$a0, 0
62+
60: R_LARCH_GOT64_LO20 TLS1
63+
64: 03000084 lu52i.d \$a0, \$a0, 0
64+
64: R_LARCH_GOT64_HI12 TLS1
65+
68: 14000004 lu12i.w \$a0, 0
66+
68: R_LARCH_TLS_GD_HI20 TLS1
67+
6c: 03800084 ori \$a0, \$a0, 0x0
68+
6c: R_LARCH_GOT_LO12 TLS1
69+
70: 16000004 lu32i.d \$a0, 0
70+
70: R_LARCH_GOT64_LO20 TLS1
71+
74: 03000084 lu52i.d \$a0, \$a0, 0
72+
74: R_LARCH_GOT64_HI12 TLS1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.L1:
2+
la.local $r4, $r5, .L1
3+
la.global $r4, $r5, .L1
4+
la.pcrel $r4, .L1
5+
la.got $r4,.L1
6+
la.tls.le $r4, TLS1
7+
la.tls.ie $r4, TLS1
8+
la.tls.ld $r4, TLS1
9+
la.tls.gd $r4, TLS1

gas/testsuite/gas/loongarch/macro_op_large_abs.d renamed to gas/testsuite/gas/loongarch/macro_op_extreme_pc.d

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
#as:
1+
#as: -mla-global-with-pcrel
22
#objdump: -dr
33
#skip: loongarch32-*-*
44

55
.*: file format .*
66

7-
87
Disassembly of section .text:
98

109
0+ <.L1>:
@@ -20,16 +19,16 @@ Disassembly of section .text:
2019
c: R_LARCH_PCALA64_HI12 .L1
2120
10: 00109484 add.d \$a0, \$a0, \$a1
2221
14: 1a000004 pcalau12i \$a0, 0
23-
14: R_LARCH_GOT_PC_HI20 .L1
22+
14: R_LARCH_PCALA_HI20 .L1
2423
14: R_LARCH_RELAX \*ABS\*
2524
18: 02c00005 li.d \$a1, 0
26-
18: R_LARCH_GOT_PC_LO12 .L1
25+
18: R_LARCH_PCALA_LO12 .L1
2726
18: R_LARCH_RELAX \*ABS\*
2827
1c: 16000005 lu32i.d \$a1, 0
29-
1c: R_LARCH_GOT64_PC_LO20 .L1
28+
1c: R_LARCH_PCALA64_LO20 .L1
3029
20: 030000a5 lu52i.d \$a1, \$a1, 0
31-
20: R_LARCH_GOT64_PC_HI12 .L1
32-
24: 380c1484 ldx.d \$a0, \$a0, \$a1
30+
20: R_LARCH_PCALA64_HI12 .L1
31+
24: 00109484 add.d \$a0, \$a0, \$a1
3332
28: 1a000004 pcalau12i \$a0, 0
3433
28: R_LARCH_PCALA_HI20 .L1
3534
28: R_LARCH_RELAX \*ABS\*
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.L1:
2+
la.local $r4, $r5, .L1
3+
la.global $r4, $r5, .L1
4+
la.pcrel $r4, $r5, .L1
5+
la.got $r4, $r5, .L1
6+
la.tls.le $r4, TLS1
7+
la.tls.ie $r4, $r5, TLS1
8+
la.tls.ld $r4, $r5, TLS1
9+
la.tls.gd $r4, $r5, TLS1

gas/testsuite/gas/loongarch/macro_op_large_abs.s

Lines changed: 0 additions & 9 deletions
This file was deleted.

gas/testsuite/gas/loongarch/macro_op_large_pc.d

Lines changed: 0 additions & 89 deletions
This file was deleted.

gas/testsuite/gas/loongarch/macro_op_large_pc.s

Lines changed: 0 additions & 9 deletions
This file was deleted.

opcodes/loongarch-opc.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const char *const loongarch_x_normal_name[32] =
171171
"lu32i.d %1,%%got64_lo20(%2);" \
172172
"lu52i.d %1,%1,%%got64_hi12(%2);" \
173173
"ld.d %1,%1,0", \
174-
&LARCH_opts.ase_lp64, \
174+
&LARCH_opts.ase_gabs, \
175175
&LARCH_opts.ase_gpcr
176176
/* got64 pic. */
177177
#define INSN_LA_GOT64_LARGE_PCREL \
@@ -229,7 +229,7 @@ const char *const loongarch_x_normal_name[32] =
229229
"lu32i.d %1,%%ie64_lo20(%2);" \
230230
"lu52i.d %1,%1,%%ie64_hi12(%2);" \
231231
"ld.d %1,%1,0", \
232-
&LARCH_opts.ase_lp64, \
232+
&LARCH_opts.ase_gabs, \
233233
&LARCH_opts.ase_gpcr
234234

235235
/* For LoongArch32/64 cmode=normal. */
@@ -260,7 +260,7 @@ const char *const loongarch_x_normal_name[32] =
260260
"ori %1,%1,%%got_lo12(%2);" \
261261
"lu32i.d %1,%%got64_lo20(%2);" \
262262
"lu52i.d %1,%1,%%got64_hi12(%2);", \
263-
&LARCH_opts.ase_lp64, \
263+
&LARCH_opts.ase_gabs, \
264264
&LARCH_opts.ase_gpcr
265265

266266
#define INSN_LA_TLS_GD32 \
@@ -290,7 +290,7 @@ const char *const loongarch_x_normal_name[32] =
290290
"ori %1,%1,%%got_lo12(%2);" \
291291
"lu32i.d %1,%%got64_lo20(%2);" \
292292
"lu52i.d %1,%1,%%got64_hi12(%2);", \
293-
&LARCH_opts.ase_lp64, \
293+
&LARCH_opts.ase_gabs, \
294294
&LARCH_opts.ase_gpcr
295295

296296
#define INSN_LA_CALL \
@@ -376,27 +376,27 @@ static struct loongarch_opcode loongarch_macro_opcodes[] =
376376
{ 0, 0, "la.pcrel", "r,la", INSN_LA_PCREL32, 0 },
377377
{ 0, 0, "la.pcrel", "r,la", INSN_LA_PCREL64, 0 },
378378
{ 0, 0, "la.pcrel", "r,r,la", INSN_LA_PCREL64_LARGE, 0 },
379-
{ 0, 0, "la.got", "r,la", INSN_LA_GOT32, 0 },
380379
{ 0, 0, "la.got", "r,la", INSN_LA_GOT32_ABS, 0 },
381-
{ 0, 0, "la.got", "r,la", INSN_LA_GOT64, 0 },
380+
{ 0, 0, "la.got", "r,la", INSN_LA_GOT32, 0 },
382381
{ 0, 0, "la.got", "r,la", INSN_LA_GOT64_LARGE_ABS, 0 },
382+
{ 0, 0, "la.got", "r,la", INSN_LA_GOT64, 0 },
383383
{ 0, 0, "la.got", "r,r,la", INSN_LA_GOT64_LARGE_PCREL, 0 },
384384
{ 0, 0, "la.tls.le", "r,l", INSN_LA_TLS_LE, 0 },
385385
{ 0, 0, "la.tls.le", "r,l", INSN_LA_TLS_LE64_LARGE, 0 },
386-
{ 0, 0, "la.tls.ie", "r,l", INSN_LA_TLS_IE32, 0 },
387386
{ 0, 0, "la.tls.ie", "r,l", INSN_LA_TLS_IE32_ABS, 0 },
388-
{ 0, 0, "la.tls.ie", "r,l", INSN_LA_TLS_IE64, 0 },
387+
{ 0, 0, "la.tls.ie", "r,l", INSN_LA_TLS_IE32, 0 },
389388
{ 0, 0, "la.tls.ie", "r,l", INSN_LA_TLS_IE64_LARGE_ABS, 0 },
389+
{ 0, 0, "la.tls.ie", "r,l", INSN_LA_TLS_IE64, 0 },
390390
{ 0, 0, "la.tls.ie", "r,r,l", INSN_LA_TLS_IE64_LARGE_PCREL, 0 },
391-
{ 0, 0, "la.tls.ld", "r,l", INSN_LA_TLS_LD32, 0 },
392391
{ 0, 0, "la.tls.ld", "r,l", INSN_LA_TLS_LD32_ABS, 0 },
393-
{ 0, 0, "la.tls.ld", "r,l", INSN_LA_TLS_LD64, 0 },
392+
{ 0, 0, "la.tls.ld", "r,l", INSN_LA_TLS_LD32, 0 },
394393
{ 0, 0, "la.tls.ld", "r,l", INSN_LA_TLS_LD64_LARGE_ABS, 0 },
394+
{ 0, 0, "la.tls.ld", "r,l", INSN_LA_TLS_LD64, 0 },
395395
{ 0, 0, "la.tls.ld", "r,r,l", INSN_LA_TLS_LD64_LARGE_PCREL, 0 },
396-
{ 0, 0, "la.tls.gd", "r,l", INSN_LA_TLS_GD32, 0 },
397396
{ 0, 0, "la.tls.gd", "r,l", INSN_LA_TLS_GD32_ABS, 0 },
398-
{ 0, 0, "la.tls.gd", "r,l", INSN_LA_TLS_GD64, 0 },
397+
{ 0, 0, "la.tls.gd", "r,l", INSN_LA_TLS_GD32, 0 },
399398
{ 0, 0, "la.tls.gd", "r,l", INSN_LA_TLS_GD64_LARGE_ABS, 0 },
399+
{ 0, 0, "la.tls.gd", "r,l", INSN_LA_TLS_GD64, 0 },
400400
{ 0, 0, "la.tls.gd", "r,r,l", INSN_LA_TLS_GD64_LARGE_PCREL, 0 },
401401
{ 0, 0, "call36", "la", INSN_LA_CALL, 0 },
402402
{ 0, 0, "tail36", "r,la", INSN_LA_TAIL, 0 },

0 commit comments

Comments
 (0)