Skip to content

Too many /link flags passed with clang-cl + lld-link and %LDFLAGS%=/link ... #15255

@frankier

Description

@frankier

Describe the bug
When running meson %LDFLAGS$=/link ... using the clang-cl driver and lld-link, the C++ sanity check will add another /link resulting in a clang-cl call containing /link /link. The second /link argument will get passed onto lld-link which thinks its a file name, resulting in a error and the meson build aborting. MSCV link.exe issues a warning but ignores the extra /link so the build continues without problems.

To Reproduce
There's a bit more explanation and a replication at https://github.com/frankier/meson_clang_win_activation

The most simple replication on Linux is to call meson with LDFLAGS=/link e.g.:

CXX=clang-cl LD=lld-link LDFLAGS='/link' CXXFLAGS=-fuse-ld=lld-link meson setup build

Although without a full cross compilation environment this would fail later on, this is enough to trigger the bug.

Expected behavior
Don't duplicate call clang-cl with duplicate /link arguments.

Care has been taken in build_wrapper_args to avoid duplicating /link. See https://github.com/mesonbuild/meson/blame/3eed425f8b5ac7cf89e51b1f06e6e7e3255ff626/mesonbuild/compilers/mixins/clike.py#L434-L446

Unfortunately, this code isn't used when preparing the arguments in the sanity checking code.

Probably multiple solutions are possible. I will make a PR with a simple one in a moment.

System parameters
The instructions above allow this to be replicated on Windows or Linux. I checked both the the versions in the repo above on Windows and the current master branch on Linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS:windowsWinodows OS specific issuesdynamic linkersDynamic linkers (ld, link, lld-link, etc)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions