Closed gitoss closed 1 month ago
Clang LTO does not work this way (separate executable for compile and link), see https://llvm.org/docs/LinkTimeOptimization.html#id4
clang -flto -c a.c -o a.o
clang -c main.c -o main.o
clang -flto -fuse-ld=lld a.o main.o -o main
Clang LTO does not work this way (separate executable for compile and link), see https://llvm.org/docs/LinkTimeOptimization.html#id4
Sorry, I have to correct the bug ticket - the problem isn't dependent on LTO, but linking doesn't work at all unless llvm-tool's llvm-lib is used.
This is the actual problem - trying to compile SVT-AV1-PSY https://github.com/gianni-rosato/svt-av1-psy
Using the defult LLVM toolset of Visual Studio's LLVM 17 works just fine:
cmake --fresh -B svt_build_llvm17 -T ClangCL -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_APPS=ON -DENABLE_AVX512=ON -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" -DCMAKE_C_FLAGS_RELEASE="/DNDEBUG /clang:-O2 -march=native -Xclang -ffast-math"
But switching the toolset to llvm-tools for LLVM 19 produces a linker error unless "Use llvm-lib" is set to "Yes" in the GUI or see above.
cmake --fresh -B svt_build_llvm19 -T LLVM_143 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DBUILD_APPS=ON -DENABLE_AVX512=ON -DCMAKE_MSVC_RUNTIME_LIBRARY="MultiThreaded" -DCMAKE_C_FLAGS_RELEASE="/DNDEBUG /clang:-O2 -march=native -Xclang -ffast-math"
The errors are like "2>ASM_AVX512.dir\Release\cdef_avx512.obj : fatal error LNK1107: invalid or corrupt file: cannot read at 0x1A34"
For simple me it seems that using -T LLVM_143 should enable using llvm-tool's llvm-lib by default.
I don't see any error with CMake 3.30.4 and VS 17.11.5.
CMake output:
VS Build output:
with CMake 3.30.4 and VS 17.11.5.
for git clone --depth=1 https://github.com/gianni-rosato/svt-av1-psy.git
at https://github.com/gianni-rosato/svt-av1-psy/commit/bb886b2936a4020c9ff2e05fd5ceb6f0ba8c8f39
with CMake 3.30.4 and VS 17.11.5.
OK, I'll have a look again, thanks for checking.
I am not using the cmake provided by VS, but the latest one installed with scoop - that might be the problem.
with CMake 3.30.4 and VS 17.11.5.
OK, I'll have a look again, thanks for checking.
I haven't enough time to re-create the default settings atm, so I'm closing the ticket - it'll still be there for reference if I'm not the only one.
When using "cmake -T LLVM_143", compiling with LTO on VS 2022 and LLVM 19 fails because UseLldLink isn't set to true in https://github.com/zufuliu/llvm-utils/blob/main/VS2017/LLVM/LLVM.Common.props
My current solution is to edit LLVM.Common.props - which works just fine, but isn't safe against future updates of llvm-utils reverting this edit.