-
Notifications
You must be signed in to change notification settings - Fork 659
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 weak symbols / symbol visibility #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 |
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: