From 7437035e6f589237bb13a0b75b737e364bd13e3f Mon Sep 17 00:00:00 2001 From: Dmitri Makarov Date: Wed, 21 Apr 2021 20:04:59 +0200 Subject: [PATCH] [SOL][BPF] Disable debug info when solana feature flag is set Solana extends BPF so that structs type information is not fully supported in BTF. This leads to ICE crashes and some unsupported relocations being emitted in binary files that linker errors on. For, now the debug information is simply disabled when compiling for Solana to avoid the errors in Debug builds. --- llvm/lib/Target/BPF/BPFTargetMachine.cpp | 1 + llvm/lib/Target/BPF/BTFDebug.cpp | 9 +++++---- llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h | 4 ++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp index 5df3043d07eea..c805eee992ad1 100644 --- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp +++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp @@ -74,6 +74,7 @@ BPFTargetMachine::BPFTargetMachine(const Target &T, const Triple &TT, BPFMCAsmInfo *MAI = static_cast(const_cast(AsmInfo.get())); MAI->setDwarfUsesRelocationsAcrossSections(!Subtarget.getUseDwarfRIS()); + MAI->setSupportsDebugInformation(!FS.contains("solana")); } namespace { diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp index 4510e93574892..d91f8865138d1 100644 --- a/llvm/lib/Target/BPF/BTFDebug.cpp +++ b/llvm/lib/Target/BPF/BTFDebug.cpp @@ -1082,11 +1082,12 @@ void BTFDebug::beginInstruction(const MachineInstr *MI) { // been generated, construct one based on function signature. if (LineInfoGenerated == false) { auto *S = MI->getMF()->getFunction().getSubprogram(); - MCSymbol *FuncLabel = Asm->getFunctionBegin(); - constructLineInfo(S, FuncLabel, S->getLine(), 0); - LineInfoGenerated = true; + if (S) { + MCSymbol *FuncLabel = Asm->getFunctionBegin(); + constructLineInfo(S, FuncLabel, S->getLine(), 0); + LineInfoGenerated = true; + } } - return; } diff --git a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h index 3292c3e5ebb51..9ec7de1758347 100644 --- a/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h +++ b/llvm/lib/Target/BPF/MCTargetDesc/BPFMCAsmInfo.h @@ -48,6 +48,10 @@ class BPFMCAsmInfo : public MCAsmInfo { void setDwarfUsesRelocationsAcrossSections(bool enable) { DwarfUsesRelocationsAcrossSections = enable; } + + void setSupportsDebugInformation(bool enable) { + SupportsDebugInformation = enable; + } }; }