[PATCH] D80425: Fix LLVM/Clang builds with mingw toolchain

Mateusz MikuĊ‚a via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 22 08:34:11 PDT 2020


mati865 added inline comments.


================
Comment at: clang/tools/libclang/CMakeLists.txt:71
+  list(APPEND LIBS ${CMAKE_DL_LIBS})
 endif()
 
----------------
thieta wrote:
> mstorsjo wrote:
> > If you say this is the same way it's done elsewhere, then sure - although I have no idea about what the issue is, why I haven't run into it, etc. Normally you wouldn't have a `libdl` on mingw right? What's the concrete issue you're running into, and in which conditions would one run into it?
> The problem here is that on my system `find_library()` picks up libdl in `/usr/lib` and then tries to link to it and gives me an error about it. `HAVE_LIBDL` comes from `config-ix.cmake` where it's checked if we are on windows or not: https://github.com/llvm/llvm-project/blob/216833b32befd14079130a3b857906f4e301179c/llvm/cmake/config-ix.cmake#L101
> 
> So this is how other places uses `CMAKE_DL_LIBS` like here: https://github.com/llvm/llvm-project/blob/7aaff8fd2da2812a2b3cbc8a41af29774b10a7d6/llvm/lib/Support/CMakeLists.txt#L13
I also had this issue in MSYS2 but used `-DCMAKE_SYSTEM_IGNORE_PATH=/usr/lib` to get around it.
MSYS2 has Cygwin like (so UNIX like) environment in `/usr/` and `/mingw{32,64}` for Mingw-w64.


================
Comment at: llvm/cmake/modules/HandleLLVMOptions.cmake:967
            CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
-  elseif(LINKER_IS_LLD_LINK)
+  elseif(LINKER_IS_LLD_LINK AND NOT MINGW)
     append("/lldltocache:${PROJECT_BINARY_DIR}/lto.cache"
----------------
thieta wrote:
> mstorsjo wrote:
> > Do you happen to know why `LINKER_IS_LLD_LINK` gets set in this case? `ld.lld` (the ELF linker interface, which then the MinGW driver remaps onto the COFF backend with the `lld-link` interface) certainly doesn't take `lld-link` style options. I believe (without diving further into it) that we shouldn't be setting this flag in this combination, but with the option implemented, we should fit it into the case further above, `elseif((UNIX OR MINGW) AND LLVM_USE_LINKER STREQUAL "lld")`
> Yeah I bet that variable is set because I pass `LLVM_USE_LINKER=lld` but I haven't digged to deeply. I can rework the if statement here when we have the lld option in there.
> Yeah I bet that variable is set because I pass LLVM_USE_LINKER=lld but I haven't digged to deeply. 

It does use `lld-link` when you use `LLVM_USE_LINKER=lld`.

The problem lies in this line:
```
append("/lldltocache:${PROJECT_BINARY_DIR}/lto.cache"
```
For MinGW that should read:
```
append("-Wl,/lldltocache:${PROJECT_BINARY_DIR}/lto.cache"
```
That's because you are passing this flag to GCC/Clang.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80425/new/

https://reviews.llvm.org/D80425





More information about the cfe-commits mailing list