-
Notifications
You must be signed in to change notification settings - Fork 652
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
Add support for function pointers #499
Add support for function pointers #499
Conversation
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.
Thanks for the PR! I've left a couple of comments, it looks good overall :)
Can you add some tests outside of the libbpf integration please? It's not trivial to debug those if they fail, and we're pretty lax when getting errors from these tests. I think you should be able to adjust loader.c to include a load of a function pointer.
Hi @lmb , thank you for your comments. I'll polish the code and add some tests as you suggested. |
0af08c7
to
233574d
Compare
I added a test in elf_reader_test.go for subprogram relocation. AFAIK this kind of relocation is supported from 5.13 onwards (running the test on with my distro kernel, v5.10, leads to a fail, instead it passes on a v5.15. And the same goes using libbpf). To avoid complicating things too much in loader.c, I wrote a separate BPF program and Go test, adding |
I realized that I misunderstood the reason why the test needs a kernel >= 5.13. Regarding the CI failure I find it surprising: maybe just a matter of flakyness? Unfortunately I am not able to see the output from the failing test on semaphore. |
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.
I think requiring 5.13 for the test is OK as long as it's documented why. What use is there for subprog loads before for_each_map_elem appeared?
offset := int64(int32(ins.Constant)+1) * asm.InstructionSize | ||
if offset < 0 { | ||
return fmt.Errorf("call: %s: invalid offset %d", name, offset) | ||
case elf.STT_SECTION: |
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.
So a load of a static function doesn't require the same offset fixup as for Call?
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.
No, they are relocated in a slightly different way: https://github.com/libbpf/libbpf/blob/472c0726e84d821186a315889c885b23895b155e/src/libbpf.c#L5963-L5966
233574d
to
84e9f21
Compare
TBH I am not aware of any other case. Digging a little bit through the relevant kernel patches it seems that this kind of relocation has been introduced to support that helper in the first place: https://www.spinics.net/lists/bpf/msg35623.html |
Signed-off-by: Fabio Falzoi <fabio.falzoi84@gmail.com>
Signed-off-by: Fabio Falzoi <fabio.falzoi84@gmail.com>
Signed-off-by: Fabio Falzoi <fabio.falzoi84@gmail.com>
84e9f21
to
8a464bd
Compare
Thanks! |
Thank you for your review and comments! |
This PR adds support for function pointer relocations, following the same logic in libbpf: torvalds/linux@53eddb5
For example, this kind of relocation is needed when using helpers such as:
long bpf_for_each_map_elem(struct bpf_map *map, void *callback_fn, void *callback_ctx, u64 flags)
which takes a callback as a parameter.
The kernel selftests
for_each_array_{array,map}_elem
have been enabled as they should be supported now.Fixes #467