-
Notifications
You must be signed in to change notification settings - Fork 729
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
elf: support bpf object linking (bpftool gen object
)
#466
Comments
I did a bit of research on this topic. Libbpf did quite some work around Since we currently don't have any need for logic to do this, we can simply treat STB_WEAK symbols as global symbols, which in practice seems to be a small change. During the investigation, I tried to replicate some of the kernels selftests where I did discover a few shortcomings:
These are independent of the handling of weak symbols, but I wanted to note them here so I don't forget. Shall I turn these into separate issues? I still need to look into the effect of |
Yes please! |
I'd probably prefer to not allow WEAK in that case. That leaves the door open to later on add support for linking in some form. I've long thought that it could be very useful to be able to ship BPF in a go module somehow, and then express BPF library dependencies via Go modules (with linking via WEAK). |
I would have to confirm, but I believe that even after linking with Additionally, even if we don't want to support it for maps, ksym variables, or bpf-to-bpf functions, I think we do want to support it for kfuncs, see the use case described in #1355. Lucky that is a 1 line change. |
I conducted an experiment, made 2 simple programs: Weak 1
Weak 2
Then combined them with Which yields:
So what bpftool does is it combines the weak functions in the same order in which they were specified on the CLI tool. If we look at it with metadata, you can see that there is only 1 symbol but 2 BPF funcs. Also the relo entries are still STB_WEAK even after linking.
Loading without modifications results in So if we want to support |
Is there any chance of adding support for __weak maps? I'm working with BPF code originally written to work with libbpf and the authors made extensive use of __weak maps. thanks, Ken |
I looked at how libbpf handles weak maps. There does not seem to be any special handling at the loader level like we have with something like kfuncs or ksyms. When used with maps it seems to be purely about being able to override at link time with |
Thanks Dylan. The error that we see when loading a weak BPF map is: Having looked at the other recent fix for Changing elf_reader.go:504 from That yields a different error: |
Ah. I think with the maps something similar is happening to what I observed with the functions. In this case it seems that the We will need to change |
Thanks for the quick reply. |
bpftool gen object
)
I've updated the title of the issue to better reflect the current state. We now support weak symbols, but we don't yet support the intricacies of linked objects. |
libbpf has added support for weak symbols, which end up in ELF with an STB_WEAK binding.
libbpf commits that might be relevant due to mentioning STB_WEAK:
linked_maps.c fails due to:
linked_funcs.c:
There is also the following, not sure if that needs additional code:
The text was updated successfully, but these errors were encountered: