1 # The file testing Nop insertion with R_RISCV_ALIGN for relaxation.
4 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+relax < %s \
5 # RUN: | llvm-objdump -d -M no-aliases - \
6 # RUN: | FileCheck -check-prefix=RELAX-INST %s
7 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+relax < %s \
8 # RUN: | llvm-readobj -r | FileCheck -check-prefix=RELAX-RELOC %s
10 # Relaxation disabled:
11 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-relax < %s \
12 # RUN: | llvm-objdump -d -M no-aliases - \
13 # RUN: | FileCheck -check-prefix=NORELAX-INST %s
14 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-relax < %s \
15 # RUN: | llvm-readobj -r | FileCheck -check-prefix=NORELAX-RELOC %s
17 # Relaxation enabled with C extension:
18 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c,+relax < %s \
19 # RUN: | llvm-objdump -d -M no-aliases - \
20 # RUN: | FileCheck -check-prefix=C-EXT-RELAX-INST %s
21 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c,+relax < %s \
22 # RUN: | llvm-readobj -r | FileCheck -check-prefix=C-EXT-RELAX-RELOC %s
24 # Relaxation disabled with C extension:
25 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c,-relax < %s \
26 # RUN: | llvm-objdump -d -M no-aliases - \
27 # RUN: | FileCheck -check-prefix=C-EXT-NORELAX-INST %s
28 # RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c,-relax < %s \
29 # RUN: | llvm-readobj -r | FileCheck -check-prefix=C-EXT-NORELAX-RELOC %s
31 # We need to insert N-MinNopSize bytes NOPs and R_RISCV_ALIGN relocation
32 # type for .align N directive when linker relaxation enabled.
33 # Linker could satisfy alignment by removing NOPs after linker relaxation.
35 # The first R_RISCV_ALIGN come from
36 # MCELFStreamer::InitSections() EmitCodeAlignment(4).
37 # C-EXT-RELAX-RELOC: R_RISCV_ALIGN - 0x2
38 # C-EXT-RELAX-INST: c.nop
41 # C-EXT-RELAX-RELOC: R_RISCV_ALIGN - 0x2
42 # C-EXT-RELAX-INST: c.nop
46 # RELAX-RELOC: R_RISCV_ALIGN - 0x4
47 # RELAX-INST: addi zero, zero, 0
48 # C-EXT-RELAX-RELOC: R_RISCV_ALIGN - 0x6
49 # C-EXT-RELAX-INST: addi zero, zero, 0
50 # C-EXT-RELAX-INST: c.nop
51 # C-EXT-NORELAX-INST: addi zero, zero, 0
55 # RELAX-RELOC: R_RISCV_ALIGN - 0xC
56 # RELAX-INST: addi zero, zero, 0
57 # RELAX-INST: addi zero, zero, 0
58 # RELAX-INST: addi zero, zero, 0
59 # NORELAX-INST: addi zero, zero, 0
60 # C-EXT-RELAX-RELOC: R_RISCV_ALIGN - 0xE
61 # C-EXT-RELAX-INST: addi zero, zero, 0
62 # C-EXT-RELAX-INST: addi zero, zero, 0
63 # C-EXT-RELAX-INST: addi zero, zero, 0
64 # C-EXT-RELAX-INST: c.nop
65 # C-EXT-INST: addi zero, zero, 0
71 # RELAX-RELOC: R_RISCV_ALIGN - 0x4
72 # RELAX-INST: addi zero, zero, 0
73 # NORELAX-INST: addi zero, zero, 0
74 # C-EXT-RELAX-RELOC: R_RISCV_ALIGN - 0x6
75 # C-EXT-RELAX-INST: addi zero, zero, 0
76 # C-EXT-RELAX-INST: c.nop
77 # C-EXT-INST: addi zero, zero, 0
80 # Alignment directive with specific padding value 0x01.
81 # We will not emit R_RISCV_ALIGN in this case.
82 # The behavior is the same as GNU assembler.
84 # RELAX-RELOC-NOT: R_RISCV_ALIGN - 0xC
87 # C-EXT-RELAX-RELOC-NOT: R_RISCV_ALIGN - 0xE
88 # C-EXT-RELAX-INST: 01 01
91 # NORELAX-RELOC-NOT: R_RISCV
92 # C-EXT-NORELAX-RELOC-NOT: R_RISCV
93 # Code alignment of a byte size less than the size of a nop must be treated
94 # as no alignment. This used to trigger a fatal error with relaxation enabled
95 # as the calculation to emit the worst-case sequence of nops would overflow.
100 # We only need to insert R_RISCV_ALIGN for code section
101 # when the linker relaxation enabled.
104 # RELAX-RELOC-NOT: R_RISCV_ALIGN
105 # C-EXT-RELAX-RELOC-NOT: R_RISCV_ALIGN
109 # RELAX-RELOC-NOT: R_RISCV_ALIGN
110 # C-EXT-RELAX-RELOC-NOT: R_RISCV_ALIGN