-
Notifications
You must be signed in to change notification settings - Fork 409
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
[CO-RE] relocations are not emitted for tracepoint 'context' argument. #793
Comments
You need very recent llvm-objdump to see CO-RE relocations with -r argument. If you have a bit older one, you won't see it, even though it's there. You can also try using https://github.com/anakryiko/btfdump to see recorded CO-RE relocations. And also the way CO-RE relocations work is that compiler still emits a correct instruction (as of vmlinux.h definitions) with hard-coded offsets and so on, but also CO-RE relocation information pointing to this instruction. libbpf will then update instruction with adjusted offset, according to actual vmlinux BTF on target host. You can also see all CO-RE relocations that libbpf is processing by looking at debug-level log output from libbpf. |
@anakryiko thanks for quick response. I double checked and you are correct, newer The cross-platform BPF load failure was caused by 'fail_memsz_adjust', since it was trying to relocate Speaking of, do you think that it would make sense to introduce some kind of a The rationale is that I inserted Also, thanks for your help in resolving the issue! |
libbpf doesn't fail BPF program loading, if relocation failed (but if it does, please provide full libbpf log, including debug level information). It just "poisons" those instructions, which is what will be rejected by verifier in the kernel. But, you can guard such poisoned instructions with additional checks, and if verifier sees that such poisoned code is unreachable, it won't complain. This allows to guard optional parts of code that rely on some unsupported (on old kernels) features, as long as it's properly detected and guarded. |
indeed. consider however such scenario: instead of if (res->fail_memsz_adjust) {
pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) accesses field incorrectly. "
"Make sure you are accessing pointers, unsigned integers, or fields of matching type and size.\n",
prog_name, relo_idx, insn_idx);
goto poison;
}
orig_val = insn->off;
insn->off = new_val; we have this: if (res->fail_memsz_adjust) {
pr_warn("prog '%s': relo #%d: insn #%d (LDX/ST/STX) accesses field incorrectly. "
"Make sure you are accessing pointers, unsigned integers, or fields of matching type and size.\n",
prog_name, relo_idx, insn_idx);
if !(config_allow_unsafe_relocs)
goto poison;
}
orig_val = insn->off;
insn->off = new_val; in that case user will be warned, and, for example, their 64-bit memory load will be clamped to lower 32-bits. and there is some chance that their code might still work properly (to some extent! but still might be useful). so, if I understand correctly, you are saying about different code paths for different kernel version. and my use case is same code executed by any kernel, but in "unsafe" way, that might change it's semantics - by reducing width of memory accesses, if cross compiling on 64-bit kernel to 32-bit kernel. Note that we already do this clamping, but only for |
I don't think "sloppy_relocation" option is a good way forward. If you are running into this problem with a valid program, let's see if we can fix the problem itself. I'm going on vacation soon, so unlikely I'll have time for this in the next 2 weeks or so, but please share (minimal) source code and compiled .bpf.o file for your use case that fails. Thanks! |
And corresponding
llvm-objdump -rd
output:What is the reason that 16-byte offset is hardcoded in first instruction?
I suspect that it causes issues when I cross-compile for different kernel and different architecture, though I use proper vmlinux.h.
tail of
./opensnoop
output on my armv7l target:And corresponding
llvm-objdump
:The text was updated successfully, but these errors were encountered: