diff --git a/llvm/lib/Target/BPF/BTF.h b/llvm/lib/Target/BPF/BTF.h --- a/llvm/lib/Target/BPF/BTF.h +++ b/llvm/lib/Target/BPF/BTF.h @@ -176,6 +176,13 @@ uint32_t Type; }; +/// BTF_KIND_FUNC can be global, static or extern. +enum : uint8_t { + FUNC_STATIC = 0, + FUNC_GLOBAL = 1, + FUNC_EXTERN = 2, +}; + /// Variable scoping information. enum : uint8_t { VAR_STATIC = 0, ///< Linkage: InternalLinkage diff --git a/llvm/lib/Target/BPF/BTFDebug.h b/llvm/lib/Target/BPF/BTFDebug.h --- a/llvm/lib/Target/BPF/BTFDebug.h +++ b/llvm/lib/Target/BPF/BTFDebug.h @@ -151,7 +151,7 @@ StringRef Name; public: - BTFTypeFunc(StringRef FuncName, uint32_t ProtoTypeId); + BTFTypeFunc(StringRef FuncName, uint32_t ProtoTypeId, uint32_t Scope); uint32_t getSize() { return BTFTypeBase::getSize(); } void completeType(BTFDebug &BDebug); void emitType(MCStreamer &OS); diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp --- a/llvm/lib/Target/BPF/BTFDebug.cpp +++ b/llvm/lib/Target/BPF/BTFDebug.cpp @@ -308,10 +308,11 @@ } } -BTFTypeFunc::BTFTypeFunc(StringRef FuncName, uint32_t ProtoTypeId) +BTFTypeFunc::BTFTypeFunc(StringRef FuncName, uint32_t ProtoTypeId, + uint32_t Scope) : Name(FuncName) { Kind = BTF::BTF_KIND_FUNC; - BTFType.Info = Kind << 24; + BTFType.Info = (Scope << 30) | (Kind << 24); BTFType.Type = ProtoTypeId; } @@ -897,8 +898,9 @@ visitSubroutineType(SP->getType(), true, FuncArgNames, ProtoTypeId); // Construct subprogram func type + uint8_t Scope = SP->isLocalToUnit() ? BTF::FUNC_STATIC : BTF::FUNC_GLOBAL; auto FuncTypeEntry = - std::make_unique(SP->getName(), ProtoTypeId); + std::make_unique(SP->getName(), ProtoTypeId, Scope); uint32_t FuncTypeId = addType(std::move(FuncTypeEntry)); for (const auto &TypeEntry : TypeEntries) @@ -1163,20 +1165,10 @@ const std::unordered_map FuncArgNames; visitSubroutineType(SP->getType(), false, FuncArgNames, ProtoTypeId); - auto VarEntry = - std::make_unique(SP->getName(), ProtoTypeId, - BTF::VAR_GLOBAL_EXTERNAL); - uint32_t VarId = addType(std::move(VarEntry)); - - StringRef SecName = F.getSection(); - if (SecName.empty()) - SecName = ".extern"; - - if (DataSecEntries.find(SecName) == DataSecEntries.end()) { - DataSecEntries[SecName] = std::make_unique(Asm, SecName); - } - - DataSecEntries[SecName]->addVar(VarId, Asm->getSymbol(&F), 8); + uint8_t Scope = BTF::FUNC_EXTERN; + auto FuncTypeEntry = + std::make_unique(SP->getName(), ProtoTypeId, Scope); + addType(std::move(FuncTypeEntry)); } }