-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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 (#72962) 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
c41472d
commit c51ab48
Showing
6 changed files
with
203 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,27 @@ | ||
## A label difference separated by an alignment directive, when the | ||
## referenced symbols are in a non-executable section with instructions, | ||
## should generate ADD/SUB relocations. | ||
## https://github.com/llvm/llvm-project/pull/76552 | ||
|
||
# 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,79 @@ | ||
## The file testing Nop insertion with R_LARCH_ALIGN for relaxation. | ||
|
||
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=-relax %s -o %t | ||
# RUN: llvm-objdump -d %t | FileCheck %s --check-prefix=INSTR | ||
# RUN: llvm-readobj -r %t | FileCheck %s --check-prefix=RELOC | ||
# RUN: llvm-mc --filetype=obj --triple=loongarch64 --mattr=+relax %s -o %t.r | ||
# RUN: llvm-objdump -d %t.r | FileCheck %s --check-prefixes=INSTR,RELAX-INSTR | ||
# RUN: llvm-readobj -r %t.r | FileCheck %s --check-prefixes=RELOC,RELAX-RELOC | ||
|
||
.text | ||
break 0 | ||
# INSTR: break 0 | ||
|
||
## Not emit R_LARCH_ALIGN if alignment directive is less than or equal to | ||
## minimum code alignment(a.k.a 4). | ||
.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. | ||
## The behavior is the same as GNU assembler. | ||
break 1 | ||
.p2align 4, 1 | ||
# INSTR-NEXT: break 1 | ||
# INSTR-COUNT-2: 01 01 01 01 | ||
|
||
break 2 | ||
.p2align 4, 1, 12 | ||
# INSTR-NEXT: break 2 | ||
# INSTR-COUNT-3: 01 01 01 01 | ||
|
||
break 3 | ||
.p2align 4 | ||
# INSTR-NEXT: break 3 | ||
# INSTR-COUNT-3: nop | ||
|
||
break 4 | ||
.p2align 5 | ||
.p2align 4 | ||
# INSTR-NEXT: break 4 | ||
# INSTR-COUNT-3: nop | ||
# RELAX-INSTR-COUNT-7: nop | ||
|
||
break 5 | ||
.p2align 4, , 11 | ||
# INSTR-NEXT: break 5 | ||
# RELAX-INSTR-COUNT-3: nop | ||
|
||
break 6 | ||
## Not emit the third parameter. | ||
.p2align 4, , 12 | ||
# INSTR-NEXT: break 6 | ||
# INSTR-NEXT: nop | ||
# INSTR-NEXT: nop | ||
# RELAX-INSTR-NEXT: nop | ||
|
||
ret | ||
# INSNR-NEXT: ret | ||
|
||
## Test the symbol index is different from .text. | ||
.section .text2, "ax" | ||
.p2align 4 | ||
break 7 | ||
|
||
# RELOC: Relocations [ | ||
# RELAX-RELOC-NEXT: Section ({{.*}}) .rela.text { | ||
# RELAX-RELOC-NEXT: 0x24 R_LARCH_ALIGN .Lla-relax-align0 0x4 | ||
# RELAX-RELOC-NEXT: 0x34 R_LARCH_ALIGN .Lla-relax-align0 0x5 | ||
# RELAX-RELOC-NEXT: 0x50 R_LARCH_ALIGN .Lla-relax-align0 0x4 | ||
# RELAX-RELOC-NEXT: 0x60 R_LARCH_ALIGN .Lla-relax-align0 0xB04 | ||
# RELAX-RELOC-NEXT: 0x70 R_LARCH_ALIGN .Lla-relax-align0 0x4 | ||
# RELAX-RELOC-NEXT: } | ||
# RELAX-RELOC-NEXT: Section ({{.*}}) .rela.text2 { | ||
# RELAX-RELOC-NEXT: 0x0 R_LARCH_ALIGN .Lla-relax-align1 0x4 | ||
# RELAX-RELOC-NEXT: } | ||
# RELOC-NEXT: ] |