Skip to content

-fuse-ld=lld-N breaks LTO on MinGW, while -fuse-ld=lld works fine despite selecting the same linker #161040

@HolyBlackCat

Description

@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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LTOLink time optimization (regular/full LTO or ThinLTO)lldquestionA question, not bug report. Check out https://llvm.org/docs/GettingInvolved.html instead!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions