-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LoongArch] Insert nops and emit align reloc when handle alignment di…
…rective Refer to RISCV, we will fix up the alignment if linker relaxation changes code size and breaks alignment. Insert enough Nops and emit R_LARCH_ALIGN relocation type so that linker could satisfy the alignment by removing Nops. It does so only in sections with the SHF_EXECINSTR flag. In LoongArch psABI v2.30, R_LARCH_ALIGN requires symbol index. The lowest 8 bits of addend represent alignment and the other bits of addend represent the maximum number of bytes to emit.
- Loading branch information
1 parent
7b45c54
commit 4985669
Showing
6 changed files
with
174 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s \ | ||
# RUN: | llvm-readobj -r - | FileCheck --check-prefixes=CHECK,RELAX %s | ||
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=-relax %s \ | ||
# RUN: | llvm-readobj -r - | FileCheck %s | ||
|
||
.section ".dummy", "a" | ||
.L1: | ||
la.pcrel $t0, sym | ||
.p2align 3 | ||
.L2: | ||
.dword .L2 - .L1 | ||
|
||
# CHECK: Relocations [ | ||
# CHECK-NEXT: Section ({{.*}}) .rela.dummy { | ||
# CHECK-NEXT: 0x0 R_LARCH_PCALA_HI20 sym 0x0 | ||
# RELAX-NEXT: 0x0 R_LARCH_RELAX - 0x0 | ||
# CHECK-NEXT: 0x4 R_LARCH_PCALA_LO12 sym 0x0 | ||
# RELAX-NEXT: 0x4 R_LARCH_RELAX - 0x0 | ||
# RELAX-NEXT: 0x8 R_LARCH_ADD64 .L2 0x0 | ||
# RELAX-NEXT: 0x8 R_LARCH_SUB64 .L1 0x0 | ||
# CHECK-NEXT: } | ||
# CHECK-NEXT: ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=-relax %s \ | ||
# RUN: | llvm-readelf -rs - | FileCheck %s --check-prefix=NORELAX | ||
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s \ | ||
# RUN: | llvm-readelf -rs - | FileCheck %s --check-prefix=RELAX | ||
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s \ | ||
# RUN: | llvm-objdump -d - | FileCheck -check-prefix=RELAX-INST %s | ||
|
||
# NORELAX: There are no relocations in this file. | ||
# NORELAX: Symbol table '.symtab' contains 1 entries: | ||
|
||
# RELAX: 0000000000000000 0000000100000066 R_LARCH_ALIGN 0000000000000000 {{.*}} + 4 | ||
# RELAX-NEXT: 0000000000000010 0000000100000066 R_LARCH_ALIGN 0000000000000000 {{.*}} + 5 | ||
# RELAX-NEXT: 000000000000002c 0000000100000066 R_LARCH_ALIGN 0000000000000000 {{.*}} + 4 | ||
# RELAX-NEXT: 000000000000003c 0000000100000066 R_LARCH_ALIGN 0000000000000000 {{.*}} + b04 | ||
# RELAX-NEXT: 0000000000000048 0000000100000066 R_LARCH_ALIGN 0000000000000000 {{.*}} + 4 | ||
# RELAX-EMPTY: | ||
# RELAX: 0000000000000000 0000000200000066 R_LARCH_ALIGN 0000000000000000 <null> + 4 | ||
# RELAX-EMPTY: | ||
# RELAX: Symbol table '.symtab' contains 3 entries: | ||
# RELAX: 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND | ||
# RELAX-NEXT: 1: 0000000000000000 0 NOTYPE LOCAL DEFAULT 2 | ||
# RELAX-NEXT: 2: 0000000000000000 0 NOTYPE LOCAL DEFAULT 4 | ||
|
||
.text | ||
.p2align 4 # A = 0x0 | ||
nop | ||
.p2align 5 # B = A + 3 * NOP + NOP = 0x10 | ||
.p2align 4 # C = B + 7 * NOP = 0x2C | ||
nop | ||
.p2align 4, , 11 # D = C + 3 * NOP + NOP = 0x3C | ||
## Not emit the third parameter. | ||
.p2align 4, , 12 # E = D + 3 * NOP = 0x48 | ||
# END = E + 3 * NOP = 0x54 = 21 * NOP | ||
|
||
## Not emit R_LARCH_ALIGN if code alignment great than alignment directive. | ||
.p2align 2 | ||
.p2align 1 | ||
.p2align 0 | ||
## Not emit instructions if max emit bytes less than min nop size. | ||
.p2align 4, , 2 | ||
## Not emit R_LARCH_ALIGN if alignment directive with specific padding value. | ||
.p2align 4, 1 | ||
nop | ||
.p2align 4, 1, 12 | ||
|
||
# RELAX-INST: <.text>: | ||
# RELAX-INST-COUNT-21: nop | ||
# RELAX-INST-COUNT-3: 01 01 01 01 | ||
# RELAX-INST-NEXT: nop | ||
# RELAX-INST-COUNT-3: 01 01 01 01 | ||
|
||
.section .text2, "ax" | ||
.p2align 4 |