Skip to content

Commit

Permalink
Changes for version flags
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasSte committed Jan 3, 2025
1 parent 26f146b commit 29d2215
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 35 deletions.
5 changes: 4 additions & 1 deletion llvm/include/llvm/BinaryFormat/ELF.h
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,10 @@ enum : unsigned {

// SBF specific e_flags
enum : unsigned {
EF_SBF_V2 = 0x20,
EF_SBF_V0 = 0x00,
EF_SBF_V1 = 0x01,
EF_SBF_V2 = 0x02,
EF_SBF_V3 = 0x03,
};

// ELF Relocation types for SBF.
Expand Down
6 changes: 3 additions & 3 deletions llvm/lib/Target/SBF/MCTargetDesc/SBFAsmBackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SBFAsmBackend : public MCAsmBackend {
public:
SBFAsmBackend(endianness Endian, const MCSubtargetInfo &STI)
: MCAsmBackend(Endian),
isSBFv2(STI.getCPU() == "sbfv2"),
IsSbfV3(STI.getCPU() == "v3"),
relocAbs64(STI.hasFeature(SBF::FeatureRelocAbs64)) {}
~SBFAsmBackend() override = default;

Expand All @@ -50,7 +50,7 @@ class SBFAsmBackend : public MCAsmBackend {
bool writeNopData(raw_ostream &OS, uint64_t Count,
const MCSubtargetInfo *STI) const override;
private:
bool isSBFv2;
bool IsSbfV3;
bool relocAbs64;
};

Expand Down Expand Up @@ -107,7 +107,7 @@ void SBFAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup,

std::unique_ptr<MCObjectTargetWriter>
SBFAsmBackend::createObjectTargetWriter() const {
return createSBFELFObjectWriter(0, relocAbs64, isSBFv2);
return createSBFELFObjectWriter(0, relocAbs64, IsSbfV3);
}

MCAsmBackend *llvm::createSBFAsmBackend(const Target &T,
Expand Down
10 changes: 5 additions & 5 deletions llvm/lib/Target/SBF/MCTargetDesc/SBFELFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace {

class SBFELFObjectWriter : public MCELFObjectTargetWriter {
public:
SBFELFObjectWriter(uint8_t OSABI, bool relocAbs64, bool isSBFv2);
SBFELFObjectWriter(uint8_t OSABI, bool relocAbs64, bool IsSbfV3);
~SBFELFObjectWriter() override = default;

protected:
Expand All @@ -48,9 +48,9 @@ bool SBFELFObjectWriter::needsRelocateWithSymbol(const MCValue &Val,
}

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

Expand Down Expand Up @@ -110,6 +110,6 @@ unsigned SBFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target,
}

std::unique_ptr<MCObjectTargetWriter>
llvm::createSBFELFObjectWriter(uint8_t OSABI, bool useRelocAbs64, bool isSBFv2) {
return std::make_unique<SBFELFObjectWriter>(OSABI, useRelocAbs64, isSBFv2);
llvm::createSBFELFObjectWriter(uint8_t OSABI, bool useRelocAbs64, bool IsSbfV3) {
return std::make_unique<SBFELFObjectWriter>(OSABI, useRelocAbs64, IsSbfV3);
}
13 changes: 11 additions & 2 deletions llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,18 @@ static MCStreamer *createSBFMCStreamer(const Triple &T, MCContext &Ctx,
if (RelaxAll)
S->getAssembler().setRelaxAll(true);
const MCSubtargetInfo *STI = Ctx.getSubtargetInfo();
if (STI->getCPU() == "sbfv2") {
S->getAssembler().setELFHeaderEFlags(llvm::ELF::EF_SBF_V2);

StringRef CPU = STI->getCPU();
unsigned EFlag = llvm::ELF::EF_SBF_V0;
if (CPU == "v1") {
EFlag = llvm::ELF::EF_SBF_V1;
} else if (CPU == "v2") {
EFlag = llvm::ELF::EF_SBF_V2;
} else if (CPU == "v3") {
EFlag = llvm::ELF::EF_SBF_V3;
}
S->getAssembler().setELFHeaderEFlags(EFlag);

return S;
}

Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ MCAsmBackend *createSBFbeAsmBackend(const Target &T, const MCSubtargetInfo &STI,
const MCTargetOptions &Options);

std::unique_ptr<MCObjectTargetWriter>
createSBFELFObjectWriter(uint8_t OSABI, bool useRelocAbs64, bool isSBFv2);
createSBFELFObjectWriter(uint8_t OSABI, bool useRelocAbs64, bool IsSbfV3);
} // namespace llvm

// Defines symbolic names for SBF registers. This defines a mapping from
Expand Down
15 changes: 1 addition & 14 deletions llvm/lib/Target/SBF/SBFSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,11 @@ void SBFSubtarget::initializeEnvironment(const Triple &TT) {
HasAlu32 = false;
HasExplicitSignExt = false;
NewMemEncoding = false;
HasStaticSyscalls = false;
}

void SBFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) {
ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);

if (CPU == "v2") {
HasJmpExt = true;
}

if (CPU == "v3") {
HasJmpExt = true;
HasAlu32 = true;
}

if (CPU == "sbfv2") {
if (!HasDynamicFrames)
report_fatal_error("sbfv2 requires dynamic-frames\n", false);
}
}

SBFSubtarget::SBFSubtarget(const Triple &TT, const std::string &CPU,
Expand Down
14 changes: 8 additions & 6 deletions llvm/lib/Target/SBF/SBFTargetFeatures.td
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ class Proc<string Name, list<SubtargetFeature> Features>
: Processor<Name, NoItineraries, Features>;

def : Proc<"generic", []>;
def : Proc<"v1", []>;
def : Proc<"v2", []>;
def : Proc<"v3", [ALU32]>;
def : Proc<"sbfv2", [FeatureDynamicFrames, FeatureRelocAbs64, FeatureStaticSyscalls,
FeatureDisableNeg, FeatureReverseSubImm, FeatureDisableLddw, FeatureCallxRegSrc,
FeaturePqrInstr, FeatureExplicitSext]>;

def : Proc<"v1", [FeatureDynamicFrames, FeatureStoreImm]>;
def : Proc<"v2", [FeatureDynamicFrames, FeatureStoreImm, FeatureDisableLddw, FeatureNewMemEncoding,
FeatureCallxRegSrc, FeaturePqrInstr, FeatureExplicitSext, FeatureDisableNeg,
FeatureReverseSubImm, ALU32]>;
def : Proc<"v3", [FeatureDynamicFrames, FeatureStoreImm, FeatureDisableLddw, FeatureNewMemEncoding,
FeatureCallxRegSrc, FeaturePqrInstr, FeatureExplicitSext, FeatureDisableNeg,
FeatureReverseSubImm, ALU32, FeatureStaticSyscalls, FeatureRelocAbs64]>;
17 changes: 14 additions & 3 deletions llvm/tools/llvm-objdump/llvm-objdump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2447,11 +2447,22 @@ 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.
// 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) {
const auto *Elf64 = dyn_cast<ELF64LEObjectFile>(Obj);
if (Elf64->getPlatformFlags() & ELF::EF_SBF_V2) {
MCPU = "sbfv2";
switch (Elf64->getPlatformFlags()) {
case llvm::ELF::EF_SBF_V1:
MCPU = "v1";
break;
case llvm::ELF::EF_SBF_V2:
MCPU = "v2";
break;
case llvm::ELF::EF_SBF_V3:
MCPU = "v3";
break;
default:
MCPU = "generic";
break;
}
}

Expand Down

0 comments on commit 29d2215

Please sign in to comment.