On Sun, Nov 07, 2021 at 10:13:09PM -0800, Andrii Nakryiko wrote: > Add test_progs-shared flavor to compile against libbpf as a shared > library. This is useful to make sure that libbpf's backwards/forward > compatibility guarantees are upheld. Currently this has to be checked > locally, but in the future we'll automate at least some scenarios as > part of libbpf CI runs. > > Biggest change is how either libbpf.a or libbpf.so is passed to the > compiler, which is controled on per-flavor through a new TRUNNER_LIBBPF > parameter. All the places that depend on libbpf artifacts (headers, > library itself, etc) to be built are moved to order-only dependency on > $(BPFOBJ). rpath is used to specify relative location to where libbpf.so > should be so that when test_progs-shared is run under QEMU, libbpf.so is > still going to be discovered correctly. > > Few selftests are using or testing internal libbpf APIs, so are not > compatible with shared library use of libbpf. Filter them out for shared > flavor. ... > +# Define test_progs-shared test runner. > +TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE > +TRUNNER_BPF_CFLAGS := $(BPF_CFLAGS) $(CLANG_CFLAGS) -DENABLE_ATOMICS_TESTS > +TRUNNER_EXTRA_CFLAGS := -Wl,-rpath=$(subst $(CURDIR)/,,$(dir $(BPFOBJ))) > +TRUNNER_LIBBPF := $(patsubst %libbpf.a,%libbpf.so,$(BPFOBJ)) > +TRUNNER_TESTS_BLACKLIST := cpu_mask.c hashmap.c perf_buffer.c raw_tp_test_run.c > +$(eval $(call DEFINE_TEST_RUNNER,test_progs,shared)) > +TRUNNER_TESTS_BLACKLIST := It's a good idea to add libbpf.so test, but going through test_progs is imo overkill. No reason to run more than one test with shared lib. If it links fine it's pretty much certain that it will work. Maybe convert test_maps into shared only? CI runs it already.