EmilAskerov wrote:

### Problem

When configuring the Clang bootstrap on Windows with a MinGW toolchain, both 
`WIN32` and `MINGW` are true. However, `clang/CMakeLists.txt` currently treats 
`WIN32` as an indication that the host uses an MSVC-style toolchain.

This causes several problems during Stage2 configuration:

- **Incorrect C and C++ compiler selection:** The bootstrap configuration 
selects `clang-cl.exe` and uses the MSVC command-line interface instead of 
`clang.exe` and `clang++.exe`. As a result, GNU-style compiler flags such as 
`-ffile-prefix-map` are reported as unknown arguments and ignored.
- **Incorrect linker selection:** When `BOOTSTRAP_LLVM_ENABLE_LLD=ON`, the 
configuration selects `lld-link.exe` instead of `ld.lld.exe`. CMake 
consequently invokes the MSVC-style `vs_link_exe` workflow, passing 
MSVC-specific linker arguments.
- **Incompatible linker flags:** GNU-style linker flags, including 
`-Wl,/Brepro` and `-flto=thin`, are passed to `lld-link.exe`, which reports 
them as unknown arguments.
- **Missing MSVC libraries:** The MSVC-style link command attempts to link 
against libraries such as `kernel32.lib`, `user32.lib`, `msvcrtd.lib`, and 
`oldnames.lib`. These libraries are not available in the MinGW environment, 
causing the link step to fail.
- **Missing MinGW LTO archiver configuration:** The existing `MSVC` and `NOT 
WIN32` branches do not cover the MinGW case. Consequently, `llvm-ar` and 
`llvm-ranlib` are not added to `clang-bootstrap-deps` or configured for the 
bootstrap stage.

The failure occurs during CMake's initial C compiler test 
(`CMakeTestCCompiler.cmake`), before the Stage2 build can be generated:

```text
The C compiler
  ".../build/bin/clang-cl.exe"
is not able to compile a simple test program.

lld-link: error: could not open 'kernel32.lib': No such file or directory
lld-link: error: could not open 'user32.lib': No such file or directory
lld-link: error: could not open 'msvcrtd.lib': No such file or directory
```

### Solution

Handle MinGW explicitly in the bootstrap configuration:

- Use `clang.exe` and `clang++.exe` for MinGW builds, while preserving 
`clang-cl.exe` for non-MinGW Windows builds.
- Add a dedicated MinGW LTO archiver configuration using `llvm-ar.exe` and 
`llvm-ranlib.exe`.
- Select `ld.lld.exe` for MinGW bootstrap builds targeting Windows, while 
retaining `lld-link.exe` for the existing MSVC configuration.

This allows the bootstrap configuration to use the appropriate GNU-style tools 
on MinGW without changing the existing MSVC behavior.

https://github.com/llvm/llvm-project/pull/242849
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to