EXTRA_* and SAN_* build flags were not correctly propagated to bpftool
and resolve_btids when building selftests/bpf. This led to various
build errors on attempt to build with SAN_CFLAGS="-fsanitize=address",
for example.
Fix the makefiles to address this:
- Pass SAN_CFLAGS/SAN_LDFLAGS to bpftool and resolve_btfids build
- Propagate EXTRA_LDFLAGS to resolve_btfids link command
- Use pkg-config to detect zlib and zstd for resolve_btfids, similar
libelf handling
Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev>
---
tools/bpf/resolve_btfids/Makefile | 7 +++++--
tools/testing/selftests/bpf/Makefile | 9 +++++----
2 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile
index 1733a6e93a07..ef083602b73a 100644
--- a/tools/bpf/resolve_btfids/Makefile
+++ b/tools/bpf/resolve_btfids/Makefile
@@ -65,6 +65,9 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU
LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null)
LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf)
+ZLIB_LIBS := $(shell $(HOSTPKG_CONFIG) zlib --libs 2>/dev/null || echo -lz)
+ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null || echo -lzstd)
+
HOSTCFLAGS_resolve_btfids += -g \
-I$(srctree)/tools/include \
-I$(srctree)/tools/include/uapi \
@@ -73,7 +76,7 @@ HOSTCFLAGS_resolve_btfids += -g \
$(LIBELF_FLAGS) \
-Wall -Werror
-LIBS = $(LIBELF_LIBS) -lz
+LIBS = $(LIBELF_LIBS) $(ZLIB_LIBS) $(ZSTD_LIBS)
export srctree OUTPUT HOSTCFLAGS_resolve_btfids Q HOSTCC HOSTLD HOSTAR
include $(srctree)/tools/build/Makefile.include
@@ -83,7 +86,7 @@ $(BINARY_IN): fixdep FORCE prepare | $(OUTPUT)
$(BINARY): $(BPFOBJ) $(SUBCMDOBJ) $(BINARY_IN)
$(call msg,LINK,$@)
- $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
+ $(Q)$(HOSTCC) $(BINARY_IN) $(KBUILD_HOSTLDFLAGS) $(EXTRA_LDFLAGS) -o $@ $(BPFOBJ) $(SUBCMDOBJ) $(LIBS)
clean_objects := $(wildcard $(OUTPUT)/*.o \
$(OUTPUT)/.*.o.cmd \
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index c6bf4dfb1495..a0a594de9007 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -326,8 +326,8 @@ $(DEFAULT_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \
$(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/bpftool
$(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
ARCH= CROSS_COMPILE= CC="$(HOSTCC)" LD="$(HOSTLD)" \
- EXTRA_CFLAGS='-g $(OPT_FLAGS) $(EXTRA_CFLAGS)' \
- EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' \
+ EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS) $(EXTRA_CFLAGS)' \
+ EXTRA_LDFLAGS='$(SAN_LDFLAGS) $(EXTRA_LDFLAGS)' \
OUTPUT=$(HOST_BUILD_DIR)/bpftool/ \
LIBBPF_OUTPUT=$(HOST_BUILD_DIR)/libbpf/ \
LIBBPF_DESTDIR=$(HOST_SCRATCH_DIR)/ \
@@ -338,8 +338,8 @@ $(CROSS_BPFTOOL): $(wildcard $(BPFTOOLDIR)/*.[ch] $(BPFTOOLDIR)/Makefile) \
$(BPFOBJ) | $(BUILD_DIR)/bpftool
$(Q)$(MAKE) $(submake_extras) -C $(BPFTOOLDIR) \
ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) \
- EXTRA_CFLAGS='-g $(OPT_FLAGS) $(EXTRA_CFLAGS)' \
- EXTRA_LDFLAGS='$(EXTRA_LDFLAGS)' \
+ EXTRA_CFLAGS='-g $(OPT_FLAGS) $(SAN_CFLAGS) $(EXTRA_CFLAGS)' \
+ EXTRA_LDFLAGS='$(SAN_LDFLAGS) $(EXTRA_LDFLAGS)' \
OUTPUT=$(BUILD_DIR)/bpftool/ \
LIBBPF_OUTPUT=$(BUILD_DIR)/libbpf/ \
LIBBPF_DESTDIR=$(SCRATCH_DIR)/ \
@@ -404,6 +404,7 @@ $(RESOLVE_BTFIDS): $(HOST_BPFOBJ) | $(HOST_BUILD_DIR)/resolve_btfids \
$(Q)$(MAKE) $(submake_extras) -C $(TOOLSDIR)/bpf/resolve_btfids \
CC="$(HOSTCC)" LD="$(HOSTLD)" AR="$(HOSTAR)" \
LIBBPF_INCLUDE=$(HOST_INCLUDE_DIR) \
+ EXTRA_LDFLAGS='$(SAN_LDFLAGS) $(EXTRA_LDFLAGS)' \
OUTPUT=$(HOST_BUILD_DIR)/resolve_btfids/ BPFOBJ=$(HOST_BPFOBJ)
# Get Clang's default includes on this system, as opposed to those seen by
--
2.53.0
On Wed, Feb 11, 2026 at 5:14 PM Ihor Solodrai <ihor.solodrai@linux.dev> wrote: > > EXTRA_* and SAN_* build flags were not correctly propagated to bpftool > and resolve_btids when building selftests/bpf. This led to various > build errors on attempt to build with SAN_CFLAGS="-fsanitize=address", > for example. > > Fix the makefiles to address this: > - Pass SAN_CFLAGS/SAN_LDFLAGS to bpftool and resolve_btfids build > - Propagate EXTRA_LDFLAGS to resolve_btfids link command > - Use pkg-config to detect zlib and zstd for resolve_btfids, similar > libelf handling > > Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> > --- > tools/bpf/resolve_btfids/Makefile | 7 +++++-- > tools/testing/selftests/bpf/Makefile | 9 +++++---- > 2 files changed, 10 insertions(+), 6 deletions(-) > > diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile > index 1733a6e93a07..ef083602b73a 100644 > --- a/tools/bpf/resolve_btfids/Makefile > +++ b/tools/bpf/resolve_btfids/Makefile > @@ -65,6 +65,9 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU > LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) > LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) > > +ZLIB_LIBS := $(shell $(HOSTPKG_CONFIG) zlib --libs 2>/dev/null || echo -lz) > +ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null || echo -lzstd) The first two patches look serious enough and justify going to bpf tree. The rest can probably go via bpf as well, since we're early in the merge window. Would be great to have some Acks first though. Why add zstd here? It's not used by resolve_btfid. Why add it?
On 2/11/26 6:39 PM, Alexei Starovoitov wrote: > On Wed, Feb 11, 2026 at 5:14 PM Ihor Solodrai <ihor.solodrai@linux.dev> wrote: >> >> EXTRA_* and SAN_* build flags were not correctly propagated to bpftool >> and resolve_btids when building selftests/bpf. This led to various >> build errors on attempt to build with SAN_CFLAGS="-fsanitize=address", >> for example. >> >> Fix the makefiles to address this: >> - Pass SAN_CFLAGS/SAN_LDFLAGS to bpftool and resolve_btfids build >> - Propagate EXTRA_LDFLAGS to resolve_btfids link command >> - Use pkg-config to detect zlib and zstd for resolve_btfids, similar >> libelf handling >> >> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> >> --- >> tools/bpf/resolve_btfids/Makefile | 7 +++++-- >> tools/testing/selftests/bpf/Makefile | 9 +++++---- >> 2 files changed, 10 insertions(+), 6 deletions(-) >> >> diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile >> index 1733a6e93a07..ef083602b73a 100644 >> --- a/tools/bpf/resolve_btfids/Makefile >> +++ b/tools/bpf/resolve_btfids/Makefile >> @@ -65,6 +65,9 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU >> LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) >> LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) >> >> +ZLIB_LIBS := $(shell $(HOSTPKG_CONFIG) zlib --libs 2>/dev/null || echo -lz) >> +ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null || echo -lzstd) > > The first two patches look serious enough and justify going to bpf tree. > The rest can probably go via bpf as well, since we're early > in the merge window. > Would be great to have some Acks first though. > > Why add zstd here? It's not used by resolve_btfid. Why add it? IIRC zstd is a transitive dependency of libelf. I stumbled on a combination of build flags that caused link errors because of this missing. I can find or produce an example log later if that'd be helpful.
On 2/11/26 7:08 PM, Ihor Solodrai wrote: > > > On 2/11/26 6:39 PM, Alexei Starovoitov wrote: >> On Wed, Feb 11, 2026 at 5:14 PM Ihor Solodrai <ihor.solodrai@linux.dev> wrote: >>> >>> EXTRA_* and SAN_* build flags were not correctly propagated to bpftool >>> and resolve_btids when building selftests/bpf. This led to various >>> build errors on attempt to build with SAN_CFLAGS="-fsanitize=address", >>> for example. >>> >>> Fix the makefiles to address this: >>> - Pass SAN_CFLAGS/SAN_LDFLAGS to bpftool and resolve_btfids build >>> - Propagate EXTRA_LDFLAGS to resolve_btfids link command >>> - Use pkg-config to detect zlib and zstd for resolve_btfids, similar >>> libelf handling >>> >>> Signed-off-by: Ihor Solodrai <ihor.solodrai@linux.dev> >>> --- >>> tools/bpf/resolve_btfids/Makefile | 7 +++++-- >>> tools/testing/selftests/bpf/Makefile | 9 +++++---- >>> 2 files changed, 10 insertions(+), 6 deletions(-) >>> >>> diff --git a/tools/bpf/resolve_btfids/Makefile b/tools/bpf/resolve_btfids/Makefile >>> index 1733a6e93a07..ef083602b73a 100644 >>> --- a/tools/bpf/resolve_btfids/Makefile >>> +++ b/tools/bpf/resolve_btfids/Makefile >>> @@ -65,6 +65,9 @@ $(BPFOBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(LIBBPF_OU >>> LIBELF_FLAGS := $(shell $(HOSTPKG_CONFIG) libelf --cflags 2>/dev/null) >>> LIBELF_LIBS := $(shell $(HOSTPKG_CONFIG) libelf --libs 2>/dev/null || echo -lelf) >>> >>> +ZLIB_LIBS := $(shell $(HOSTPKG_CONFIG) zlib --libs 2>/dev/null || echo -lz) >>> +ZSTD_LIBS := $(shell $(HOSTPKG_CONFIG) libzstd --libs 2>/dev/null || echo -lzstd) >> >> The first two patches look serious enough and justify going to bpf tree. >> The rest can probably go via bpf as well, since we're early >> in the merge window. >> Would be great to have some Acks first though. >> >> Why add zstd here? It's not used by resolve_btfid. Why add it? > > IIRC zstd is a transitive dependency of libelf. > > I stumbled on a combination of build flags that caused link errors > because of this missing. I can find or produce an example log later > if that'd be helpful. Reproduced the splat. See below. Basically, the bug here was that building selftests/bpf with EXTRA_LDFLAGS="-static" didn't propagate -static to resolve_btfids so zstd and co were actually linked dynamically. After I fixed the propagation of EXTRA_LDFLAGS, the static build of selftests would fail on linking of resolve_btfids, because of -zstd missing: LINK resolve_btfids /usr/bin/x86_64-linux-gnu-ld.bfd: /lib/x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_compress': (.text+0xe4): undefined reference to `ZSTD_createCCtx' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x243): undefined reference to `ZSTD_compressStream2' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x24e): undefined reference to `ZSTD_isError' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x272): undefined reference to `ZSTD_freeCCtx' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x4ff): undefined reference to `ZSTD_compressStream2' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x50a): undefined reference to `ZSTD_isError' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x6e1): undefined reference to `ZSTD_freeCCtx' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x708): undefined reference to `ZSTD_freeCCtx' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x78e): undefined reference to `ZSTD_freeCCtx' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x828): undefined reference to `ZSTD_freeCCtx' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0x8f7): undefined reference to `ZSTD_freeCCtx' /usr/bin/x86_64-linux-gnu-ld.bfd: /lib/x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress': (.text+0xaf7): undefined reference to `ZSTD_decompress' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0xb02): undefined reference to `ZSTD_isError' /usr/bin/x86_64-linux-gnu-ld.bfd: /lib/x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf': (.text+0xc37): undefined reference to `ZSTD_decompress' /usr/bin/x86_64-linux-gnu-ld.bfd: (.text+0xc42): undefined reference to `ZSTD_isError' clang-21: error: linker command failed with exit code 1 (use -v to see invocation) make[1]: *** [Makefile:89: /ws/linux/tools/testing/selftests/bpf/tools/build/resolve_btfids//resolve_btfids] Error 1 make: *** [Makefile:404: /ws/linux/tools/testing/selftests/bpf/tools/build/resolve_btfids/resolve_btfids] Error 2 make: *** Waiting for unfinished jobs....
© 2016 - 2026 Red Hat, Inc.