Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lld/ELF/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,8 @@ static uint16_t getBitcodeMachineKind(Ctx &ctx, StringRef path,
return t.isOSIAMCU() ? EM_IAMCU : EM_386;
case Triple::x86_64:
return EM_X86_64;
case Triple::bpfel:
case Triple::bpfeb:
case Triple::sbf:
return EM_SBF;
default:
Expand Down
2 changes: 1 addition & 1 deletion lld/ELF/InputSection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ void InputSection::relocateNonAlloc(Ctx &ctx, uint8_t *buf,
const uint64_t offset = rel.r_offset;

// FIX: Temporary remap BPF_64_64 relocations in debug sections.
if (ctx.arg.emachine == EM_SBF && type == R_SBF_64_64 && isDebug)
if ((ctx.arg.emachine == EM_SBF || ctx.arg.emachine == EM_BPF) && type == R_SBF_64_64 && isDebug)
type = R_BPF_64_ABS64;

uint8_t *bufLoc = buf + offset;
Expand Down
4 changes: 2 additions & 2 deletions lldb/source/Utility/ArchSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,9 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = {
0xFFFFFFFFu, 0xFFFFFFFFu}, // sbfv1
{ArchSpec::eCore_sbfv2, llvm::ELF::EM_SBF, ArchSpec::eSBFSubType_sbfv2,
0xFFFFFFFFu, 0xFFFFFFFFu}, // sbfv2
{ArchSpec::eCore_sbfv3, llvm::ELF::EM_SBF, ArchSpec::eSBFSubType_sbfv3,
{ArchSpec::eCore_sbfv3, llvm::ELF::EM_BPF, ArchSpec::eSBFSubType_sbfv3,
0xFFFFFFFFu, 0xFFFFFFFFu}, // sbfv3
{ArchSpec::eCore_sbfv4, llvm::ELF::EM_SBF, ArchSpec::eSBFSubType_sbfv4,
{ArchSpec::eCore_sbfv4, llvm::ELF::EM_BPF, ArchSpec::eSBFSubType_sbfv4,
0xFFFFFFFFu, 0xFFFFFFFFu}, // sbfv3
};

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Object/ELF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ StringRef llvm::object::getELFRelocationTypeName(uint32_t Machine,
break;
case ELF::EM_BPF:
switch (Type) {
#include "llvm/BinaryFormat/ELFRelocs/BPF.def"
#include "llvm/BinaryFormat/ELFRelocs/SBF.def"
default:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/ObjectYAML/ELFYAML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ void ScalarEnumerationTraits<ELFYAML::ELF_REL>::enumeration(
#include "llvm/BinaryFormat/ELFRelocs/AMDGPU.def"
break;
case ELF::EM_BPF:
#include "llvm/BinaryFormat/ELFRelocs/BPF.def"
#include "llvm/BinaryFormat/ELFRelocs/SBF.def"
break;
case ELF::EM_SBF:
#include "llvm/BinaryFormat/ELFRelocs/SBF.def"
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/SBF/MCTargetDesc/SBFELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool SBFELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
}

SBFELFObjectWriter::SBFELFObjectWriter(uint8_t OSABI, bool relocAbs64)
: MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI,ELF::EM_SBF,
: MCELFObjectTargetWriter(/*Is64Bit*/ true, OSABI, relocAbs64? ELF::EM_BPF : ELF::EM_SBF,
/*HasRelocationAddend*/ false),
relocAbs64(relocAbs64) {}

Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/BPF/reloc-2.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; XFAIL: *
; RUN: llc -mtriple=bpfel -mcpu=v1 -filetype=obj -o %t.el < %s
; RUN: llvm-objdump -r %t.el | FileCheck --check-prefix=RELOC %s
; RUN: llvm-objdump --no-print-imm-hex -d --no-show-raw-insn %t.el | FileCheck --check-prefix=DUMP %s
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/BPF/reloc-3.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; XFAIL: *
; RUN: llc -mtriple=bpfel -filetype=obj -o %t.el < %s
; RUN: llvm-readelf -r %t.el | FileCheck %s
; RUN: llc -mtriple=bpfeb -filetype=obj -o %t.eb < %s
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/BPF/reloc-btf-2.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; XFAIL: *
; RUN: llc -mtriple=bpfel -filetype=obj < %s | llvm-objdump -r - | FileCheck --check-prefix=CHECK-RELOC %s
; RUN: llc -mtriple=bpfeb -filetype=obj < %s | llvm-objdump -r - | FileCheck --check-prefix=CHECK-RELOC %s

Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/BPF/reloc-btf.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; XFAIL: *
; RUN: llc -mtriple=bpfel -filetype=obj < %s | llvm-objdump -r - | FileCheck --check-prefix=CHECK-RELOC %s

; Function Attrs: norecurse nounwind readnone
Expand Down
1 change: 1 addition & 0 deletions llvm/test/CodeGen/BPF/reloc.ll
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
; XFAIL: *
; RUN: llc -mtriple=bpfel -filetype=obj < %s | llvm-objdump -r - | FileCheck --check-prefix=CHECK-RELOC %s

%struct.bpf_context = type { i64, i64, i64, i64, i64, i64, i64 }
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/SBF/reloc-btf.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ entry:
ret i32 0, !dbg !11
}

; CHECK-RELOC: file format elf64-sbf
; CHECK-RELOC: file format elf64-bpf
; CHECK-RELOC: RELOCATION RECORDS FOR [.debug_info]:
; CHECK-RELOC: R_SBF_64_ABS32 .debug_abbrev
; CHECK-RELOC: R_SBF_64_ABS64
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/SBF/reloc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ define i32 @bpf_prog1(%struct.bpf_context* nocapture %ctx) #0 section "events/ne
; <label>:13 ; preds = %10, %0
ret i32 0

; CHECK-RELOC: file format elf64-sbf
; CHECK-RELOC: file format elf64-bpf
; CHECK-RELOC: RELOCATION RECORDS FOR [.eh_frame]:
; CHECK-RELOC: 00000000000001c R_SBF_64_ABS64
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/MC/BPF/insn-unit.s
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// CHECK: 18 09 00 00 ff ff ff ff 00 00 00 00 01 00 00 00 r9 = 8589934591 ll
// CHECK: 18 09 00 00 ff ff ff ff 00 00 00 00 01 00 00 00 r9 = 8589934591 ll
// CHECK: 18 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r9 = 0 ll
// CHECK: 0000000000000060: R_BPF_64_64 dummy_map
// CHECK: 0000000000000060: R_SBF_64_64 dummy_map

// ======== BPF_LDX Class ========
r5 = *(u8 *)(r0 + 0) // BPF_LDX | BPF_B
Expand Down
39 changes: 21 additions & 18 deletions llvm/test/MC/SBF/elf-header.s
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# RUN: llvm-mc %s -filetype=obj -triple=sbf-solana-solana --mcpu=v1 | llvm-readobj -h - \
# RUN: | FileCheck %s
# RUN: | FileCheck --check-prefixes=CHECK,CHECK-V1 %s
# RUN: llvm-mc %s -filetype=obj -triple=sbf-solana-solana --mcpu=v2 | llvm-readobj -h - \
# RUN: | FileCheck %s
# RUN: | FileCheck --check-prefixes=CHECK,CHECK-V1 %s
# RUN: llvm-mc %s -filetype=obj -triple=sbf-solana-solana --mcpu=v3 | llvm-readobj -h - \
# RUN: | FileCheck %s
# RUN: | FileCheck --check-prefixes=CHECK,CHECK-V3 %s

# CHECK: Format: elf64-sbf
# CHECK: Arch: sbf
# CHECK: AddressSize: 64bit
# CHECK: ElfHeader {
# CHECK: Ident {
# CHECK: Magic: (7F 45 4C 46)
# CHECK: Class: 64-bit (0x2)
# CHECK: DataEncoding: LittleEndian (0x1)
# CHECK: FileVersion: 1
# CHECK: OS/ABI: SystemV (0x0)
# CHECK: ABIVersion: 0
# CHECK: }
# CHECK: Type: Relocatable (0x1)
# CHECK: Machine: EM_SBF (0x107)
# CHECK: Version: 1
# CHECK-V1: Format: elf64-sbf
# CHECK-V3: Format: elf64-bpf
# CHECK-V1: Arch: sbf
# CHECK-V3: Arch: bpf
# CHECK: AddressSize: 64bit
# CHECK: ElfHeader {
# CHECK: Ident {
# CHECK: Magic: (7F 45 4C 46)
# CHECK: Class: 64-bit (0x2)
# CHECK: DataEncoding: LittleEndian (0x1)
# CHECK: FileVersion: 1
# CHECK: OS/ABI: SystemV (0x0)
# CHECK: ABIVersion: 0
# CHECK: }
# CHECK: Type: Relocatable (0x1)
# CHECK-V1: Machine: EM_SBF (0x107)
# CHECK-V3: Machine: EM_BPF (0xF7)
# CHECK: Version: 1
8 changes: 4 additions & 4 deletions llvm/test/Object/BPF/yaml2obj-elf-bpf-rel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

# CHECK: Relocations [
# CHECK-NEXT: Section (3) .rel.text {
# CHECK-NEXT: 0x0 R_BPF_64_64 g
# CHECK-NEXT: 0x0 R_SBF_64_64 g
# CHECK-NEXT: }
# CHECK-NEXT: Section (5) .rel.stack_sizes {
# CHECK-NEXT: 0x0 R_BPF_64_ABS64 .text
# CHECK-NEXT: 0x0 R_SBF_64_ABS64 .text
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK: StackSizes [
Expand Down Expand Up @@ -47,15 +47,15 @@ Sections:
Info: .text
Relocations:
- Symbol: g
Type: R_BPF_64_64
Type: R_SBF_64_64
- Name: .rel.stack_sizes
Type: SHT_REL
Link: .symtab
AddressAlign: 0x8
Info: .stack_sizes
Relocations:
- Symbol: .text
Type: R_BPF_64_ABS64
Type: R_SBF_64_ABS64
- Type: SectionHeaderTable
Sections:
- Name: .strtab
Expand Down
18 changes: 9 additions & 9 deletions llvm/test/tools/llvm-objdump/BPF/core-relo-formatting.s
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@
# NOADDR: r1 = 0x1
# NOADDR-NEXT: CO-RE <type_exists> [3] struct foo
# NOADDR-NEXT: call -0x1
# NOADDR-NEXT: R_BPF_64_32 consume
# NOADDR-NEXT: R_SBF_64_32 consume
# NOADDR-NEXT: r1 = 0x0
# NOADDR-NEXT: CO-RE <byte_off> [3] struct foo::a (0:0)
# NOADDR-NEXT: call -0x1
# NOADDR-NEXT: R_BPF_64_32 consume
# NOADDR-NEXT: R_SBF_64_32 consume
# NOADDR-NEXT: r1 = 0x1 ll
# NOADDR-NEXT: CO-RE <enumval_exists> [8] enum bar::U = 0
# NOADDR-NEXT: call -0x1
# NOADDR-NEXT: R_BPF_64_32 consume
# NOADDR-NEXT: R_SBF_64_32 consume
# NOADDR-NEXT: exit

# NORELO: r1 = 0x1
Expand All @@ -64,29 +64,29 @@
# ADDR: 1: r1 = 0x1
# ADDR-NEXT: 0000000000000008: CO-RE <type_exists> [3] struct foo
# ADDR-NEXT: 2: call -0x1
# ADDR-NEXT: 0000000000000010: R_BPF_64_32 consume
# ADDR-NEXT: 0000000000000010: R_SBF_64_32 consume
# ADDR-NEXT: 3: r1 = 0x0
# ADDR-NEXT: 0000000000000018: CO-RE <byte_off> [3] struct foo::a (0:0)
# ADDR-NEXT: 4: call -0x1
# ADDR-NEXT: 0000000000000020: R_BPF_64_32 consume
# ADDR-NEXT: 0000000000000020: R_SBF_64_32 consume
# ADDR-NEXT: 5: r1 = 0x1 ll
# ADDR-NEXT: 0000000000000028: CO-RE <enumval_exists> [8] enum bar::U = 0
# ADDR-NEXT: 7: call -0x1
# ADDR-NEXT: 0000000000000038: R_BPF_64_32 consume
# ADDR-NEXT: 0000000000000038: R_SBF_64_32 consume
# ADDR-NEXT: 8: exit

# VMA: 3: r1 = 0x1
# VMA-NEXT: 0000000000000018: CO-RE <type_exists> [3] struct foo
# VMA-NEXT: 4: call -0x1
# VMA-NEXT: 0000000000000010: R_BPF_64_32 consume
# VMA-NEXT: 0000000000000010: R_SBF_64_32 consume
# VMA-NEXT: 5: r1 = 0x0
# VMA-NEXT: 0000000000000028: CO-RE <byte_off> [3] struct foo::a (0:0)
# VMA-NEXT: 6: call -0x1
# VMA-NEXT: 0000000000000020: R_BPF_64_32 consume
# VMA-NEXT: 0000000000000020: R_SBF_64_32 consume
# VMA-NEXT: 7: r1 = 0x1 ll
# VMA-NEXT: 0000000000000038: CO-RE <enumval_exists> [8] enum bar::U = 0
# VMA-NEXT: 9: call -0x1
# VMA-NEXT: 0000000000000038: R_BPF_64_32 consume
# VMA-NEXT: 0000000000000038: R_SBF_64_32 consume
# VMA-NEXT: 10: exit

.text
Expand Down
15 changes: 14 additions & 1 deletion llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,19 @@ static const Target *getTarget(const ObjectFile *Obj) {
Obj->setARMSubArch(TheTriple);
}

// This condition tricks llvm-objdump into believing that an SBPFv3 with EM_BPF
// should use the SBF mnemonics.
if (const auto *Elf64 = dyn_cast<ELF64LEObjectFile>(Obj)) {
if (TheTriple.isBPF() &&
(Elf64->getPlatformFlags() == llvm::ELF::EF_SBF_V3 ||
Elf64->getPlatformFlags() == llvm::ELF::EF_SBF_V4)) {
TheTriple.setArch(Triple::sbf);
TheTriple.setOS(Triple::SolanaOS);
TheTriple.setVendor(Triple::Solana);
ArchName = "sbf";
}
}

// Get the target specific parser.
std::string Error;
const Target *TheTarget = TargetRegistry::lookupTarget(ArchName, TheTriple,
Expand Down Expand Up @@ -2589,7 +2602,7 @@ 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 newer SBF features correctly.
if (MCPU.empty() && Obj->isELF() && Obj->getArch() == Triple::sbf) {
if (MCPU.empty() && Obj->isELF() && (Obj->getArch() == Triple::sbf || Obj->getArch() == Triple::bpfel)) {
const auto *Elf64 = dyn_cast<ELF64LEObjectFile>(Obj);
switch (Elf64->getPlatformFlags()) {
case llvm::ELF::EF_SBF_V1:
Expand Down
Loading