-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bcc internals: Keep track of BPF progs using function instead of section #3660
bcc internals: Keep track of BPF progs using function instead of section #3660
Conversation
[buildbot, test this please] |
[buildbot, ok to test] |
string attr = string("__attribute__((section(\"") + BPF_FN_PREFIX + D->getName().str() + "\")))\n"; | ||
rewriter_.InsertText(real_start_loc, attr); | ||
if (SectionAttr *A = D->getAttr<SectionAttr>()) { | ||
func_info->section_ = A->getName().str(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
section_
can also be set when object is loaded (and is - see notifyObjectLoaded
)
I'm inclined to remove this in favor of notifyObjectLoaded
as that's at the end of the compilation process and therefore leaves less (no?) room for unexpected section changes that the FrontendAction might not know about.
abc9b4e
to
55dda4b
Compare
There are quite some test failures. Maybe trying to resolve them first? For example, the following is a link to fc27 failure: You can run the test on your local machine easily for most tests. |
55dda4b
to
ce74405
Compare
Some btf_ext-related APIs in libbpf are being deprecated because they make incorrect assumptions. They're being used only by bcc currently, so vendor them before they get deleted. After / as part of iovisor#3660, may need to revisit the incorrect assumptions being made here. The functions and structs were ripped directly from libbpf with minimal changes: * Change void* arithmetic to uint8_t * __u32 -> uint32_t and similar * Add a wrapping namespace * `rec_size` functions were not needed - just grab the rec_size directly since type is no longer opaque to bcc
Some btf_ext-related APIs in libbpf are being deprecated because they make incorrect assumptions. They're being used only by bcc currently, so vendor them before they get deleted. After / as part of iovisor#3660, may need to revisit the incorrect assumptions being made here. The functions and structs were ripped directly from libbpf with minimal changes: * Change void* arithmetic to uint8_t * __u32 -> uint32_t and similar * Add a wrapping namespace * `rec_size` functions were not needed - just grab the rec_size directly since type is no longer opaque to bcc
Some btf_ext-related APIs in libbpf are being deprecated because they make incorrect assumptions. They're being used only by bcc currently, so vendor them before they get deleted. After / as part of iovisor#3660, may need to revisit the incorrect assumptions being made here. The functions and structs were ripped directly from libbpf with minimal changes: * Change void* arithmetic to uint8_t * __u32 -> uint32_t and similar * Add a wrapping namespace * `rec_size` functions were not needed - just grab the rec_size directly since type is no longer opaque to bcc
Some btf_ext-related APIs in libbpf are being deprecated because they make incorrect assumptions. They're being used only by bcc currently, so vendor them before they get deleted. After / as part of iovisor#3660, may need to revisit the incorrect assumptions being made here. The functions and structs were ripped directly from libbpf with minimal changes: * Change void* arithmetic to uint8_t * __u32 -> uint32_t and similar * Add a wrapping namespace * `rec_size` functions were not needed - just grab the rec_size directly since type is no longer opaque to bcc
Some btf_ext-related APIs in libbpf are being deprecated because they make incorrect assumptions. They're being used only by bcc currently, so vendor them before they get deleted. After / as part of #3660, may need to revisit the incorrect assumptions being made here. The functions and structs were ripped directly from libbpf with minimal changes: * Change void* arithmetic to uint8_t * __u32 -> uint32_t and similar * Add a wrapping namespace * `rec_size` functions were not needed - just grab the rec_size directly since type is no longer opaque to bcc
e88dfa7
to
cc8c94b
Compare
@yonghong-song this is finally in a reasonable state now that test infra is better, please take a look when you have the chance edit: But I'd like to do the last step of manual testing (in checklist) before it gets merged |
Thanks @davemarchevsky I will look at the patch tomorrow. |
I tried the patch with latest upstream llvm, which I built clang/llvm binary from source. I got
The same for
Could you take a look? |
Okay, I did a little bit study on my above issues. It happened with latest upstream llvm. The reason is due to function signature change. The following can fix the compilation issue.
I briefly looked at the code. Look good to me in high level. I will go through another round in detail once the patch is updated to fix the issues with llvm14. |
@yonghong-song nice catch! I haven't been able to repro yet, have been struggling to get LLVM to build in a docker container in Speaking of which, I looked in the code and it seems that this |
@davemarchevsky the following is my llvm cmake build command,
In the auto generated code, I do have LLVM_ENABLE_ABI_BREAKING_CHECKS equal to 1.
|
Also, for your information, my code is essentially copied from/similar to below |
Replace usage of the raw string with macro. Signed-off-by: Dave Marchevsky <[email protected]>
bcc currently identifies each individual BPF prog in an object file by putting the prog in a special ".bpf.fn.$FUNC_NAME" section when preprocessing the AST. After JITting an object file, the location and size of the section are considered to be "the function's insns". In order to support libbpf-style loading, we need to support its sec_def-style SEC() attributes e.g. SEC("tp_btf/softirq_entry"), which allow libbpf to determine the type of BPF prog - and often other information like where to attach - based on the section name. These are not guaranteed to be unique per function, so we can no longer assume that a section contains only one function. This commit gets rid of that assumption. bcc now finds the symbol in the JITed image matching each BPF prog function and uses it to determine size/location. Also, this commit only adds the ".bpf.fn.$FUNC_NAME" section attribute iff there isn't already a custom section attribute set. Signed-off-by: Dave Marchevsky <[email protected]>
cc8c94b
to
8323d74
Compare
@yonghong-song Updated and revalidated - but I was never able to repro the exact errors you were seeing in a docker environment. I went with a smaller change to deal with --- a/src/cc/bpf_module.cc
+++ b/src/cc/bpf_module.cc
@@ -92,18 +92,25 @@ class MyMemoryManager : public SectionMemoryManager {
const object::ObjectFile &o) override {
auto sizes = llvm::object::computeSymbolSizes(o);
for (auto ss : sizes) {
- std::string name = ss.first.getName()->str();
+ auto maybe_name = ss.first.getName();
+ if (!maybe_name)
+ continue;
+
+ std::string name = maybe_name->str();
auto info = prog_func_info_->get_func(name);
- if (info) {
- StringRef sec;
-#if LLVM_MAJOR_VERSION >= 10
- sec = *ss.first.getSection().get()->getName();
-#else
- ss.first.getSection().get()->getName(sec);
-#endif
- info->section_ = sec.str();
- info->size_ = ss.second;
- }
+ if (!info)
+ continue;
+
+ auto section = ss.first.getSection();
+ if (!section)
+ continue;
+
+ auto sec_name = section.get()->getName();
+ if (!sec_name)
+ continue;
+
+ info->section_ = sec_name->str();
+ info->size_ = ss.second;
}
} ( |
tested with llvm13/llvm14 and in-progress llvm15. all passed. did another round of source checking, looks good to me. |
Some btf_ext-related APIs in libbpf are being deprecated because they make incorrect assumptions. They're being used only by bcc currently, so vendor them before they get deleted. After / as part of iovisor#3660, may need to revisit the incorrect assumptions being made here. The functions and structs were ripped directly from libbpf with minimal changes: * Change void* arithmetic to uint8_t * __u32 -> uint32_t and similar * Add a wrapping namespace * `rec_size` functions were not needed - just grab the rec_size directly since type is no longer opaque to bcc
Context: I'm working on a project to enable bcc to create object files which can be loaded by
libbpf
's loader. This will make enabling "modern"libbpf
features - e.g. global variables - significantly easier and by its nature would make an AOT-compiled mode for bcc straightforward. bcc programs should be able to use this mode with minimal code changes.In order to do this we need to support libbpf-style
SEC
attribute annotations, which requires some modification of internal loader/bookkeeping plumbing. The summary of the major commit in this branch elaborates:Status: I need to address a few things before this is in a mergeable state
BPFModule
still needsections_
? If not, let's get rid of itprog_func_info_
-owned memory similarly tosections_
now (when not usingrw_engine
)SOURCE_DEBUG
) should work w/ custom sec names