llvm-mingw

repository·master·Indexed 25 days ago

https://github.com/mstorsjo/llvm-mingw

A recipe for building a reproducible MinGW-w64 toolchain based on LLVM, Clang, and LLD. It supports ARM/ARM64 Windows, PDB debug info generation, and Address/Undefined Behavior Sanitizers. The toolchain provides options for both UCRT and msvcrt, and can be installed via prebuilt releases or built from source in Unix environments, Docker, or MSYS2.

Tokens
883
Snippets
2
Records
6
Agent score
34%

What's inside llvm-mingw

  1. Build LLVM MinGW from source

    master

    You can build the toolchain for your current Unix environment or as a Docker image.

    Build for current Unix environment: Run the build-all.sh script with a target directory.

    Build as a Docker image: Use the standard Docker build command.

    Note: If you change configure flags in the build-*.sh scripts, you may need to wipe the build directory for each project to ensure the new options are applied.

    ./build-all.sh <target-dir>
    
    docker build .
  2. Generate PDB debug information

    master

    By default, LLVM MinGW produces debug info in DWARF format. To generate debug info in Microsoft's PDB format, you must modify your build commands:

    1. Compilation: Add -gcodeview along with the standard -g flag.
    2. Linking: Add -Wl,--pdb= to the linking command. This creates a .pdb file at the same location as the output EXE/DLL. You can specify a custom name using -Wl,--pdb=module.pdb.

    Caveat: Microsoft debuggers may have assumptions about the C++ ABI that do not align with the Itanium ABI used by MinGW.

  3. Install LLVM MinGW via prebuilt releases

    master

    You can download and install prebuilt toolchains from the GitHub Releases page by simply unpacking the archives.

    There are two main types of packages:

    • Cross-compilers (llvm-mingw-<version>-<crt>-<distro>-<arch>.tar.xz): Run these on Linux to compile binaries for any of the four Windows architectures (i686, x86_64, armv7, arm64).
    • Native toolchains (llvm-mingw-<version>-<crt>-<arch>.zip): Run these on Windows to compile binaries for any of the four Windows architectures.

    C Runtime (CRT) Options:

    • UCRT (Universal C Runtime): The primary target. Available on Windows 10+ out of the box, or can be installed on Vista or newer. Note: Address Sanitizer requires UCRT.
    • msvcrt: A legacy alternative that works on all Windows versions without extra installation, but is less featureful.
  4. Build LLVM MinGW in MSYS2

    master

    To build the toolchain within an MSYS2 environment, install the required dependencies using pacman:

    pacman -S --needed git wget mingw-w64-x86_64-gcc mingw-w64-x86_64-ninja mingw-w64-x86_64-cmake make mingw-w64-x86_64-python3 autoconf libtool
  5. LLVM MinGW Compatibility and Known Issues

    master

    When using LLVM MinGW, be aware of the following technical constraints:

    • Binary Compatibility: The toolchain uses a different CRT and C++ standard library than most other MinGW toolchains. It is incompatible with object files and static libraries built with other toolchains. Mixing DLLs is allowed only if CRT resources (like file handles or memory) are not shared across DLL boundaries.
    • Address Sanitizer: Only works properly with the UCRT and is currently only supported on x86.
    • Linker (LLD) Limitations: LLD does not support linker scripts (COFF part). Use response files instead to pass lists of object files.
    • Libtool Issues: Projects using libtool may fail to link if they contain C++. This is due to libtool failing to detect compiler_rt when using Clang. To fix this, you may need to patch libtool or the project's configure script to prefer response files over linker scripts.
    • Windows Version Requirements:
      • The toolchain defaults to targeting Windows 7.
      • Runtime libraries (libunwind, libcxxabi, libcxx) assume Windows 7 or newer.
      • Windows native TLS support requires Windows Vista or newer.