[compiler-rt] [compiler-rt][MSVC][CMake] Wrap Linker flags for ICX (PR #118496)
via llvm-commits
llvm-commits at lists.llvm.org
Sun May 18 10:43:17 PDT 2025
BukeBeyond wrote:
> > > CMAKE_CXX_LINKER_WRAPPER_FLAG contains -Xlinker which CMake provides from platform defaults.
> >
> >
> > Which version of CMake are you using? What exactly is the C++ compiler? At the time of writing this code `CMAKE_CXX_LINKER_WRAPPER_FLAG` was always empty for clang-cl and cl.exe, and only set for the intel compiler (icx).
>
> Actually can you file an issue with a full reproducer? I can take a look at it then.
I tested with Cmake 3.29.4 and the latest 4.0.2. I also tested with clang and clang-cl as the compiler. Here is the
[CMakeCache.txt](https://github.com/user-attachments/files/20273985/CMakeCache.txt) with the build settings.
Here’s my latest understanding of the issue:
For .exe and .dll builds, CMake lets the Compiler handle the linking. In this case, CMAKE_CXX_LINKER_WRAPPER_FLAG (e.g., -Xlinker) is given to the Compiler, to forward the Linker flags.
However for Static libraries (.lib / .a), CMake directly calls llvm-ar or lib.exe, bypassing the Compiler. Therefore, CMAKE_STATIC_LINKER_FLAGS are passed as-is — and should not include CMAKE_CXX_LINKER_WRAPPER_FLAG, which only makes sense when going through the Compiler.
That’s why this line is incorrect:
`set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} ${CMAKE_CXX_LINKER_WRAPPER_FLAG}/IGNORE:4221")`
This gives -Xlinker or /link directly to the the static librarian llvm-ar.exe (or lib.exe) causing a build failure.
I suspect that in your testing, either: CMAKE_CXX_LINKER_WRAPPER_FLAG was empty, or The conditional wrapping the above line didn’t fire (perhaps due to CMAKE_LINKER MATCHES "link.exe$" being false).
To help debug this, I would insert the following after the conditional, in compiler-rt/CMakeLists.txt around line 780:
```
message(STATUS "SAY: ${CMAKE_LINKER}")
message(STATUS "SAY: ${CMAKE_CXX_LINKER_WRAPPER_FLAG}")
```
Thankfully, running ninja on an already built LLVM, will not retrigger a whole new build, and you can test just the compiler-rt CMake quickly.
https://github.com/llvm/llvm-project/pull/118496
More information about the llvm-commits
mailing list