Warning about missing symbol when building with LTO and the mold linker
libva has an issue regarding a symbol not being found during the linking phase when using -flto and the mold linker.
I've turned mold's warnings into errors with -Wl,--fatal-warnings, so I can catch them more easily. Below is the last couple of lines from the build log, and I am also adding the complete log as an attachment.
libva source used is at 984dfee4177021c400367f5dffc0776a6dd745dc mold used is at commit b04aba89d3a1931470983212925443e7aefca1e1 gcc (Gentoo 13.1.1_p20230527 p3) 13.1.1 20230527
Steps to reproduce:
- Clone this repo and
cdinto the libva folder - run
export CFLAGS="-O2 -flto=auto"andexport LDFLAGS="-fuse-ld=mold -Wl,--fatal-warnings" - run
./autogen.sh --prefix=/usrandmake V=1
/bin/sh ../libtool --tag=CC --mode=link gcc -Wall -fstack-protector-strong -O2 -flto=auto -fstack-protector-strong -version-info 1902:0:1900 -no-undefined -Wl,-version-script,./libva.syms -fuse-ld=mold -Wl,--fatal-warnings -o libva.la -rpath /usr/lib libva_la-va.lo libva_la-va_compat.lo libva_la-va_str.lo libva_la-va_trace.lo
libtool: link: gcc -shared -fPIC -DPIC .libs/libva_la-va.o .libs/libva_la-va_compat.o .libs/libva_la-va_str.o .libs/libva_la-va_trace.o -fstack-protector-strong -O2 -flto=auto -fstack-protector-strong -Wl,-version-script -Wl,./libva.syms -fuse-ld=mold -Wl,--fatal-warnings -Wl,-soname -Wl,libva.so.2 -o .libs/libva.so.2.1900.0
mold: error: ./libva.syms: cannot assign version `VA_API_0.32.0` to symbol `vaCreateSurfaces_0_32_0`: symbol not found
collect2: error: ld returned 1 exit status
This is also reproducible with GNU's ld linker even if not using LTO if LDFLAGS="-Wl,--no-undefined-version" is set.
FAILED: va/libva.so.2.2000.0 cc -o va/libva.so.2.2000.0 va/libva.so.2.2000.0.p/va.c.o va/libva.so.2.2000.0.p/va_compat.c.o va/libva.so.2.2000.0.p/va_str.c.o va/libva.so.2.2000.0.p/va_trace.c.o -Wl,--as-needed -Wl,--no-undefined -shared -fPIC -Wl,--start-group -Wl,-soname,libva.so.2 -Wl,--no-undefined-version -ldl -Wl,--end-group /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: va/libva.so.2.2000.0: version node not found for symbol vaCreateSurfaces@VA_API_0.32.0 /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/bin/ld: failed to set dynamic section sizes: bad value