File: loongarch-relax-align.s

package info (click to toggle)
swiftlang 6.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,604 kB
  • sloc: cpp: 9,901,740; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (126 lines) | stat: -rw-r--r-- 3,943 bytes parent folder | download | duplicates (8)
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
# REQUIRES: loongarch

# RUN: llvm-mc --filetype=obj --triple=loongarch32 --mattr=+relax %s -o %t.32.o
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.64.o
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.32.o -o %t.32
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.64.o -o %t.64
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.32.o --no-relax -o %t.32n
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.64.o --no-relax -o %t.64n
# RUN: llvm-objdump -td --no-show-raw-insn %t.32 | FileCheck %s
# RUN: llvm-objdump -td --no-show-raw-insn %t.64 | FileCheck %s
# RUN: llvm-objdump -td --no-show-raw-insn %t.32n | FileCheck %s
# RUN: llvm-objdump -td --no-show-raw-insn %t.64n | FileCheck %s

## Test the R_LARCH_ALIGN without symbol index.
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.o64.o --defsym=old=1
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.o64.o -o %t.o64
# RUN: ld.lld --section-start=.text=0x10000 --section-start=.text2=0x20000 -e 0 %t.o64.o --no-relax -o %t.o64n
# RUN: llvm-objdump -td --no-show-raw-insn %t.o64 | FileCheck %s
# RUN: llvm-objdump -td --no-show-raw-insn %t.o64n | FileCheck %s

## -r keeps section contents unchanged.
# RUN: ld.lld -r %t.64.o -o %t.64.r
# RUN: llvm-objdump -dr --no-show-raw-insn %t.64.r | FileCheck %s --check-prefix=CHECKR

# CHECK-DAG: {{0*}}10000 l .text  {{0*}}44 .Ltext_start
# CHECK-DAG: {{0*}}10038 l .text  {{0*}}0c .L1
# CHECK-DAG: {{0*}}10040 l .text  {{0*}}04 .L2
# CHECK-DAG: {{0*}}20000 l .text2 {{0*}}14 .Ltext2_start

# CHECK:      <.Ltext_start>:
# CHECK-NEXT:   break 1
# CHECK-NEXT:   break 2
# CHECK-NEXT:   nop
# CHECK-NEXT:   nop
# CHECK-NEXT:   break 3
# CHECK-NEXT:   break 4
# CHECK-NEXT:   nop
# CHECK-NEXT:   nop
# CHECK-NEXT:   pcalau12i     $a0, 0
# CHECK-NEXT:   addi.{{[dw]}} $a0, $a0, 0
# CHECK-NEXT:   pcalau12i     $a0, 0
# CHECK-NEXT:   addi.{{[dw]}} $a0, $a0, 56
# CHECK-NEXT:   pcalau12i     $a0, 0
# CHECK-NEXT:   addi.{{[dw]}} $a0, $a0, 64
# CHECK-EMPTY:
# CHECK-NEXT: <.L1>:
# CHECK-NEXT:   nop
# CHECK-NEXT:   nop
# CHECK-EMPTY:
# CHECK-NEXT: <.L2>:
# CHECK-NEXT:   break 5

# CHECK:      <.Ltext2_start>:
# CHECK-NEXT:   pcalau12i     $a0, 0
# CHECK-NEXT:   addi.{{[dw]}} $a0, $a0, 0
# CHECK-NEXT:   nop
# CHECK-NEXT:   nop
# CHECK-NEXT:   break 6

# CHECKR:      <.Ltext2_start>:
# CHECKR-NEXT:   pcalau12i $a0, 0
# CHECKR-NEXT:   {{0*}}00: R_LARCH_PCALA_HI20 .Ltext2_start
# CHECKR-NEXT:   {{0*}}00: R_LARCH_RELAX      *ABS*
# CHECKR-NEXT:   addi.d    $a0, $a0, 0
# CHECKR-NEXT:   {{0*}}04: R_LARCH_PCALA_LO12 .Ltext2_start
# CHECKR-NEXT:   {{0*}}04: R_LARCH_RELAX      *ABS*
# CHECKR-NEXT:   nop
# CHECKR-NEXT:   {{0*}}08: R_LARCH_ALIGN      .Lalign_symbol+0x4
# CHECKR-NEXT:   nop
# CHECKR-NEXT:   nop
# CHECKR-NEXT:   break 6

.macro .fake_p2align_4 max=0
  .ifdef old
    .if \max==0
      .reloc ., R_LARCH_ALIGN, 0xc
      nop; nop; nop
    .endif
  .else
    .reloc ., R_LARCH_ALIGN, .Lalign_symbol + 0x4 + (\max << 8)
    nop; nop; nop
  .endif
.endm

  .text
.Lalign_symbol:
.Ltext_start:
  break 1
  break 2
## +0x8: Emit 2 nops, delete 1 nop.
  .fake_p2align_4

  break 3
## +0x14: Emit 3 nops > 8 bytes, not emit.
  .fake_p2align_4 8

  break 4
  .fake_p2align_4 8
## +0x18: Emit 2 nops <= 8 bytes.

## Compensate
.ifdef old
  nop; nop
.endif

## +0x20: Test symbol value and symbol size can be handled.
  la.pcrel $a0, .Ltext_start
  la.pcrel $a0, .L1
  la.pcrel $a0, .L2

## +0x38: Emit 2 nops, delete 1 nop.
.L1:
  .fake_p2align_4
.L2:
  break 5
  .size .L1, . - .L1
  .size .L2, . - .L2
  .size .Ltext_start, . - .Ltext_start

## Test another text section.
  .section .text2,"ax",@progbits
.Ltext2_start:
  la.pcrel $a0, .Ltext2_start
  .fake_p2align_4
  break 6
  .size .Ltext2_start, . - .Ltext2_start