msys2 / MINGW-packages

Package scripts for MinGW-w64 targets to build under MSYS2.
https://packages.msys2.org
BSD 3-Clause "New" or "Revised" License
2.31k stars 1.23k forks source link

[svt-av1] Statically linking with libSvtAv1Enc does not satisfy symbols after 2.3.0 update #22439

Closed backwardsEric closed 2 weeks ago

backwardsEric commented 3 weeks ago

Description / Steps to reproduce the issue

On GitHub's window-latest runner, statically linking the C source below, saved as check.c, with the mingw64 package for svt-av1 fails with the linker error, "check.c:6:(.text.startup+0xa): undefined reference to `svt_av1_get_version'".

#include <stdio.h>
#include <EbSvtAv1Enc.h>

int main(int argc, char *argv[])
{
        (void)printf("SvtAv1 version: %s\n", svt_av1_get_version());
        return 0;
}

MSYS2 was set up in the runner with msys2/setup-msys2@v2 with the update parameter set to true. The versions of the packages installed for gcc, binutils, and svt-av1 were mingw-w64-x86_64-gcc-14.2.0-1, mingw-w64-x86_64-binutils-2.43.1-1, mingw-w64-x86_64-svt-av1-2.3.0-1.

The source code was compiled with

gcc -o check.o -c check.c -std=c99 -g -O2 -W -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wwrite-strings -Wmissing-prototypes -Wnested-externs -Wshadow -Wunused-macros -pedantic -I/mingw64/include/svt-av1

The command used for linking was

gcc -o check.exe -mconsole -static -Wl,-v -Wl,--trace-symbol=svt_av1_get_version check.o -lSvtAv1Enc

Expected behavior

Statically linking with the library satisfies the missing svt_av1_get_version symbol in check.o.

Dynamic linking (dropping -static from command for linking) does work. Statically linking a full application with libSDL2, libSDL2_ttf, libSDL2_image, and all their dependencies, including libSvtAv1Enc, did work before svt-av1 was upgraded to 2.3.0.

Actual behavior

gcc -v reported

Using built-in specs.
COLLECT_GCC=D:\a\_temp\msys64\mingw64\bin\gcc.exe
COLLECT_LTO_WRAPPER=D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../gcc-14.2.0/configure --prefix=/mingw64 --with-local-prefix=/mingw64/local --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --with-native-system-header-dir=/mingw64/include --libexecdir=/mingw64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-languages=c,lto,c++,fortran,ada,objc,obj-c++,rust,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-lto --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/mingw64 --with-mpfr=/mingw64 --with-mpc=/mingw64 --with-isl=/mingw64 --with-pkgversion='Rev1, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --disable-libstdcxx-debug --enable-plugin --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.2.0 (Rev1, Built by MSYS2 project) 

The messages from linking were

collect2 version 14.2.0
D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe -plugin D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/liblto_plugin.dll -plugin-opt=D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/lto-wrapper.exe -plugin-opt=-fresolution=D:\a\_temp\msys64\tmp\ccg8Ylvf.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lpthread -plugin-opt=-pass-through=-ladvapi32 -plugin-opt=-pass-through=-lshell32 -plugin-opt=-pass-through=-luser32 -plugin-opt=-pass-through=-lkernel32 -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -plugin-opt=-pass-through=-lkernel32 -m i386pep --subsystem console -Bdynamic -o check.exe D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../lib/crt2.o D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/crtbegin.o -LD:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0 -LD:/a/_temp/msys64/mingw64/bin/../lib/gcc -LD:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/lib/../lib -LD:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../lib -LD:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/lib -LD:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../.. -Bstatic -v --trace-symbol=svt_av1_get_version check.o -lSvtAv1Enc -lmingw32 -lgcc -lgcc_eh -lmingwex -lmsvcrt -lkernel32 -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmingwex -lmsvcrt -lkernel32 D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../lib/default-manifest.o D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/crtend.o
D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: check.o: reference to svt_av1_get_version
GNU ld (GNU Binutils) 2.43.1
D:/a/_temp/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: check.o: in function `main':
D:/a/svt-av1-linking/svt-av1-linking/src/check.c:6:(.text.startup+0xa): undefined reference to `svt_av1_get_version'
collect2.exe: error: ld returned 1 exit status

Verification

Windows Version

MINGW64_NT-10.0-20348

MINGW environments affected

Are you willing to submit a PR?

No

1480c1 commented 3 weeks ago

Possibly related to lto on by default and cmake choosing thin lto by default and turning off fatlto?

Andarwinux commented 3 weeks ago

It looks like mingw gcc's LTO doesn't work without -ffat-lto-object. clang64 is supposed to be fine.