-
Notifications
You must be signed in to change notification settings - Fork 14.8k
MC: Refine ALIGN relocation conditions #150816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MaskRay
merged 6 commits into
main
from
users/MaskRay/spr/mc-refine-align-relocation-conditions
Aug 8, 2025
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,50 @@ | ||
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+c,+relax %s --defsym LATE=1 -o %t1 | ||
# RUN: llvm-objdump -dr --no-show-raw-insn -M no-aliases %t1 | FileCheck %s | ||
|
||
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+c,+relax %s -o %t0 | ||
# RUN: llvm-objdump -dr --no-show-raw-insn -M no-aliases %t0 | FileCheck %s --check-prefix=CHECK0 | ||
|
||
# CHECK: 6: c.nop | ||
# CHECK-EMPTY: | ||
# CHECK: 10: auipc ra, 0x0 | ||
# CHECK-NEXT: R_RISCV_CALL_PLT foo | ||
# CHECK-NEXT: R_RISCV_RELAX *ABS* | ||
# CHECK: 20: c.nop | ||
# CHECK-NEXT: R_RISCV_ALIGN *ABS*+0x6 | ||
|
||
## Alignment directives in a lower-numbered subsection may be conservatively treated as linker-relaxable. | ||
# CHECK0: 6: c.nop | ||
# CHECK0-NEXT: R_RISCV_ALIGN *ABS*+0x6 | ||
# CHECK0: 20: c.nop | ||
# CHECK0-NEXT: R_RISCV_ALIGN *ABS*+0x6 | ||
|
||
.text 2 | ||
.option push | ||
.option norelax | ||
## R_RISCV_ALIGN is required even if norelax, because it is after a linker-relaxable instruction. | ||
.balign 8 | ||
l2: | ||
.word 0x12345678 | ||
.option pop | ||
|
||
.text 1 | ||
.space 4 | ||
.ifdef LATE | ||
.space 0 | ||
.endif | ||
call foo | ||
.ifdef LATE | ||
.space 8 | ||
.else | ||
.space 4 | ||
.endif | ||
|
||
.text 0 | ||
_start: | ||
.space 6 | ||
.option push | ||
.option norelax | ||
.balign 8 | ||
l0: | ||
.word 0x12345678 | ||
.option pop |
This file contains hidden or 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 |
---|---|---|
@@ -1,8 +1,21 @@ | ||
# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-relax < %s \ | ||
# RUN: | llvm-readobj -r - | FileCheck %s | ||
|
||
# Check that .option relax overrides -mno-relax and enables R_RISCV_ALIGN | ||
# relocations. | ||
# CHECK: R_RISCV_ALIGN | ||
.option relax | ||
.align 4 | ||
## .option relax overrides -mno-relax and enables R_RISCV_ALIGN/R_RISCV_RELAX relocations. | ||
# CHECK: .rela.text | ||
# CHECK: R_RISCV_CALL_PLT | ||
# CHECK-NEXT: R_RISCV_RELAX | ||
# CHECK-NEXT: R_RISCV_ALIGN | ||
.option relax | ||
call foo | ||
.align 4 | ||
|
||
## Alignments before the first linker-relaxable instruction do not need relocations. | ||
# CHECK-NOT: .rela.text1 | ||
.section .text1,"ax" | ||
.align 4 | ||
nop | ||
|
||
# CHECK: .rela.text2 | ||
.section .text2,"ax" | ||
call foo |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: I made minimum changes to keep LoongArch tests passing but I do not intend to apply the ALIGN optimization (first behavior in the description).
Up to a LoongArch contributor to replace
if (!F.getSubtargetInfo()->hasFeature(LoongArch::FeatureRelax))
withif (F.getLayoutOrder() <= Sec->firstLinkerRelaxable())
and a few tests @SixWeining @MQ-mengqingNote: The RISC-V alignment tests are poorly organized, so please avoid following their example. You can create a more effective structure within the LoongArch/Relocations directory.