-
Couldn't load subscription status.
- Fork 15k
[RISCV] Add initial assembler/MC layer support for big-endian #146534
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
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0488910
[RISCV] Add initial assembler/MC layer support for big-endian
djtodoro 8367541
[RISCV] Add tests for BE
djtodoro 23b5958
Address comments
djtodoro 2bdee6c
Address comments
djtodoro c4f0fd3
Apply refactor
djtodoro fc33888
Improve tests
djtodoro a69a66e
Remove fixup_riscv_*
djtodoro da4ad8b
Apply clang-format
djtodoro 7b766e8
Drop BE support from TargetLoweringObjectFileImpl
djtodoro 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
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,29 @@ | ||
| # RUN: llvm-mc --disassemble %s -triple=riscv32be -mattr=+c 2>&1 | FileCheck %s | ||
| # RUN: llvm-mc --disassemble %s -triple=riscv64be -mattr=+c 2>&1 | FileCheck %s | ||
|
|
||
| # Test basic disassembly for big-endian RISC-V | ||
| # Instructions are always little-endian encoded in RISC-V | ||
|
|
||
| [0x13,0x05,0x45,0x06] | ||
| # CHECK: addi a0, a0, 100 | ||
|
|
||
| [0xb7,0x52,0x34,0x12] | ||
| # CHECK: lui t0, 74565 | ||
|
|
||
| [0x03,0x26,0x05,0x00] | ||
| # CHECK: lw a2, 0(a0) | ||
|
|
||
| [0x23,0x22,0xc5,0x00] | ||
| # CHECK: sw a2, 4(a0) | ||
|
|
||
| [0xef,0x00,0x00,0x00] | ||
| # CHECK: jal 0 | ||
|
|
||
| [0x63,0x00,0xb5,0x00] | ||
| # CHECK: beq a0, a1, 0 | ||
|
|
||
| [0x01,0x00] | ||
| # CHECK: nop | ||
|
|
||
| [0x05,0x05] | ||
| # CHECK: addi a0, a0, 1 |
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,101 @@ | ||
| # RUN: llvm-mc --triple=riscv32be %s --show-encoding \ | ||
| # RUN: | FileCheck --check-prefixes=CHECK-FIXUP,CHECK-ENCODING %s | ||
| # RUN: llvm-mc --filetype=obj --triple=riscv32be %s \ | ||
| # RUN: | llvm-objdump -d - | FileCheck --check-prefix=CHECK-INSTR %s | ||
| # RUN: llvm-mc --filetype=obj --triple=riscv32be %s \ | ||
| # RUN: | llvm-readobj -r - | FileCheck --check-prefix=CHECK-REL %s | ||
|
|
||
| # RUN: llvm-mc --triple=riscv64be %s --show-encoding \ | ||
| # RUN: | FileCheck --check-prefixes=CHECK-FIXUP,CHECK-ENCODING %s | ||
| # RUN: llvm-mc --filetype=obj --triple=riscv64be %s \ | ||
| # RUN: | llvm-objdump -d - | FileCheck --check-prefix=CHECK-INSTR %s | ||
| # RUN: llvm-mc --filetype=obj --triple=riscv64be %s \ | ||
| # RUN: | llvm-readobj -r - | FileCheck --check-prefix=CHECK-REL %s | ||
|
|
||
| ## Checks that fixups that can be resolved within the same object file are | ||
| ## applied correctly on big-endian RISC-V targets. | ||
| ## | ||
| ## This test verifies that RISC-V instructions remain little-endian even on | ||
| ## big-endian systems. This is a fundamental property of RISC-V: | ||
| ## - Instructions are always little-endian | ||
| ## - Data can be big-endian or little-endian depending on the system | ||
|
|
||
| .LBB0: | ||
| addi t0, t0, 1 | ||
| # CHECK-ENCODING: encoding: [0x93,0x82,0x12,0x00] | ||
| # CHECK-INSTR: addi t0, t0, 0x1 | ||
|
|
||
| lui t1, %hi(val) | ||
| # CHECK-ENCODING: encoding: [0x37,0bAAAA0011,A,A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: %hi(val), kind: fixup_riscv_hi20 | ||
| # CHECK-INSTR: lui t1, 0x12345 | ||
|
|
||
| lw a0, %lo(val)(t1) | ||
| # CHECK-ENCODING: encoding: [0x03,0x25,0bAAAA0011,A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: %lo(val), kind: fixup_riscv_lo12_i | ||
| # CHECK-INSTR: lw a0, 0x678(t1) | ||
|
|
||
| addi a1, t1, %lo(val) | ||
| # CHECK-ENCODING: encoding: [0x93,0x05,0bAAAA0011,A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: %lo(val), kind: fixup_riscv_lo12_i | ||
| # CHECK-INSTR: addi a1, t1, 0x678 | ||
|
|
||
| sw a0, %lo(val)(t1) | ||
| # CHECK-ENCODING: encoding: [0x23'A',0x20'A',0xa3'A',A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: %lo(val), kind: fixup_riscv_lo12_s | ||
| # CHECK-INSTR: sw a0, 0x678(t1) | ||
|
|
||
| 1: | ||
| auipc t1, %pcrel_hi(.LBB0) | ||
| # CHECK-ENCODING: encoding: [0x17,0bAAAA0011,A,A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: %pcrel_hi(.LBB0), kind: fixup_riscv_pcrel_hi20 | ||
| # CHECK-INSTR: auipc t1, 0 | ||
|
|
||
| addi t1, t1, %pcrel_lo(1b) | ||
| # CHECK-ENCODING: encoding: [0x13,0x03,0bAAAA0011,A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: %pcrel_lo({{.*}}), kind: fixup_riscv_pcrel_lo12_i | ||
| # CHECK-INSTR: addi t1, t1, -0x14 | ||
|
|
||
| sw t1, %pcrel_lo(1b)(t1) | ||
| # CHECK-ENCODING: encoding: [0x23'A',0x20'A',0x63'A',A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: %pcrel_lo({{.*}}), kind: fixup_riscv_pcrel_lo12_s | ||
| # CHECK-INSTR: sw t1, -0x14(t1) | ||
|
|
||
| jal zero, .LBB0 | ||
| # CHECK-ENCODING: encoding: [0x6f,0bAAAA0000,A,A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: .LBB0, kind: fixup_riscv_jal | ||
| # CHECK-INSTR: j 0x0 <.text> | ||
|
|
||
| jal zero, .LBB2 | ||
| # CHECK-ENCODING: encoding: [0x6f,0bAAAA0000,A,A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: .LBB2, kind: fixup_riscv_jal | ||
| # CHECK-INSTR: j 0x50d18 <.text+0x50d18> | ||
|
|
||
| beq a0, a1, .LBB0 | ||
| # CHECK-ENCODING: encoding: [0x63'A',A,0xb5'A',A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: .LBB0, kind: fixup_riscv_branch | ||
| # CHECK-INSTR: beq a0, a1, 0x0 <.text> | ||
|
|
||
| blt a0, a1, .LBB1 | ||
| # CHECK-ENCODING: encoding: [0x63'A',0x40'A',0xb5'A',A] | ||
| # CHECK-FIXUP: fixup A - offset: 0, value: .LBB1, kind: fixup_riscv_branch | ||
| # CHECK-INSTR: blt a0, a1, 0x480 <.text+0x480> | ||
|
|
||
| .fill 1104 | ||
|
|
||
| .LBB1: | ||
|
|
||
| .fill 329876 | ||
| addi zero, zero, 0 | ||
| .LBB2: | ||
|
|
||
| .set val, 0x12345678 | ||
|
|
||
| # CHECK-REL-NOT: R_RISCV | ||
|
|
||
| .data | ||
| .align 3 | ||
| data_label: | ||
| .word val # On BE: 0x12345678 stored as [0x12, 0x34, 0x56, 0x78] | ||
| .long val # On BE: 0x12345678 stored as [0x12, 0x34, 0x56, 0x78] | ||
| .quad val # On BE: 0x0000000012345678 stored as [0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78] |
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.
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.
In a follow-up, this should probably be turned into some kind of target-independent hook, as AArch64 is also little-endian instructions always, but little/big-endian data. This does not need to be in the current PR.
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.
Yes, noted, I agree.