brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.4 KiB · 4d4d998 Raw
186 lines · plain
1# The file testing Nop insertion with R_RISCV_ALIGN for relaxation.2 3# Relaxation enabled: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 %s7# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+relax < %s \8# RUN:     | llvm-readobj -r - | FileCheck -check-prefix=RELAX-RELOC %s9 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 %s14# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-relax < %s \15# RUN:     | llvm-readobj -r - | FileCheck -check-prefix=NORELAX-RELOC %s16 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-OR-ZCA-EXT-RELAX-INST %s21# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c,+relax < %s \22# RUN:     | llvm-readobj -r - | FileCheck -check-prefix=C-OR-ZCA-EXT-RELAX-RELOC %s23 24# Relaxation enabled with Zca extension:25# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+zca,+relax < %s \26# RUN:     | llvm-objdump --mattr=+zca -d -M no-aliases - \27# RUN:     | FileCheck -check-prefix=C-OR-ZCA-EXT-RELAX-INST %s28# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+zca,+relax < %s \29# RUN:     | llvm-readobj -r - | FileCheck -check-prefix=C-OR-ZCA-EXT-RELAX-RELOC %s30 31# Relaxation disabled with C extension:32# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c,-relax < %s \33# RUN:     | llvm-objdump -d -M no-aliases - \34# RUN:     | FileCheck -check-prefix=C-OR-ZCA-EXT-NORELAX-INST %s35# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+c,-relax < %s \36# RUN:     | llvm-readobj -r - | FileCheck -check-prefix=C-OR-ZCA-EXT-NORELAX-RELOC %s37 38# Relaxation disabled with ZCA extension:39# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+zca,-relax < %s \40# RUN:     | llvm-objdump --mattr=+zca -d -M no-aliases - \41# RUN:     | FileCheck -check-prefix=C-OR-ZCA-EXT-NORELAX-INST %s42# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+zca,-relax < %s \43# RUN:     | llvm-readobj -r - | FileCheck -check-prefix=C-OR-ZCA-EXT-NORELAX-RELOC %s44 45# We need to insert N-MinNopSize bytes NOPs and R_RISCV_ALIGN relocation46# type for .align N directive when linker relaxation enabled.47# Linker could satisfy alignment by removing NOPs after linker relaxation.48 49test:50## Start with a linker-relaxable instruction so that the following alignment can be relaxable.51	call foo52# NORELAX-RELOC:              R_RISCV_CALL_PLT53# C-OR-ZCA-EXT-NORELAX-RELOC: R_RISCV_CALL_PLT54 55	.p2align 256# If the +c extension is enabled, the text section will be 2-byte aligned, so57# one c.nop instruction is sufficient.58# C-OR-ZCA-EXT-RELAX-RELOC: R_RISCV_ALIGN - 0x259# C-OR-ZCA-EXT-RELAX-INST:  c.nop60	bne     zero, a0, .LBB0_261	mv	a0, zero62	.p2align 363# RELAX-RELOC: R_RISCV_ALIGN - 0x664# RELAX-INST:  addi    zero, zero, 065# C-OR-ZCA-EXT-RELAX-RELOC: R_RISCV_ALIGN - 0x666# C-OR-ZCA-EXT-RELAX-INST:  c.nop67# C-OR-ZCA-EXT-RELAX-INST:  addi    zero, zero, 068# C-OR-ZCA-EXT-NORELAX-INST: addi    zero, zero, 069	add	a0, a0, a170	.align 471.LBB0_2:72# RELAX-RELOC: R_RISCV_ALIGN - 0xE73# RELAX-INST:  addi    zero, zero, 074# RELAX-INST:  addi    zero, zero, 075# RELAX-INST:  addi    zero, zero, 076# NORELAX-INST: addi    zero, zero, 077# C-OR-ZCA-EXT-RELAX-RELOC: R_RISCV_ALIGN - 0xE78# C-OR-ZCA-EXT-RELAX-INST:  addi    zero, zero, 079# C-OR-ZCA-EXT-RELAX-INST:  addi    zero, zero, 080# C-OR-ZCA-EXT-RELAX-INST:  addi    zero, zero, 081# C-OR-ZCA-EXT-RELAX-INST:  c.nop82# C-EXT-INST: addi    zero, zero, 083# C-EXT-INST: c.nop84	add	a0, a0, a185	.p2align 386.constant_pool:87.long	312677019388# RELAX-RELOC: R_RISCV_ALIGN - 0x689# RELAX-INST:  addi    zero, zero, 090# NORELAX-INST: addi    zero, zero, 091# C-OR-ZCA-EXT-RELAX-RELOC: R_RISCV_ALIGN - 0x692# C-OR-ZCA-EXT-RELAX-INST:  addi    zero, zero, 093# C-OR-ZCA-EXT-RELAX-INST-NOT:  c.nop94# C-EXT-INST: addi    zero, zero, 095# C-EXT-INST: c.nop96	add	a0, a0, a197# Alignment directive with specific padding value 0x01.98# We will not emit R_RISCV_ALIGN in this case.99# The behavior is the same as GNU assembler.100	.p2align 4, 1101# RELAX-RELOC-NOT: R_RISCV_ALIGN - 0xC102# RELAX-INST:  0101103# RELAX-INST:  0101104# C-OR-ZCA-EXT-RELAX-RELOC-NOT: R_RISCV_ALIGN - 0xE105# C-OR-ZCA-EXT-RELAX-INST:  0101106# C-EXT-INST:  0101107	ret108# NORELAX-RELOC-NOT: R_RISCV109# C-OR-ZCA-EXT-NORELAX-RELOC-NOT: R_RISCV110# Code alignment of a byte size less than the size of a nop must be treated111# as no alignment. This used to trigger a fatal error with relaxation enabled112# as the calculation to emit the worst-case sequence of nops would overflow.113	.p2align        1114	add	a0, a0, a1115	.p2align        0116	add	a0, a0, a1117# We only need to insert R_RISCV_ALIGN for code section118# when the linker relaxation enabled.119        .data120	.p2align        3121# RELAX-RELOC-NOT: R_RISCV_ALIGN122# C-OR-ZCA-EXT-RELAX-RELOC-NOT: R_RISCV_ALIGN123data1:124	.word 7125	.p2align        4126# RELAX-RELOC-NOT: R_RISCV_ALIGN127# C-OR-ZCA-EXT-RELAX-RELOC-NOT: R_RISCV_ALIGN128data2:129	.word 9130# Check that the initial alignment is properly handled when using .option to131# disable the C extension. This used to crash.132# C-OR-ZCA-EXT-RELAX-INST:      <.text2>:133# C-OR-ZCA-EXT-RELAX-INST-NEXT: add a0, a0, a1134	.section .text2, "x"135	.option norvc136	.balign 4137	add	a0, a0, a1138 139## Branches crossing the linker-relaxable R_RISCV_ALIGN need relocations.140# RELAX-RELOC-NOT:  .rela.text3 {141# C-OR-ZCA-EXT-RELAX-RELOC-NOT:  .rela.text3 {142	.section .text3, "ax"143	bnez t1, 1f144	bnez t2, 2f1451:146	.p2align 31472:148	bnez t1, 1b149	bnez t1, 2b150 151## .text3 with a call at the start152# NORELAX-RELOC:    .rela.text3a153# RELAX-RELOC:      .rela.text3a {154# RELAX-RELOC-NEXT:    0x0  R_RISCV_CALL_PLT foo 0x0155# RELAX-RELOC-NEXT:    0x0  R_RISCV_RELAX - 0x0156# RELAX-RELOC-NEXT:    0xC  R_RISCV_BRANCH .Ltmp[[#]] 0x0157# RELAX-RELOC-NEXT:    0x10 R_RISCV_ALIGN - 0x6158# RELAX-RELOC-NEXT:    0x16 R_RISCV_BRANCH .Ltmp[[#]] 0x0159# RELAX-RELOC-NEXT: }160# C-OR-ZCA-EXT-NORELAX-RELOC: .rela.text3a161# C-OR-ZCA-EXT-RELAX-RELOC: .rela.text3a162.section .text3a, "ax"163call foo164bnez t1, 1f165bnez t2, 2f1661:167.p2align 31682:169bnez t1, 1b170bnez t1, 2b171 172## .text3 with a call at the end173# RELAX-RELOC:      .rela.text3b {174# RELAX-RELOC-NEXT:    0x10 R_RISCV_CALL_PLT foo 0x0175# RELAX-RELOC-NEXT:    0x10 R_RISCV_RELAX - 0x0176# RELAX-RELOC-NEXT: }177.section .text3b, "ax"178bnez t1, 1f179bnez t2, 2f1801:181.p2align 31822:183bnez t1, 1b184bnez t1, 2b185call foo186