Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lld / test / ELF / riscv-relax-align.s
blob8a46d601d4ef03a4de45a7f5ae6632ac8bd3fd49
1 # REQUIRES: riscv
2 ## Test that we can handle R_RISCV_ALIGN.
4 # RUN: rm -rf %t && mkdir %t && cd %t
6 # RUN: llvm-mc -filetype=obj -triple=riscv32 -mattr=+relax %s -o 32.o
7 # RUN: ld.lld -Ttext=0x10000 32.o -o 32
8 # RUN: llvm-objdump -td --no-show-raw-insn -M no-aliases 32 | FileCheck %s
9 ## R_RISCV_ALIGN is handled regarldess of --no-relax.
10 # RUN: ld.lld -Ttext=0x10000 --no-relax 32.o -o 32.norelax
11 # RUN: llvm-objdump -td --no-show-raw-insn -M no-aliases 32.norelax | FileCheck %s
13 # RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+relax %s -o 64.o
14 # RUN: ld.lld -Ttext=0x10000 64.o -o 64
15 # RUN: llvm-objdump -td --no-show-raw-insn -M no-aliases 64 | FileCheck %s
16 # RUN: ld.lld -Ttext=0x10000 --no-relax 64.o -o 64.norelax
17 # RUN: llvm-objdump -td --no-show-raw-insn -M no-aliases 64.norelax | FileCheck %s
19 # RUN: ld.lld -Ttext=0x10000 --gc-sections 64.o -o 64.gc
20 # RUN: llvm-objdump -td --no-show-raw-insn -M no-aliases 64.gc | FileCheck %s --check-prefix=GC
22 ## -r keeps section contents unchanged.
23 # RUN: ld.lld -r 64.o -o 64.r
24 # RUN: llvm-objdump -dr --no-show-raw-insn -M no-aliases 64.r | FileCheck %s --check-prefix=CHECKR
26 # CHECK-DAG: 00010004 l .text {{0*}}1c a
27 # CHECK-DAG: 00010008 l .text {{0*}}28 b
28 # CHECK-DAG: 00010014 l .text {{0*}}20 c
29 # CHECK-DAG: 00010000 g .text {{0*}}38 _start
31 # CHECK: <_start>:
32 # CHECK-NEXT: addi a0, a0, 1
33 # CHECK-EMPTY:
34 # CHECK-NEXT: <a>:
35 # CHECK-NEXT: addi a0, a0, 2
36 # CHECK-EMPTY:
37 # CHECK-NEXT: <b>:
38 # CHECK-NEXT: addi zero, zero, 0
39 # CHECK-NEXT: addi zero, zero, 0
40 # CHECK-NEXT: 10010: addi a0, a0, 3
41 # CHECK-EMPTY:
42 # CHECK-NEXT: <c>:
43 # CHECK-NEXT: addi a0, a0, 4
44 # CHECK-NEXT: addi a0, a0, 5
45 # CHECK-NEXT: addi zero, zero, 0
46 # CHECK-NEXT: 10020: addi a0, a0, 6
47 # CHECK-NEXT: addi a0, a0, 7
48 # CHECK-NEXT: addi zero, zero, 0
49 # CHECK-NEXT: addi zero, zero, 0
50 # CHECK-NEXT: 10030: addi a0, a0, 8
51 # CHECK-NEXT: addi a0, a0, 9
52 # CHECK-EMPTY:
53 # CHECK: <e>:
54 # CHECK-NEXT: addi a0, a0, 1
55 # CHECK-EMPTY:
56 # CHECK-NEXT: <f>:
57 # CHECK-NEXT: 10044: addi a0, a0, 2
58 # CHECK-NEXT: addi zero, zero, 0
59 # CHECK-NEXT: addi zero, zero, 0
60 # CHECK-NEXT: addi zero, zero, 0
61 # CHECK-NEXT: addi zero, zero, 0
62 # CHECK-NEXT: addi zero, zero, 0
63 # CHECK-NEXT: addi zero, zero, 0
64 # CHECK-NEXT: 10060: addi a0, a0, 3
65 # CHECK-EMPTY:
67 ## _start-0x10070 = 0x10000-0x10070 = -112
68 # CHECK: <.L1>:
69 # CHECK-NEXT: 10070: auipc a0, 0
70 # CHECK-NEXT: addi a0, a0, -112
71 # CHECK-NEXT: addi zero, zero, 0
72 # CHECK-NEXT: addi zero, zero, 0
73 # CHECK-NEXT: auipc a0, 0
74 # CHECK-NEXT: addi a0, a0, -112
75 # CHECK-EMPTY:
77 # GC-DAG: 00010004 l .text {{0*}}1c a
78 # GC-DAG: 00010008 l .text {{0*}}28 b
79 # GC-DAG: 00010014 l .text {{0*}}20 c
80 # GC-DAG: 00010000 g .text {{0*}}38 _start
81 # GC: <_start>:
82 # GC-NOT: <d>:
84 # CHECKR: <_start>:
85 # CHECKR-NEXT: addi a0, a0, 1
86 # CHECKR-EMPTY:
87 # CHECKR-NEXT: <a>:
88 # CHECKR-NEXT: addi a0, a0, 2
89 # CHECKR-EMPTY:
90 # CHECKR-NEXT: <b>:
91 # CHECKR-NEXT: addi zero, zero, 0
92 # CHECKR-NEXT: 0000000000000008: R_RISCV_ALIGN *ABS*+0xc
93 # CHECKR-NEXT: addi zero, zero, 0
94 # CHECKR-NEXT: addi zero, zero, 0
95 # CHECKR-NEXT: addi a0, a0, 3
96 # CHECKR-EMPTY:
97 # CHECKR-NEXT: <c>:
98 # CHECKR-NEXT: addi a0, a0, 4
99 # CHECKR-NEXT: addi a0, a0, 5
100 # CHECKR-NEXT: addi zero, zero, 0
101 # CHECKR-NEXT: 0000000000000020: R_RISCV_ALIGN *ABS*+0x1c
102 # CHECKR-NEXT: addi zero, zero, 0
103 # CHECKR-NEXT: addi zero, zero, 0
104 # CHECKR-NEXT: addi zero, zero, 0
105 # CHECKR-NEXT: addi zero, zero, 0
106 # CHECKR-NEXT: addi zero, zero, 0
107 # CHECKR-NEXT: addi zero, zero, 0
108 # CHECKR-NEXT: addi a0, a0, 6
109 # CHECKR-NEXT: addi a0, a0, 7
110 # CHECKR-NEXT: addi zero, zero, 0
111 # CHECKR-NEXT: 0000000000000044: R_RISCV_ALIGN *ABS*+0xc
112 # CHECKR-NEXT: addi zero, zero, 0
113 # CHECKR-NEXT: addi zero, zero, 0
114 # CHECKR-NEXT: addi a0, a0, 8
115 # CHECKR-NEXT: addi a0, a0, 9
117 .global _start
118 _start:
119 addi a0, a0, 1
121 addi a0, a0, 2
123 .balign 16
124 addi a0, a0, 3
126 addi a0, a0, 4
127 addi a0, a0, 5
128 .balign 32
129 .size a, . - a
130 addi a0, a0, 6
131 addi a0, a0, 7
132 .balign 16
133 .size b, . - b
134 addi a0, a0, 8
135 .size c, . - c
136 addi a0, a0, 9
137 .size _start, . - _start
139 ## Test another text section.
140 .section .text2,"ax",@progbits
143 .balign 8
144 addi a0, a0, 1
146 addi a0, a0, 2
147 .balign 32
148 .size d, . - d
149 addi a0, a0, 3
150 .size e, . - e
151 .size f, . - f
153 ## Test that matching HI20 can be found despite deleted bytes.
154 .section .pcrel,"ax",@progbits
155 .L1:
156 auipc a0, %pcrel_hi(_start)
157 addi a0, a0, %pcrel_lo(.L1)
158 .balign 16
159 .L2:
160 auipc a0, %pcrel_hi(_start)
161 addi a0, a0, %pcrel_lo(.L1)