Issue 161040
Summary `-fuse-ld=lld-N` breaks LTO on MinGW, while `-fuse-ld=lld` works fine despite selecting the same linker
Labels lld
Assignees
Reporter HolyBlackCat
    This only happens on MinGW, if the LLD binary is suffixed with a version number. Since MSYS2 doesn't use the version suffix, this is tricky to test: you can e.g. use Ubuntu and install suffixed LLD from https://apt.llvm.org/, and then cross-compile to MinGW (I've tested via https://github.com/HolyBlackCat/quasi-msys2).

If you compile `int main() {}` with `clang++ 1.cpp -flto -fuse-ld=lld-20`, it says:
```console
clang: error: 'x86_64-w64-windows-gnu': unable to pass LLVM bit-code files to linker
```
But if you use `-fuse-ld=lld`, it works fine.

The fun part is that if you remove `-flto` and add `-v`, it turns out that the same linker gets used in both cases.

`-fuse-ld=lld` calls `/usr/lib/llvm-20/bin/ld.lld`, which is a symlink to `lld` (resolves to `/usr/lib/llvm-20/bin/lld`), and `-fuse-ld=lld-20` calls `/usr/bin/ld.lld-20`, which is a symlink to `../lib/llvm-20/bin/ld.lld` (also resolves to `/usr/lib/llvm-20/bin/lld`).

Tested on Clang 20.1.7 on Ubuntu, and also on 21.1.1 on FreeBSD.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to