Skip to content

Commit

Permalink
Read flag from elf
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Jan 3, 2024
1 parent 8e94a17 commit 15259a9
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion llvm/lib/Target/SBF/Disassembler/SBFDisassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SBFDisassembler : public MCDisassembler {
uint8_t getInstClass(uint64_t Inst) const { return (Inst >> 56) & 0x7; };
uint8_t getInstSize(uint64_t Inst) const { return (Inst >> 59) & 0x3; };
uint8_t getInstMode(uint64_t Inst) const { return (Inst >> 61) & 0x7; };
bool isMov32(uint64_t Inst) const { return (Inst >> 56) == 0xb4; }
};

} // end anonymous namespace
Expand Down Expand Up @@ -175,7 +176,7 @@ DecodeStatus SBFDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
STI.getFeatureBits()[SBF::ALU32])
Result = decodeInstruction(DecoderTableSBFALU3264, Instr, Insn, Address,
this, STI);
else if (InstClass == SBF_ALU && !STI.getFeatureBits()[SBF::ALU32] &&
else if (isMov32(Insn) && !STI.getFeatureBits()[SBF::ALU32] &&
STI.getFeatureBits()[SBF::FeatureDisableLddw])
Result =
decodeInstruction(DecoderTableSBFv264, Instr, Insn, Address, this, STI);
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/SBF/objdump_cond_op.ll
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: llc -march=sbf -mcpu=sbfv2 -filetype=obj -o - %s | llvm-objdump -d --mcpu=sbfv2 - | FileCheck %s
; RUN: llc -march=sbf -mcpu=sbfv2 -filetype=obj -o - %s | llvm-objdump -d - | FileCheck %s

; Source Code:
; int gbl;
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/SBF/objdump_imm_hex.ll
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
; RUN: llc -march=sbf -mcpu=sbfv2 -filetype=obj -o - %s | llvm-objdump -d --mcpu=sbfv2 - | FileCheck --check-prefix=CHECK-DEC %s
; RUN: llc -march=sbf -mcpu=sbfv2 -filetype=obj -o - %s | llvm-objdump -d --mcpu=sbfv2 --print-imm-hex - | FileCheck --check-prefix=CHECK-HEX %s
; RUN: llc -march=sbf -mcpu=sbfv2 -filetype=obj -o - %s | llvm-objdump -d - | FileCheck --check-prefix=CHECK-DEC %s
; RUN: llc -march=sbf -mcpu=sbfv2 -filetype=obj -o - %s | llvm-objdump -d --print-imm-hex - | FileCheck --check-prefix=CHECK-HEX %s
; RUN: llc < %s -march=sbf -mcpu=sbfv2 -show-mc-encoding | FileCheck --check-prefix=CHECK-REL %s

; Source Code:
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/SBF/objdump_static_var.ll
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
; Function Attrs: norecurse nounwind
define dso_local i32 @test() local_unnamed_addr #0 {
%1 = load volatile i64, i64* @a, align 8, !tbaa !2
; CHECK: mov32 w1, 0x0
; CHECK: mov32 r1, 0x0
; CHECK: R_SBF_64_64 a
; CHECK: hor64 r1, 0x0
; CHECK: ldxdw r1, [r1 + 0x0]
%2 = load volatile i32, i32* @b, align 4, !tbaa !6
; CHECK: mov32 w2, 0x0
; CHECK: mov32 r2, 0x0
; CHECK: R_SBF_64_64 b
; CHECK: hor64 r2, 0x0
; CHECK: ldxw r0, [r2 + 0x0]
Expand Down
10 changes: 6 additions & 4 deletions llvm/test/MC/SBF/insn-unit-32.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RUN: llvm-mc -triple sbf --mcpu=sbfv2 -filetype=obj -o %t %s
# RUN: llvm-objdump -d -r %t | FileCheck %s
# RUN: llvm-objdump --mattr=+alu32 -d -r %t | FileCheck %s
# RUN: llvm-objdump -d -r %t | FileCheck %s --check-prefixes=CHECK,CHECK-alu64
# RUN: llvm-objdump --mattr=+alu32 -d -r %t | FileCheck %s --check-prefixes=CHECK,CHECK-alu32

// ======== BPF_ALU Class ========
neg32 w1 // BPF_NEG
Expand Down Expand Up @@ -51,8 +51,10 @@
// CHECK: 64 06 00 00 3f 00 00 00 lsh32 w6, 0x3f
// CHECK: 74 07 00 00 20 00 00 00 rsh32 w7, 0x20
// CHECK: a4 08 00 00 00 00 00 00 xor32 w8, 0x0
// CHECK: b4 09 00 00 01 00 00 00 mov32 w9, 0x1
// CHECK: b4 09 00 00 ff ff ff ff mov32 w9, -0x1
// CHECK-alu64: b4 09 00 00 01 00 00 00 mov32 r9, 0x1
// CHECK-alu64: b4 09 00 00 ff ff ff ff mov32 r9, -0x1
// CHECK-alu32: b4 09 00 00 01 00 00 00 mov32 w9, 0x1
// CHECK-alu32: b4 09 00 00 ff ff ff ff mov32 w9, -0x1
// CHECK: c4 0a 00 00 40 00 00 00 arsh32 w10, 0x40

jeq w0, w1, Llabel0 // BPF_JEQ | BPF_X
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/SBF/sbf-alu.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# RUN: llvm-mc %s -triple=sbf-solana-solana --mcpu=sbfv2 --show-encoding \
# RUN: | FileCheck %s --check-prefix=CHECK-ASM-NEW
# RUN: llvm-mc %s -triple=sbf-solana-solana --mcpu=sbfv2 -filetype=obj \
# RUN: | llvm-objdump -d -r - \
# RUN: | llvm-objdump -d -r --mattr=+alu32 - \
# RUN: | FileCheck --check-prefix=CHECK-OBJ-NEW %s


Expand Down
9 changes: 9 additions & 0 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,15 @@ static void disassembleObject(ObjectFile *Obj, bool InlineRelocs) {
}
}

// The SBF target specifies the cpu type as an ELF flag, which is not parsed automatically in LLVM objdump.
// We must set the CPU type here so that the disassembler can decode the SBFv2 features correctly.
if (MCPU.empty() && Obj->isELF() && Obj->getArch() == Triple::sbf) {
const auto *Elf64 = dyn_cast<ELF64LEObjectFile>(Obj);
if (Elf64->getPlatformFlags() & ELF::EF_SBF_V2) {
MCPU = "sbfv2";
}
}

std::unique_ptr<const MCSubtargetInfo> STI(
TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString()));
if (!STI)
Expand Down

0 comments on commit 15259a9

Please sign in to comment.