[PATCH] D71638: [WIP][BPF] extern BTF_KIND_FUNC to cover global, static and extern funcs
Yonghong Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 17 16:49:24 PST 2019
yonghong-song created this revision.
yonghong-song added reviewers: ast, anakryiko.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.
Previous extern function is added as BTF_KIND_VAR. This does not work
well with existing BTF infrastructure as function expected to use
BTF_KIND_FUNC and BTF_KIND_FUNC_PROTO.
This patch added extern function to BTF_KIND_FUNC. The top two bits
of btf_type.info are used to indicate what kind of function it is:
0: static
1: global
2: extern
one example:
-bash-4.4$ cat t.c
extern int foo(void);
static __attribute__((noinline)) int test1() { return foo(); }
int test2() { return test1(); }
-bash-4.4$ clang -target bpf -O2 -g -S t.c
...
.long 0 # BTF_KIND_FUNC_PROTO(id = 1)
.long 218103808 # 0xd000000
.long 2
.long 1 # BTF_KIND_INT(id = 2)
.long 16777216 # 0x1000000
.long 4
.long 16777248 # 0x1000020
.long 5 # BTF_KIND_FUNC(id = 3)
.long 1275068416 # 0x4c000000
.long 1
.long 0 # BTF_KIND_FUNC_PROTO(id = 4)
.long 218103808 # 0xd000000
.long 2
.long 68 # BTF_KIND_FUNC(id = 5)
.long 201326592 # 0xc000000
.long 4
.long 0 # BTF_KIND_FUNC_PROTO(id = 6)
.long 218103808 # 0xd000000
.long 2
.long 137 # BTF_KIND_FUNC(id = 7)
.long 2348810240 # 0x8c000000
.long 6
.ascii "test2" # string offset=5
.ascii "test1" # string offset=68
.ascii "foo" # string offset=137
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71638
Files:
llvm/lib/Target/BPF/BTF.h
llvm/lib/Target/BPF/BTFDebug.cpp
llvm/lib/Target/BPF/BTFDebug.h
Index: llvm/lib/Target/BPF/BTFDebug.h
===================================================================
--- llvm/lib/Target/BPF/BTFDebug.h
+++ 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);
Index: llvm/lib/Target/BPF/BTFDebug.cpp
===================================================================
--- llvm/lib/Target/BPF/BTFDebug.cpp
+++ 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<BTFTypeFunc>(SP->getName(), ProtoTypeId);
+ std::make_unique<BTFTypeFunc>(SP->getName(), ProtoTypeId, Scope);
uint32_t FuncTypeId = addType(std::move(FuncTypeEntry));
for (const auto &TypeEntry : TypeEntries)
@@ -1163,20 +1165,10 @@
const std::unordered_map<uint32_t, StringRef> FuncArgNames;
visitSubroutineType(SP->getType(), false, FuncArgNames, ProtoTypeId);
- auto VarEntry =
- std::make_unique<BTFKindVar>(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<BTFKindDataSec>(Asm, SecName);
- }
-
- DataSecEntries[SecName]->addVar(VarId, Asm->getSymbol(&F), 8);
+ uint8_t Scope = BTF::FUNC_EXTERN;
+ auto FuncTypeEntry =
+ std::make_unique<BTFTypeFunc>(SP->getName(), ProtoTypeId, Scope);
+ addType(std::move(FuncTypeEntry));
}
}
Index: llvm/lib/Target/BPF/BTF.h
===================================================================
--- llvm/lib/Target/BPF/BTF.h
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71638.234414.patch
Type: text/x-patch
Size: 2843 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191218/eb14620f/attachment.bin>
More information about the llvm-commits
mailing list