libbpf / bpftool

Automated upstream mirror for bpftool stand-alone build.
Other
406 stars 72 forks source link

Test for bpf_perf_link #88

Closed hramrach closed 1 year ago

hramrach commented 1 year ago

vmlinux.h is generated from the running kernel, not system headers.

When the running kernel is older than 5.15 it lacks bpf_perf_link and build fails.

Detect presence of the structure and skip building the part of code that requires it when it is not present.

Fixes: #17

qmonnet commented 1 year ago

Thanks! But such contributions shouldn't be submitted against this repo which is just a mirror, this is the kind of fixes that need to be sent to the BPF mailing list.

As for the fix itself, we shouldn't need another feature detection item. We should be able to deal with the absence of bpf_perf_link with CO-RE, I would rather like to see the patches from Alexander merged upstream. I emailed him a few days ago to see if he was still working on the patchset, but haven't heard back yet.

hramrach commented 1 year ago

Thanks for pointing out that patchset. Apparently this is not limited to old kernels, the feature can be disabled by a config option so this should be handled more gracefully.

hramrach commented 1 year ago

This is now dump of the relevant patches form the mentioned mail thread.

With this the package can be built but YMMV.

Hopefully this will eventually make it into the official repository.

qmonnet commented 1 year ago

Thanks! Yes it will, these patches are long overdue. I'll try to post them this weekend if I can, next week otherwise.

qmonnet commented 1 year ago

With this the package can be built

Out of curiosity, what kernel versions did you check? 5.14, I guess, but did you manage to build on 5.3 as well?

hramrach commented 1 year ago

I am using distribution kernels so the results are not transferable to other environments. Interestingly it did build even with the 5.3 kernel version that is not patched to support module BTF and as far as BTF goes it should be pretty close to upstream.

qmonnet commented 1 year ago

@hramrach I've got a slightly different patchset, with the CO-RE checks for existence of the enum value (bpf_core_enum_value_exists()). This works on a host with 5.8, but I had to upgrade the LLVM version (it relies on __builtin_preserve_enum_value, which is LLVM 12 if I remember correctly). This seems acceptable in my case, but won't help much in yours if you can't use recent LLVM versions.

So just checking before sending the series, what clang/LLVM versions are available on your env?

hramrach commented 1 year ago

Thanks for updating the patches.

It builds with llvm 12/13/16 depending on distribution release. Not sure there is much point going further back in llvm archaeology, somebody with a different llvm collection would have to answer that. I don't have any older llvm prebuilt that is also usable for bpf. The exact usability is also questionable, any functional tests will have to come once the package is buildable, and the scope depends very much on how people happen to use it.

qmonnet commented 1 year ago

It builds with llvm 12/13/16 depending on distribution release.

LLVM 12+ is all I needed to know. Perfect, thanks!