forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RISCV][MC] Add CLI option to disable branch relaxation
D154958 enables branch relaxation for unresolved symbols. This has an interesting consequence for some LLD tests: branch relocations are tested by using branches to undefined symbols and defining them, with different values, on the LLD command line. These tests broke and there doesn't seem to be an easy workaround: as far as I can tell, there is no way to convince llvm-mc to emit a branch relocation to an undefined symbol without branch relaxation kicking in. This patch proposes to add a flag, `-riscv-asm-relax-branches=0`, to do just that. The main purpose for this flag is for testing but it might be seen as a first step to some kind of "strict" or WYSIWYG mode (i.e., what you give to the assembler is exactly what comes out). The need for this has been mentioned in, for example, D108961. However, I suspect there will be a lot of discussion around what exactly such a strict mode would look like. Therefore, I gated this feature behind a CLI flag instead of adding a new target feature. Reviewed By: asb, MaskRay Differential Revision: https://reviews.llvm.org/D155953
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
## Test that long branches are not relaxed with -riscv-asm-relax-branches=0 | ||
# RUN: split-file %s %t | ||
# RUN: llvm-mc -filetype=obj -triple=riscv64 -mattr=+c \ | ||
# RUN: -riscv-asm-relax-branches=0 %t/pass.s \ | ||
# RUN: | llvm-objdump -dr -M no-aliases - \ | ||
# RUN: | FileCheck %t/pass.s | ||
# RUN: not llvm-mc -filetype=obj -triple=riscv64 -mattr=+c -o /dev/null \ | ||
# RUN: -riscv-asm-relax-branches=0 %t/fail.s 2>&1 \ | ||
# RUN: | FileCheck %t/fail.s | ||
|
||
#--- pass.s | ||
.text | ||
test_undefined: | ||
## Branches to undefined symbols should not be relaxed | ||
# CHECK: bne a0, a1, {{.*}} | ||
# CHECK-NEXT: R_RISCV_BRANCH foo | ||
bne a0, a1, foo | ||
# CHECK: c.beqz a0, {{.*}} | ||
# CHECK-NEXT: R_RISCV_RVC_BRANCH foo | ||
c.beqz a0, foo | ||
# CHECK: c.j {{.*}} | ||
# CHECK-NEXT: R_RISCV_RVC_JUMP foo | ||
c.j foo | ||
|
||
## Branches to defined in-range symbols should work normally | ||
test_defined_in_range: | ||
# CHECK: bne a0, a1, {{.*}} <bar> | ||
bne a0, a1, bar | ||
# CHECK: c.beqz a0, {{.*}} <bar> | ||
c.beqz a0, bar | ||
# CHECK: c.j {{.*}} <bar> | ||
c.j bar | ||
bar: | ||
|
||
#--- fail.s | ||
.text | ||
## Branches to defined out-of-range symbols should report an error | ||
test_defined_out_of_range: | ||
bne a0, a1, 1f # CHECK: :[[#@LINE]]:3: error: fixup value out of range | ||
.skip (1 << 12) | ||
1: | ||
c.beqz a0, 1f # CHECK: :[[#@LINE]]:3: error: fixup value out of range | ||
.skip (1 << 8) | ||
1: | ||
c.j 1f # CHECK: :[[#@LINE]]:3: error: fixup value out of range | ||
.skip (1 << 11) | ||
1: |