diff --git a/llvm/include/llvm/BinaryFormat/ELF.h b/llvm/include/llvm/BinaryFormat/ELF.h index a5ecdb0e6bcc2a4..339f8f96c236b21 100644 --- a/llvm/include/llvm/BinaryFormat/ELF.h +++ b/llvm/include/llvm/BinaryFormat/ELF.h @@ -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. diff --git a/llvm/lib/Target/SBF/MCTargetDesc/SBFAsmBackend.cpp b/llvm/lib/Target/SBF/MCTargetDesc/SBFAsmBackend.cpp index 2090878d20c1b8d..4367910af246ebf 100644 --- a/llvm/lib/Target/SBF/MCTargetDesc/SBFAsmBackend.cpp +++ b/llvm/lib/Target/SBF/MCTargetDesc/SBFAsmBackend.cpp @@ -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; @@ -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; }; @@ -107,7 +107,7 @@ void SBFAsmBackend::applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, std::unique_ptr SBFAsmBackend::createObjectTargetWriter() const { - return createSBFELFObjectWriter(0, relocAbs64, isSBFv2); + return createSBFELFObjectWriter(0, relocAbs64, IsSbfV3); } MCAsmBackend *llvm::createSBFAsmBackend(const Target &T, diff --git a/llvm/lib/Target/SBF/MCTargetDesc/SBFELFObjectWriter.cpp b/llvm/lib/Target/SBF/MCTargetDesc/SBFELFObjectWriter.cpp index ea5307ed13767e7..0e7147b238e15e6 100644 --- a/llvm/lib/Target/SBF/MCTargetDesc/SBFELFObjectWriter.cpp +++ b/llvm/lib/Target/SBF/MCTargetDesc/SBFELFObjectWriter.cpp @@ -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: @@ -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) {} @@ -110,6 +110,6 @@ unsigned SBFELFObjectWriter::getRelocType(MCContext &Ctx, const MCValue &Target, } std::unique_ptr -llvm::createSBFELFObjectWriter(uint8_t OSABI, bool useRelocAbs64, bool isSBFv2) { - return std::make_unique(OSABI, useRelocAbs64, isSBFv2); +llvm::createSBFELFObjectWriter(uint8_t OSABI, bool useRelocAbs64, bool IsSbfV3) { + return std::make_unique(OSABI, useRelocAbs64, IsSbfV3); } diff --git a/llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.cpp b/llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.cpp index e92e2fcb534e4ea..621145e11659461 100644 --- a/llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.cpp +++ b/llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.cpp @@ -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; } diff --git a/llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.h b/llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.h index f6cc55b67d24733..d3645082be7255d 100644 --- a/llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.h +++ b/llvm/lib/Target/SBF/MCTargetDesc/SBFMCTargetDesc.h @@ -43,7 +43,7 @@ MCAsmBackend *createSBFbeAsmBackend(const Target &T, const MCSubtargetInfo &STI, const MCTargetOptions &Options); std::unique_ptr -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 diff --git a/llvm/lib/Target/SBF/SBFSubtarget.cpp b/llvm/lib/Target/SBF/SBFSubtarget.cpp index 5d3e24fef099c45..257ba92e35ec720 100644 --- a/llvm/lib/Target/SBF/SBFSubtarget.cpp +++ b/llvm/lib/Target/SBF/SBFSubtarget.cpp @@ -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, diff --git a/llvm/lib/Target/SBF/SBFTargetFeatures.td b/llvm/lib/Target/SBF/SBFTargetFeatures.td index a11b0aacbbd17c9..ec963ba8179ff98 100644 --- a/llvm/lib/Target/SBF/SBFTargetFeatures.td +++ b/llvm/lib/Target/SBF/SBFTargetFeatures.td @@ -53,9 +53,11 @@ class Proc Features> : Processor; 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]>; \ No newline at end of file + +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]>; \ No newline at end of file diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 275433ade50765f..d55b595b0c3e0a8 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -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(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; } }