bpftool icon indicating copy to clipboard operation
bpftool copied to clipboard

missing zstd library when building statically on Ubuntu 24.04

Open mtardy opened this issue 1 year ago • 4 comments

When building bpftool statically on Ubuntu 24.04 (note that it works fine on 22.04), -lzstd must be added to LIBS and BOOTSTRAP_LIBS. See my "live patch" https://github.com/cilium/tetragon/pull/2777/commits/8e994cf0bc2ad2ccd88ba9a490913052a1b9a825.

Would it make sense to upstream that? I would be happy to.

I have a repro, do the following steps with ubuntu:22.04 and ubuntu:24.04 (replace clang 15 with clang 18 on 24.04)

apt-get update && apt-get install -y --no-install-recommends clang-15 libclang-common-15-dev libclang-cpp15 libllvm15 llvm-15-linker-tools libclang1-15 llvm-15 llvm-15-runtime llvm-15-linker-tools make
apt-get update && apt-get install -y curl git llvm gcc pkg-config zlib1g-dev libelf-dev libcap-dev
git clone https://github.com/libbpf/bpftool.git
cd bpftool
git submodule update --init --recursive
make -C src EXTRA_CFLAGS=--static EXTRA_LDFLAGS=-v -j $(nproc) && strip src/bpftool

mtardy avatar Aug 16 '24 13:08 mtardy

Thanks for the report! We'll need to update both the kernel and the mirror repo, independently. Do you have more context on the change, by any chance? Is there a way to figure out whether the -lzstd is required without having to add a new set of probes?

qmonnet avatar Aug 21 '24 23:08 qmonnet

Thanks for the report! We'll need to update both the kernel and the mirror repo, independently. Do you have more context on the change, by any chance? Is there a way to figure out whether the -lzstd is required without having to add a new set of probes?

Tbh I don't exactly know the "why", I just ended up finding that it fixed my issue when using the newer Ubuntu version. I could investigate to see!

mtardy avatar Aug 22 '24 09:08 mtardy

I hit the same problem, for what is worth zstd is required by libelf. It could be that older versions of libelf didn't use zstd.

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/13/../../../x86_64-linux-gnu/libelf.a(elf_compress.o): in function `__libelf_decompress_elf':
(.text+0xd45): undefined reference to `ZSTD_decompress'

petrutlucian94 avatar Sep 11 '24 09:09 petrutlucian94

Yes. Elfutils commit a5b07cdf9c49 adds support for ZSTD compression, since elfutils 0.189.

Ubuntu 22.04 ships version 0.186 (or 0.188 in backports), Ubuntu 24.04 has 0.189 or 0.190 depending on the arch.

qmonnet avatar Sep 11 '24 09:09 qmonnet

@mtardy Were you working on upstreaming a fix at all for this issue? I can't remember

qmonnet avatar Oct 29 '24 22:10 qmonnet

@mtardy Were you working on upstreaming a fix at all for this issue? I can't remember

I'm not, sorry!

mtardy avatar Oct 30 '24 11:10 mtardy

https://lore.kernel.org/bpf/[email protected]/t/#u

qmonnet avatar Dec 11 '24 13:12 qmonnet

Merged in perf tree and made it to linux-next, but this hasn't been synced with bpf-next (from where we update this mirror repo) yet.

qmonnet avatar Jan 15 '25 10:01 qmonnet

Fixed in Makefile with https://github.com/libbpf/bpftool/commit/67f1758bd7889bbec1ec5dab56888b19ec7212f3, corresponding probe in GitHub mirror repo in https://github.com/libbpf/bpftool/commit/f964613f2218981e81c6cf331b79f531bbaa148a.

We still need the flag and probe for libbfd, though (#73).

qmonnet avatar Jul 23 '25 21:07 qmonnet