bpf_program__set_autoattach()'s return type changed from void to int to let callers observe the new -EINVAL rejection for MANUAL-strategy programs, but the symbol stayed under its original LIBBPF_1.0.0 node in libbpf.map. Binaries already linked against the old void-returning ABI recorded a request for exactly that symbol@version pair at link time; without a version bump they would silently start hitting the new rejection behavior underneath them after a libbpf upgrade. Split the symbol via ELF symbol versioning: - bpf_program__set_autoattach_deprecated() keeps the original unconditional behavior, bound via COMPAT_VERSION() to the existing LIBBPF_1.0.0 node. - bpf_program__set_autoattach_v1_8_0() carries the new MANUAL-rejecting behavior, bound via DEFAULT_VERSION() to the new LIBBPF_1.8.0 node. Old binaries keep resolving bpf_program__set_autoattach() to the old behavior at runtime; anything linked against the current headers/map gets the new int-returning, MANUAL-rejecting behavior. Also adds the missing __LIBBPF_MARK_DEPRECATED_1_8 gate to libbpf_common.h (only the 1.0 gate existed) so LIBBPF_DEPRECATED_SINCE(1, 8, ...) can mark the deprecated variant. Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Andrey Grodzovsky --- tools/lib/bpf/libbpf.c | 9 ++++++++- tools/lib/bpf/libbpf.h | 6 ++++++ tools/lib/bpf/libbpf.map | 2 ++ tools/lib/bpf/libbpf_common.h | 6 ++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 85e1d9c775ab..224fb0247a39 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -9974,7 +9974,14 @@ bool bpf_program__autoattach(const struct bpf_program *prog) return prog->autoattach; } -int bpf_program__set_autoattach(struct bpf_program *prog, bool autoattach) +COMPAT_VERSION(bpf_program__set_autoattach_deprecated, bpf_program__set_autoattach, LIBBPF_1.0.0) +void bpf_program__set_autoattach_deprecated(struct bpf_program *prog, bool autoattach) +{ + prog->autoattach = autoattach; +} + +DEFAULT_VERSION(bpf_program__set_autoattach_v1_8_0, bpf_program__set_autoattach, LIBBPF_1.8.0) +int bpf_program__set_autoattach_v1_8_0(struct bpf_program *prog, bool autoattach) { if (prog->load_strategy == BPF_PROG_LOAD_STRATEGY_MANUAL) return libbpf_err(-EINVAL); diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index faea42f75847..d172c137cc37 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -393,6 +393,12 @@ LIBBPF_API bool bpf_program__autoload(const struct bpf_program *prog); LIBBPF_API int bpf_program__set_autoload(struct bpf_program *prog, bool autoload); LIBBPF_API bool bpf_program__autoattach(const struct bpf_program *prog); LIBBPF_API int bpf_program__set_autoattach(struct bpf_program *prog, bool autoattach); +/* this "specialization" should go away once the deprecation window for + * bpf_program__set_autoattach_deprecated() closes + */ +LIBBPF_API int bpf_program__set_autoattach_v1_8_0(struct bpf_program *prog, bool autoattach); +LIBBPF_DEPRECATED_SINCE(1, 8, "use int-returning bpf_program__set_autoattach() instead") +LIBBPF_API void bpf_program__set_autoattach_deprecated(struct bpf_program *prog, bool autoattach); struct bpf_insn; diff --git a/tools/lib/bpf/libbpf.map b/tools/lib/bpf/libbpf.map index 8def5474885a..999e791d9887 100644 --- a/tools/lib/bpf/libbpf.map +++ b/tools/lib/bpf/libbpf.map @@ -465,6 +465,8 @@ LIBBPF_1.8.0 { bpf_program__clone; bpf_program__load; bpf_program__load_strategy; + bpf_program__set_autoattach; + bpf_program__set_autoattach_deprecated; bpf_program__set_load_strategy; btf__find_by_name_kind_own; btf__new_empty_opts; diff --git a/tools/lib/bpf/libbpf_common.h b/tools/lib/bpf/libbpf_common.h index 8fe248e14eb6..12ad4f5f558f 100644 --- a/tools/lib/bpf/libbpf_common.h +++ b/tools/lib/bpf/libbpf_common.h @@ -36,6 +36,12 @@ #define __LIBBPF_MARK_DEPRECATED_1_0(X) #endif +#if __LIBBPF_CURRENT_VERSION_GEQ(1, 8) +#define __LIBBPF_MARK_DEPRECATED_1_8(X) X +#else +#define __LIBBPF_MARK_DEPRECATED_1_8(X) +#endif + /* This set of internal macros allows to do "function overloading" based on * number of arguments provided by used in backwards-compatible way during the * transition to libbpf 1.0 -- 2.34.1