Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I link to libwinpthread libc++ and libunwind statically? #311

Closed
tommyvct opened this issue Oct 29, 2022 · 11 comments
Closed

How can I link to libwinpthread libc++ and libunwind statically? #311

tommyvct opened this issue Oct 29, 2022 · 11 comments

Comments

@tommyvct
Copy link

tommyvct commented Oct 29, 2022

Background: I'm compiling FFmpeg for OBS Studio's dependency. Currently, FFmpeg and it's dependencies are cross-compiled from Linux. Because we are targeting Windows ARM64 platform, this toolchain is our only hope other than MSVC, which requires a substantial infrastructure rewrite.

In our own build of FFmpeg, for x64 targets, we used GNU toolchain and linked against libwinpthread statically like this:

ff_ldflags+=(-Wl,-Bstatic -pthread)

where ff_ldflags will be one part of the configure script invocation.

But when I switched to LLVM-MinGW toolchain, this LD flag will somehow make FFmpeg failed to find what it just compiled:

LD      libswscale/swscale-6.dll
lld: error: unable to find library -lavutil
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

If I remove the suspicious LD flags altogether, the compilation will success but pthread will be dynamically linked.

Ref #273

The full FFmpeg configure invocation is here:

--disable-w32threads
--enable-pthreads
--arch=arm64
--target-os=mingw32
--cross-prefix=aarch64-w64-mingw32-
--pkg-config=pkg-config
--enable-cross-compile
--disable-mediafoundation
--cc=aarch64-w64-mingw32-clang
--cxx=aarch64-w64-mingw32-clang++
--pkg-config-flags=--static
--prefix=/home/tommyvct/GitHub/obs-deps/windows-arm64/obs-ffmpeg-arm64
--enable-version3
--enable-gpl
--enable-libx264
--enable-libopus
--enable-libvorbis
--enable-libvpx
--enable-librist
--enable-libsrt
--enable-shared
--disable-static
--disable-libjack
--disable-indev=jack
--disable-outdev=sdl
--disable-doc
--disable-postproc
--host-cflags=-I/home/tommyvct/GitHub/obs-deps/windows-arm64/obs-ffmpeg-arm64/include
--host-ldflags=-I/home/tommyvct/GitHub/obs-deps/windows-arm64/obs-ffmpeg-arm64/include
--extra-cflags="
    -I/home/tommyvct/GitHub/obs-deps/windows-arm64/obs-ffmpeg-arm64/include
    -static-libgcc
    -w
    -pipe
    -fno-semantic-interposition
    -O3
    -DNDEBUG"
--extra-cxxflags="
    -I/home/tommyvct/GitHub/obs-deps/windows-arm64/obs-ffmpeg-arm64/include
    -static-libgcc
    -static-libstdc++
    -w
    -pipe
    -fno-semantic-interposition
    -O3
    -DNDEBUG"
--extra-ldflags="
    -L/home/tommyvct/GitHub/obs-deps/windows-arm64/obs-ffmpeg-arm64/lib
    -static-libgcc
    -static-libstdc++
    -static-libgcc
    -Wl,-Bstatic
    -lwinpthread"
@longnguyen2004
Copy link
Contributor

Just a question: why don't you use the native w32 thread wrapper in ffmpeg?

@tommyvct tommyvct changed the title How can I link to libwinpthread statically? How can I link to libwinpthread libc++ and libunwind statically? Oct 29, 2022
@tommyvct
Copy link
Author

@mstorsjo
Copy link
Owner

In our own build of FFmpeg, for x64 targets, we used GNU toolchain and linked against libwinpthread statically like this:

ff_ldflags+=(-Wl,-Bstatic -pthread)

where ff_ldflags will be one part of the configure script invocation.

But when I switched to LLVM-MinGW toolchain, this LD flag will somehow make FFmpeg failed to find what it just compiled:

LD      libswscale/swscale-6.dll
lld: error: unable to find library -lavutil
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

If I remove the suspicious LD flags altogether, the compilation will success but pthread will be dynamically linked.

The reason for the failure to link, is because when you add the flag -Wl,-Bstatic, you're telling the linker that it should try to link all the libraries following this one on the command line, as static-only - and libavutil only exists as dynamic library in this build.

Something like -Wl,-Bstatic -lwinpthread -Wl,-Wl,-Bdynamic should work - which resets the state back to allowing dynamic libraries after this particular library.

The -Bstatic and -Bdynamic options work the same for GCC/binutils too, but it's possible that some layer (the GCC/Clang layer, which then mangles the options invoking the underlying linker) makes them appear in a slightly different order, which makes this work for the GCC/binutils case but not here. I'm curious to see exactly why it happens to work there. If you happen to have a build environment available, built with GCC for x86_64, where you can try that out, can you try rerunning the same command there, with verbose options. E.g. like this:

rm libswscale/swscale-6.dll
make V=1 libswscale/swscale-6.dll

This should show the exact command used to run the linking - something like this:

x86_64-w64-mingw32-gcc -shared -Wl,--out-implib,libswscale/libswscale.dll.a -Wl,--disable-auto-image-base libswscale/swscale-6.def -Wl,--image-base,0x180000000 -Wl,-Bsymbolic -Wl,--version-script,libswscale/libswscale.ver -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -Wl,--nxcompat,--dynamicbase -Wl,--high-entropy-va -Wl,--as-needed -Wl,--warn-common -Wl,-rpath-link=:libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil  -o libswscale/swscale-6.dll libswscale/alphablend.o libswscale/gamma.o libswscale/half2float.o libswscale/hscale.o libswscale/hscale_fast_bilinear.o libswscale/input.o libswscale/options.o libswscale/output.o libswscale/rgb2rgb.o libswscale/slice.o libswscale/swscale.o libswscale/swscale_unscaled.o libswscale/utils.o libswscale/version.o libswscale/vscale.o libswscale/x86/hscale_fast_bilinear_simd.o libswscale/x86/input.o libswscale/x86/output.o libswscale/x86/rgb2rgb.o libswscale/x86/rgb_2_rgb.o libswscale/x86/scale.o libswscale/x86/scale_avx2.o libswscale/x86/swscale.o libswscale/x86/yuv2rgb.o libswscale/x86/yuv2yuvX.o libswscale/x86/yuv_2_rgb.o libswscale/yuv2rgb.o libswscale/log2_tab.o libswscale/swscaleres.o -lavutil -lm -lm -luser32 -lbcrypt

(It does include a couple other commands too, but this is the interesting one.)
Now if you run this command manually, but add -v at the end of it, it'll print out the exact full command it uses for invoking the linker.

At the end of the output of that command, there's a long command line that looks something like this:

/usr/lib/gcc/x86_64-w64-mingw32/9.3-posix/collect2 -plugin /usr/lib/gcc/x86_64-w64-mingw32/9.3-posix/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-w64-mingw32/9.3-posix/lto-wrapper -plugin-opt=-fresolution=/tmp/ccyu1dfq.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -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_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep --shared -Bdynamic -e DllMainCRTStartup --enable-auto-image-base -o libswscale/swscale-6.dll /usr/lib/gcc/x86_64-w64-mingw32/9.3-posix/../../../../x86_64-w64-mingw32/lib/dllcrt2.o /usr/lib/gcc/x86_64-w64-mingw32/9.3-posix/crtbegin.o -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L/usr/lib/gcc/x86_64-w64-mingw32/9.3-posix -L/usr/lib/gcc/x86_64-w64-mingw32/9.3-posix/../../../../x86_64-w64-mingw32/lib --out-implib libswscale/libswscale.dll.a --disable-auto-image-base libswscale/swscale-6.def --image-base 0x180000000 -Bsymbolic --version-script libswscale/libswscale.ver --nxcompat --dynamicbase --high-entropy-va --as-needed --warn-common -rpath-link=:libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil libswscale/alphablend.o libswscale/gamma.o libswscale/half2float.o libswscale/hscale.o libswscale/hscale_fast_bilinear.o libswscale/input.o libswscale/options.o libswscale/output.o libswscale/rgb2rgb.o libswscale/slice.o libswscale/swscale.o libswscale/swscale_unscaled.o libswscale/utils.o libswscale/version.o libswscale/vscale.o libswscale/x86/hscale_fast_bilinear_simd.o libswscale/x86/input.o libswscale/x86/output.o libswscale/x86/rgb2rgb.o libswscale/x86/rgb_2_rgb.o libswscale/x86/scale.o libswscale/x86/scale_avx2.o libswscale/x86/swscale.o libswscale/x86/yuv2rgb.o libswscale/x86/yuv2yuvX.o libswscale/x86/yuv_2_rgb.o libswscale/yuv2rgb.o libswscale/log2_tab.o libswscale/swscaleres.o -lavutil -lm -lm -luser32 -lbcrypt -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt /usr/lib/gcc/x86_64-w64-mingw32/9.3-posix/crtend.o

This is the interesting one - if you can provide that, for the working GCC case (plus for the failing llvm-mingw case) it'd let me know more about what's going on.

But TL;DR, adding a -Wl,-Bdynamic after the -lwinpthreads option should probably fix the issue for you.

Other than that - there's another quite hacky but effective way of making sure that it doesn't link these libraries as dynamic. If you just remove the files libwinpthread.dll.a (and libc++.dll.a and libunwind.dll.a) from llvm-mingw/<arch>-w64-mingw32/lib, it'll only find the static versions and pick that. But that's rather hacky.

@tommyvct
Copy link
Author

tommyvct commented Nov 5, 2022

I did some further research: FFmpeg is innocent, but it's dynamically linked dependencies, namely librist and libsrt are culprits.

I'll come back later for your experiment.

@tommyvct
Copy link
Author

tommyvct commented Nov 6, 2022

@mstorsjo
this is the gcc mingw one you requested:

 /usr/lib/gcc/x86_64-w64-mingw32/10-win32/collect2 -plugin /usr/lib/gcc/x86_64-w64-mingw32/10-win32/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-w64-mingw32/10-win32/lto-wrapper -plugin-opt=-fresolution=/tmp/cceaarag.res -plugin-opt=-pass-through=-lmingw32 -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_eh -plugin-opt=-pass-through=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -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=-lmoldname -plugin-opt=-pass-through=-lmingwex -plugin-opt=-pass-through=-lmsvcrt -m i386pep --shared -Bdynamic -e DllMainCRTStartup --enable-auto-image-base -o libswscale/swscale-6.dll /usr/lib/gcc/x86_64-w64-mingw32/10-win32/../../../../x86_64-w64-mingw32/lib/dllcrt2.o /usr/lib/gcc/x86_64-w64-mingw32/10-win32/crtbegin.o -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L/home/tommyvct/GitHub/obs-deps/windows-x64/obs-ffmpeg-x64/lib -L/usr/lib/gcc/x86_64-w64-mingw32/10-win32 -L/usr/lib/gcc/x86_64-w64-mingw32/10-win32/../../../../x86_64-w64-mingw32/lib --out-implib libswscale/libswscale.dll.a --disable-auto-image-base libswscale/swscale-6.def --image-base 0x180000000 -Bsymbolic --version-script libswscale/libswscale.ver -Bstatic --nxcompat --dynamicbase --high-entropy-va --as-needed --warn-common -rpath-link=:libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil libswscale/alphablend.o libswscale/gamma.o libswscale/hscale.o libswscale/hscale_fast_bilinear.o libswscale/input.o libswscale/options.o libswscale/output.o libswscale/rgb2rgb.o libswscale/slice.o libswscale/swscale.o libswscale/swscale_unscaled.o libswscale/utils.o libswscale/vscale.o libswscale/x86/hscale_fast_bilinear_simd.o libswscale/x86/input.o libswscale/x86/output.o libswscale/x86/rgb2rgb.o libswscale/x86/rgb_2_rgb.o libswscale/x86/scale.o libswscale/x86/scale_avx2.o libswscale/x86/swscale.o libswscale/x86/yuv2rgb.o libswscale/x86/yuv2yuvX.o libswscale/x86/yuv_2_rgb.o libswscale/yuv2rgb.o libswscale/log2_tab.o libswscale/swscaleres.o -lavutil -lm -latomic -lm -luser32 -lbcrypt -latomic -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt /usr/lib/gcc/x86_64-w64-mingw32/10-win32/crtend.o

This is from the llvm lld:

 "/home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/bin/ld.lld" -m arm64pe --shared -Bdynamic -e DllMainCRTStartup --enable-auto-image-base -o libswscale/swscale-6.dll /home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/aarch64-w64-mingw32/lib/dllcrt2.o /home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/aarch64-w64-mingw32/lib/crtbegin.o -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavutil -Llibpostproc -Llibswscale -Llibswresample -L/home/tommyvct/GitHub/obs-deps/windows-arm64/obs-ffmpeg-arm64/lib -L/home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/aarch64-w64-mingw32/lib -L/home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/aarch64-w64-mingw32/mingw/lib -L/home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/lib -L/home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/aarch64-w64-mingw32/sys-root/mingw/lib -L/home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/lib/clang/15.0.0/lib/windows --out-implib libswscale/libswscale.dll.a --disable-auto-image-base libswscale/swscale-6.def -Bstatic --nxcompat --dynamicbase --as-needed libswscale/aarch64/hscale.o libswscale/aarch64/output.o libswscale/aarch64/rgb2rgb.o libswscale/aarch64/rgb2rgb_neon.o libswscale/aarch64/swscale.o libswscale/aarch64/swscale_unscaled.o libswscale/aarch64/yuv2rgb_neon.o libswscale/alphablend.o libswscale/gamma.o libswscale/hscale.o libswscale/hscale_fast_bilinear.o libswscale/input.o libswscale/options.o libswscale/output.o libswscale/rgb2rgb.o libswscale/slice.o libswscale/swscale.o libswscale/swscale_unscaled.o libswscale/utils.o libswscale/vscale.o libswscale/yuv2rgb.o libswscale/log2_tab.o libswscale/swscaleres.o -lavutil -lm -lm -luser32 -lbcrypt -lmingw32 /home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/lib/clang/15.0.0/lib/windows/libclang_rt.builtins-aarch64.a -l:libunwind.a -lmoldname -lmingwex -lmsvcrt -lpthread -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 /home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/lib/clang/15.0.0/lib/windows/libclang_rt.builtins-aarch64.a -l:libunwind.a -lmoldname -lmingwex -lmsvcrt -lkernel32 /home/tommyvct/GitHub/obs-deps/llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/aarch64-w64-mingw32/lib/crtend.o

The questions are:

  1. What is collect2?
  2. Why -Bdynamic is needed on clang-lld while gcc doesn't need it?

@tommyvct
Copy link
Author

tommyvct commented Nov 6, 2022

In our implementation, we did use the DLL renaming hack to force static linkage.

After reimplementing the renaming hack, both libsrt and librist have libc++ and libwinpthread linked statically.

During compilation, a warning -static-libstdc++ is not used happened multiple times, and that's expected because -static-libstdc++ is almost in all building scripts. -static-libc++ is not recognized.

@tommyvct
Copy link
Author

tommyvct commented Nov 6, 2022

While compiling srt for Windows ARM64, the produced pkg-config file has a major problem:
Screenshot from 2022-11-06 07-39-40

Look at the -l-l:libunwind.a in Libs.private, it doesn't look good. In fact, it caused FFmpeg failed to compile:
image

All the changes between x64 and ARM64 builds are 1) change of toolchain, from mingw-gcc to mingw-llvm and 2) get rid of -Wl,--exclude-libs,ALL from -DCMAKE_SHARED_LINKER_FLAGS because lld doesn't support it: try llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/bin/aarch64-w64-mingw32-ld -help, you can neither find the --exclude-libs switch nor switches that does the same thing, even it's clearly stated in the llvm-lld manual.
image

Now, if we get rid of the cursed -l-l:libunwind.a in the Windows ARM64 pkg-config file, FFmpeg will compile just fine.

We need a better way to eliminate -l-l:libunwind.a in the pkg-config file, rather than delete the cursed string on the fly.

@mstorsjo
Copy link
Owner

mstorsjo commented Nov 6, 2022

@mstorsjo this is the gcc mingw one you requested:

This is from the llvm lld:

The questions are:

  1. What is collect2?

It's some GCC program which is used as a wrapper for invoking the linker - I don't actually remember exactly what role it has. For this investigation, it's role is irrelevant anyway.

  1. Why -Bdynamic is needed on clang-lld while gcc doesn't need it?

Now that's a good question - from that linker invocation, it does look like GCC/binutils should run into the same issue too - but apparently it doesn't. I guess I'd have to try this out for myself to see why it happens to work there.

In principle though, adding it in the GCC case would be safer too, you're more or less just lucky that it has worked so far, I'd say.

Also, notice how the -Bstatic and -lpthread options end up in different places in the command line. It maybe might be safest to make sure they appear togeter by using e.g. -Wl,-Bstatic -Wl,-lpthread -Wl,-Bdynamic, so that they're all routed via the same -Wl mechanism too.

During compilation, a warning -static-libstdc++ is not used happened multiple times, and that's expected because -static-libstdc++ is almost in all building scripts. -static-libc++ is not recognized.

That's because -static-libstdc++ only is relevant if linking a C++ application; if you're linking a C application (i.e. invoking the C compiler driver for linking, instead of the C++ compiler driver) then -static-libstdc++ does nothing. Even though the option is called libstdc++ it applies to whichever C++ library that the compiler uses.

All the changes between x64 and ARM64 builds are 1) change of toolchain, from mingw-gcc to mingw-llvm and 2) get rid of -Wl,--exclude-libs,ALL from -DCMAKE_SHARED_LINKER_FLAGS because lld doesn't support it: try llvm-mingw-20220906-ucrt-ubuntu-18.04-x86_64/bin/aarch64-w64-mingw32-ld -help, you can neither find the --exclude-libs switch nor switches that does the same thing, even it's clearly stated in the llvm-lld manual.

The ELF linker interface of lld probably supports it, while the mingw interface doesn't yet. I haven't run into any case actively using this option in the last 4 years so it hasn't needed to be implemented yet.

Now, if we get rid of the cursed -l-l:libunwind.a in the Windows ARM64 pkg-config file, FFmpeg will compile just fine.

We need a better way to eliminate -l-l:libunwind.a in the pkg-config file, rather than delete the cursed string on the fly.

Yes, clearly. On first sight, it looks like a bug in whatever build files libsrt uses for creating the pkg-config files (or more precisely, for gathering info about what to put in it). How does one reproduce that issue? Does this library need a bazillion of dependencies, or can it be built on its own?

@tommyvct
Copy link
Author

tommyvct commented Nov 6, 2022

How does one reproduce that issue? Does this library need a bazillion of dependencies, or can it be built on its own?

This library itself only depends on mbedtls, but outside of our use case it is optional, since srt can use system openssl as it's default crypt library.

To reproduce the bug:

  1. Clone my branch of obs-deps.
  2. Comment line 138 and 139 out in deps.ffmpeg/60-srt.zsh because I already applied the sed -i hack to the srt build script.
  3. Run build-ffmpeg.zsh mbedtls --target windows-arm64 --config Release then build-ffmpeg.zsh srt --target windows-arm64 --config Release --debug.
    The --debug switch will spit everything out. The build script should also handle downloading and expanding the llvm-mingw toolchain.

@mstorsjo
Copy link
Owner

  1. Why -Bdynamic is needed on clang-lld while gcc doesn't need it?

Now that's a good question - from that linker invocation, it does look like GCC/binutils should run into the same issue too - but apparently it doesn't. I guess I'd have to try this out for myself to see why it happens to work there.

I had a look now, and it just so happens to work due to a different circumstance.

When -static or -Bstatic is specified, the linker won't try to load DLL import libraries like lib<name>.dll.a but will only look for import libraries named lib<name>.a. The linker also looks for a bunch of other name patterns too - see e.g. https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/emultempl/pep.em;h=e68d1e69f17ad73af065b6bed19ae89ded913172;hb=b51c2fec1da205ea3e7354cbb3e253018d64873c#l2066. All of these are skipped if the static flag is set.

But due to surprising circumstances, the MSVC style library form <name>.lib is tested even if the static flag is set. LLD didn't use to do this - this was reported as issue #305 - and is fixed in latest git of LLD (in llvm/llvm-project@e75c87f), which will be part of the the next release (16).

Normally you wouldn't have libraries named <name>.lib in mingw builds, but ffmpeg does provide such files (for MSVC compat). So when you're linking with -Bstatic -Llibavutil -lavutil, the linker ignores the library libavutil/libavutil.dll.a, but then surprisingly finds libavutil/avutil.lib and uses that instead. So that's why it has happened to work before. This behaviour should appear since LLD 16 too. But to actually be safe and not rely on ffmpeg producing such .lib files in the intermediate stages of the build, it'd be better to in general try to enclose the -Bstatic flag to specifically the lib it belongs to, and restore the default with -Bdynamic afterwards.

Now, if we get rid of the cursed -l-l:libunwind.a in the Windows ARM64 pkg-config file, FFmpeg will compile just fine.
We need a better way to eliminate -l-l:libunwind.a in the pkg-config file, rather than delete the cursed string on the fly.

Yes, clearly. On first sight, it looks like a bug in whatever build files libsrt uses for creating the pkg-config files (or more precisely, for gathering info about what to put in it). How does one reproduce that issue? Does this library need a bazillion of dependencies, or can it be built on its own?

Thanks for the instructions on building it. It looks like if the compiler links against some of its standard libraries with an unusual syntax, -l:libunwind.a (which the linker look explicitly for a file named libunwind.a, ignoring what other static/dynamic flags have been set), then CMake includes this library with this full option name form in CMAKE_CXX_IMPLICIT_LINK_LIBRARIES, which srt's cmake file doesn't expect: https://github.com/Haivision/srt/blob/v1.5.0/CMakeLists.txt#L1069-L1075 See Haivision/srt#2536 for a fix to this cmake file, which should avoid the misformed options in the pkg-config file.

tommyvct added a commit to tommyvct/obs-deps that referenced this issue Nov 14, 2022
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Nov 15, 2022
deps-ffmpeg: restore -Bdynamic after -Bstatic

ref: mstorsjo/llvm-mingw#311 (comment)
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Nov 15, 2022
deps-ffmpeg: restore -Bdynamic after -Bstatic

ref: mstorsjo/llvm-mingw#311 (comment)
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Nov 15, 2022
deps-ffmpeg: restore -Bdynamic after -Bstatic

ref: mstorsjo/llvm-mingw#311 (comment)
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Nov 15, 2022
deps-ffmpeg: restore -Bdynamic after -Bstatic

ref: mstorsjo/llvm-mingw#311 (comment)
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Nov 18, 2022
deps-ffmpeg: restore -Bdynamic after -Bstatic

ref: mstorsjo/llvm-mingw#311 (comment)

deps.qt: Add support for Windows ARM64

deps.windows: Add support for Windows ARM64

deps.ffmpeg: Add support for Windows ARM64

deps-ffmpeg: restore -Bdynamic after -Bstatic

ref: mstorsjo/llvm-mingw#311 (comment)

deps.qt: Add support for Windows ARM64

deps.windows: Add support for Windows ARM64
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Nov 18, 2022
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Nov 25, 2022
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Dec 3, 2022
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Dec 4, 2022
tommyvct added a commit to tommyvct/obs-deps that referenced this issue Jan 8, 2023
@mstorsjo
Copy link
Owner

But due to surprising circumstances, the MSVC style library form <name>.lib is tested even if the static flag is set. LLD didn't use to do this - this was reported as issue #305 - and is fixed in latest git of LLD (in llvm/llvm-project@e75c87f), which will be part of the the next release (16).

The fix for this issue is now available in the prerelease with LLVM 16.0.0 RC 1: https://github.com/mstorsjo/llvm-mingw/releases/tag/20230130

If there's nothing more to follow up on here in this issue, I believe this issue can be closed, and new issues can be opened for other more targeted issues if there are other things to look into.

tommyvct added a commit to tommyvct/obs-deps that referenced this issue Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants