diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2021-02-16 20:13:02 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2021-02-16 20:13:02 +0000 |
commit | b60736ec1405bb0a8dd40989f67ef4c93da068ab (patch) | |
tree | 5c43fbb7c9fc45f0f87e0e6795a86267dbd12f9d /llvm/lib/Target/BPF/BTFDebug.cpp | |
parent | cfca06d7963fa0909f90483b42a6d7d194d01e08 (diff) | |
download | src-b60736ec1405bb0a8dd40989f67ef4c93da068ab.tar.gz src-b60736ec1405bb0a8dd40989f67ef4c93da068ab.zip |
Vendor import of llvm-project main 8e464dd76bef, the last commit beforevendor/llvm-project/llvmorg-12-init-17869-g8e464dd76bef
the upstream release/12.x branch was created.
Diffstat (limited to 'llvm/lib/Target/BPF/BTFDebug.cpp')
-rw-r--r-- | llvm/lib/Target/BPF/BTFDebug.cpp | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp index 4510e9357489..f9bdffe7cbae 100644 --- a/llvm/lib/Target/BPF/BTFDebug.cpp +++ b/llvm/lib/Target/BPF/BTFDebug.cpp @@ -22,6 +22,7 @@ #include "llvm/MC/MCSectionELF.h" #include "llvm/MC/MCStreamer.h" #include "llvm/Support/LineIterator.h" +#include "llvm/Target/TargetLoweringObjectFile.h" using namespace llvm; @@ -993,12 +994,13 @@ void BTFDebug::generatePatchImmReloc(const MCSymbol *ORSym, uint32_t RootId, FieldReloc.OffsetNameOff = addString(IndexPattern); FieldReloc.RelocKind = std::stoull(std::string(RelocKindStr)); - PatchImms[GVar] = std::stoul(std::string(PatchImmStr)); + PatchImms[GVar] = std::make_pair(std::stoll(std::string(PatchImmStr)), + FieldReloc.RelocKind); } else { StringRef RelocStr = AccessPattern.substr(FirstDollar + 1); FieldReloc.OffsetNameOff = addString("0"); FieldReloc.RelocKind = std::stoull(std::string(RelocStr)); - PatchImms[GVar] = RootId; + PatchImms[GVar] = std::make_pair(RootId, FieldReloc.RelocKind); } FieldRelocTable[SecNameOff].push_back(FieldReloc); } @@ -1074,6 +1076,9 @@ void BTFDebug::beginInstruction(const MachineInstr *MI) { } } + if (!CurMI) // no debug info + return; + // Skip this instruction if no DebugLoc or the DebugLoc // is the same as the previous instruction. const DebugLoc &DL = MI->getDebugLoc(); @@ -1125,6 +1130,20 @@ void BTFDebug::processGlobals(bool ProcessingMapDef) { if (ProcessingMapDef != SecName.startswith(".maps")) continue; + // Create a .rodata datasec if the global variable is an initialized + // constant with private linkage and if it won't be in .rodata.str<#> + // and .rodata.cst<#> sections. + if (SecName == ".rodata" && Global.hasPrivateLinkage() && + DataSecEntries.find(std::string(SecName)) == DataSecEntries.end()) { + SectionKind GVKind = + TargetLoweringObjectFile::getKindForGlobal(&Global, Asm->TM); + // skip .rodata.str<#> and .rodata.cst<#> sections + if (!GVKind.isMergeableCString() && !GVKind.isMergeableConst()) { + DataSecEntries[std::string(SecName)] = + std::make_unique<BTFKindDataSec>(Asm, std::string(SecName)); + } + } + SmallVector<DIGlobalVariableExpression *, 1> GVs; Global.getDebugInfo(GVs); @@ -1194,14 +1213,23 @@ bool BTFDebug::InstLower(const MachineInstr *MI, MCInst &OutMI) { auto *GVar = dyn_cast<GlobalVariable>(GVal); if (GVar) { // Emit "mov ri, <imm>" - uint32_t Imm; + int64_t Imm; + uint32_t Reloc; if (GVar->hasAttribute(BPFCoreSharedInfo::AmaAttr) || - GVar->hasAttribute(BPFCoreSharedInfo::TypeIdAttr)) - Imm = PatchImms[GVar]; - else + GVar->hasAttribute(BPFCoreSharedInfo::TypeIdAttr)) { + Imm = PatchImms[GVar].first; + Reloc = PatchImms[GVar].second; + } else { return false; + } - OutMI.setOpcode(BPF::MOV_ri); + if (Reloc == BPFCoreSharedInfo::ENUM_VALUE_EXISTENCE || + Reloc == BPFCoreSharedInfo::ENUM_VALUE || + Reloc == BPFCoreSharedInfo::BTF_TYPE_ID_LOCAL || + Reloc == BPFCoreSharedInfo::BTF_TYPE_ID_REMOTE) + OutMI.setOpcode(BPF::LD_imm64); + else + OutMI.setOpcode(BPF::MOV_ri); OutMI.addOperand(MCOperand::createReg(MI->getOperand(0).getReg())); OutMI.addOperand(MCOperand::createImm(Imm)); return true; @@ -1215,7 +1243,7 @@ bool BTFDebug::InstLower(const MachineInstr *MI, MCInst &OutMI) { const GlobalValue *GVal = MO.getGlobal(); auto *GVar = dyn_cast<GlobalVariable>(GVal); if (GVar && GVar->hasAttribute(BPFCoreSharedInfo::AmaAttr)) { - uint32_t Imm = PatchImms[GVar]; + uint32_t Imm = PatchImms[GVar].first; OutMI.setOpcode(MI->getOperand(1).getImm()); if (MI->getOperand(0).isImm()) OutMI.addOperand(MCOperand::createImm(MI->getOperand(0).getImm())); |