[PATCH] D124999: ld.lld: Respect -fallback-gnu-driver.

Shea Levy via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 6 01:10:20 PDT 2022


shlevy added a subscriber: Ericson2314.
shlevy added a comment.

In D124999#3495825 <https://reviews.llvm.org/D124999#3495825>, @MaskRay wrote:

> The description does not have information to justify why such an option is needed.

We can split up the justification into two parts:

1. Why enable changing the default driver at all? D87418 <https://reviews.llvm.org/D87418>, introducing `LLD_DEFAULT_LD_LLD_IS_MINGW`, gives the primary justification: there are build systems which grep through `--help` for certain flags. E.g. any package using libtool <https://git.savannah.gnu.org/cgit/libtool.git/tree/m4/libtool.m4#n5132> (so far I've hit this with `gmp` and `libffi` but there are certainly countless others) will think `lld` can't produce shared libraries. As a secondary consideration, if I'm manually invoking e.g. `x86_64-w64-mingw32-ld --help` I want to see the usage for the actual command I care about. As a tertiary consideration, if no machine type is set (with `-m`) then both the `ELF` driver and the `COFF` driver (which the `MinGW` driver uses under the hood) have logic to detect the appropriate machine type from input files, but without the ability to change the default driver there is no way to take advantage of that autodetection via `ld.lld` for COFF.
2. Why make this knob configurable at run-time? As @Ericson2314 touches on in https://github.com/ClangBuiltLinux/llvm-distributors-conf-2021/issues/20, the LLVM toolchain has a great (and IME unique amongst serious compilers) virtue of target-agnosticism in the build process. This has design benefits, but the immediate cash value is that if I fix `build` and `host` I can build one core toolchain and use the same underlying binaries to compile for all of the targets that LLVM supports. Without run-time configuration, to achieve the benefits of point 1 we would have to break this invariant and build a different `lld` for `MinGW` targets than for non-`MinGW` targets. With this (or an analogue that uses env vars, if that's preferred), we can instead simply ensure that the build environment for the specific target passes the right flags (as I do here <https://github.com/NixOS/nixpkgs/blob/b8182b9d00b921d8c5d4b5501139f5ba63ffd29d/pkgs/build-support/bintools-wrapper/add-lld-ldflags-before.sh>).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124999



More information about the llvm-commits mailing list