should ship with a static library
Task Info (Flyspray) | |
---|---|
Opened By | Max (qtmax) |
Task ID | 78526 |
Type | Feature Request |
Project | Arch Linux |
Category | Packages: Core |
Version | None |
OS | All |
Opened | 2023-05-15 19:03:33 UTC |
Status | Assigned |
Assignee | Jelle van der Waa (jelly) |
Assignee | Levente Polyak (anthraxx) |
Assignee | Giancarlo Razzolini (grazzolini) |
Details
Description:
When static linking with libelf, linking fails because of missing libzstd.a (see the steps below).
libelf ships with libelf.a, libelf depends on zlib and zstd (pkg-config --libs --static libelf
returns -lelf -lz -lzstd
, and both zlib and zstd are in the package dependencies), zlib ships with libz.a, however, libzstd.a is missing from the zstd package, which breaks the dependency chain.
The zstd package should provide libzstd.a to satisfy the dependency of libelf.
Additional info:
- libelf 0.189-1, zstd 1.5.5-1
Steps to reproduce (minimal):
$ echo '#include <libelf.h>' > /tmp/test.c $ echo 'int main() { return elf_compress(0, 0, 0); }' >> /tmp/test.c $ gcc -c /tmp/test.c -o /tmp/test.o $ gcc -static /tmp/test.o -lelf -lzstd -lz -o /dev/null
The last command fails with:
/usr/bin/ld: cannot find -lzstd: No such file or directory collect2: error: ld returned 1 exit status
After removing -lzstd, it fails with:
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../lib/libelf.a(elf_compress.o): in function __libelf_compress': (.text+0x103): undefined reference to
ZSTD_createCCtx'
/usr/bin/ld: (.text+0x286): undefined reference to ZSTD_compressStream2' /usr/bin/ld: (.text+0x292): undefined reference to
ZSTD_isError'
/usr/bin/ld: (.text+0x2be): undefined reference to ZSTD_freeCCtx' /usr/bin/ld: (.text+0x542): undefined reference to
ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x68a): undefined reference to ZSTD_freeCCtx' /usr/bin/ld: (.text+0x759): undefined reference to
ZSTD_freeCCtx'
/usr/bin/ld: (.text+0x7b5): undefined reference to ZSTD_freeCCtx' /usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../lib/libelf.a(elf_compress.o):(.text+0x81d): more undefined references to
ZSTD_freeCCtx' follow
/usr/bin/ld: /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/../../../../lib/libelf.a(elf_compress.o): in function __libelf_decompress': (.text+0x9f5): undefined reference to
ZSTD_decompress'
/usr/bin/ld: (.text+0x9fe): undefined reference to `ZSTD_isError'
collect2: error: ld returned 1 exit status
The error doesn't happen if /usr/lib/libzstd.a is present.
Real-world use case:
Building the BPF test runner for using it in the vmtest VM requires this patch for static linking: https://github.com/cilium/linux/commit/3a1cef477e3e8e208d2d33035215f1f9d646afef, and static linking fails on Arch Linux due to missing libzstd.a, although libelf.a is present.