diff --git a/llvm/lib/Target/BPF/BPF.td b/llvm/lib/Target/BPF/BPF.td index b8c2298584cc..877bd15f4f2b 100644 --- a/llvm/lib/Target/BPF/BPF.td +++ b/llvm/lib/Target/BPF/BPF.td @@ -29,6 +29,9 @@ def DummyFeature : SubtargetFeature<"dummy", "isDummyMode", def ALU32 : SubtargetFeature<"alu32", "HasAlu32", "true", "Enable ALU32 instructions">; +def DwarfRIS: SubtargetFeature<"dwarfris", "UseDwarfRIS", "true", + "Disable MCAsmInfo DwarfUsesRelocationsAcrossSections">; + def BPFInstPrinter : AsmWriter { string AsmWriterClassName = "InstPrinter"; bit isMCAsmWriter = 1; diff --git a/llvm/lib/Target/BPF/BPFSubtarget.cpp b/llvm/lib/Target/BPF/BPFSubtarget.cpp index 2bb07032304c..56780bd9d46f 100644 --- a/llvm/lib/Target/BPF/BPFSubtarget.cpp +++ b/llvm/lib/Target/BPF/BPFSubtarget.cpp @@ -37,6 +37,7 @@ BPFSubtarget &BPFSubtarget::initializeSubtargetDependencies(StringRef CPU, void BPFSubtarget::initializeEnvironment() { HasJmpExt = false; HasAlu32 = false; + UseDwarfRIS = false; } void BPFSubtarget::initSubtargetFeatures(StringRef CPU, StringRef FS) { diff --git a/llvm/lib/Target/BPF/BPFSubtarget.h b/llvm/lib/Target/BPF/BPFSubtarget.h index 4fbd4b001816..067b22ad3ceb 100644 --- a/llvm/lib/Target/BPF/BPFSubtarget.h +++ b/llvm/lib/Target/BPF/BPFSubtarget.h @@ -50,6 +50,9 @@ protected: // whether the cpu supports alu32 instructions. bool HasAlu32; + // whether we should enable MCAsmInfo DwarfUsesRelocationsAcrossSections + bool UseDwarfRIS; + public: // This constructor initializes the data members to match that // of the specified triple. @@ -63,6 +66,7 @@ public: void ParseSubtargetFeatures(StringRef CPU, StringRef FS); bool getHasJmpExt() const { return HasJmpExt; } bool getHasAlu32() const { return HasAlu32; } + bool getUseDwarfRIS() const { return UseDwarfRIS; } const BPFInstrInfo *getInstrInfo() const override { return &InstrInfo; } const BPFFrameLowering *getFrameLowering() const override { diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp index 0114d18599a3..91ff64ba797f 100644 --- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp +++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp @@ -13,6 +13,7 @@ #include "BPFTargetMachine.h" #include "BPF.h" +#include "MCTargetDesc/BPFMCAsmInfo.h" #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h" #include "llvm/CodeGen/TargetPassConfig.h" @@ -68,6 +69,9 @@ BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT, TLOF(make_unique()), Subtarget(TT, CPU, FS, *this) { initAsmInfo(); + + BPFMCAsmInfo *MAI = static_cast(const_cast(AsmInfo)); + MAI->setDwarfUsesRelocationsAcrossSections(!Subtarget.getUseDwarfRIS()); } namespace { // BPF Code Generator Pass Configuration Options. diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h index fa06f31add90..171f7f607ff4 100644 --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h @@ -37,8 +37,6 @@ public: ExceptionsType = ExceptionHandling::DwarfCFI; MinInstAlignment = 8; - DwarfUsesRelocationsAcrossSections = false; - // the default is 4 and it only affects dwarf elf output // so if not set correctly, the dwarf data will be // messed up in random places by 4 bytes. .debug_line @@ -46,6 +44,10 @@ public: // line numbers, etc. CodePointerSize = 8; } + + void setDwarfUsesRelocationsAcrossSections(bool enable) { + DwarfUsesRelocationsAcrossSections = enable; + } }; }