Skip to content

Conversation

@frankier
Copy link
Contributor

Various build tools may produce command lines invoking clang-cl and lld-link which contain /link twice like so: e.g. clang-cl.exe sanitycheckcpp.cc /Fesanitycheckcpp.exe .... /link /link ...

If link.exe is used, it ignores the extra /link and just issues a warning, however lld-link tries to treat /link as a file name.

This PR adds a flag which is ignored in order to improve compatibility with link.exe

There's some extra context including an "in-the-wild" example and reproducer of the problem here: https://github.com/frankier/meson_clang_win_activation

@frankier frankier changed the title Add (ignored) /link flag to lld-link for compatibility with link.exe Add (ignored) /link flag to lld-link for compatibility with MSVC link.exe Nov 17, 2025
@github-actions
Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@llvmbot
Copy link
Member

llvmbot commented Nov 17, 2025

@llvm/pr-subscribers-lld-coff
@llvm/pr-subscribers-platform-windows

@llvm/pr-subscribers-lld

Author: Frankie Robertson (frankier)

Changes

Various build tools may produce command lines invoking clang-cl and lld-link which contain /link twice like so: e.g. clang-cl.exe sanitycheckcpp.cc /Fesanitycheckcpp.exe .... /link /link ...

If link.exe is used, it ignores the extra /link and just issues a warning, however lld-link tries to treat /link as a file name.

This PR adds a flag which is ignored in order to improve compatibility with link.exe

There's some extra context including an "in-the-wild" example and reproducer of the problem here: https://github.com/frankier/meson_clang_win_activation


Full diff: https://github.com/llvm/llvm-project/pull/168364.diff

3 Files Affected:

  • (modified) lld/COFF/DriverUtils.cpp (+3)
  • (modified) lld/COFF/Options.td (+1)
  • (modified) lld/test/COFF/driver.test (+3)
diff --git a/lld/COFF/DriverUtils.cpp b/lld/COFF/DriverUtils.cpp
index 10a3934d53284..42c7f93381510 100644
--- a/lld/COFF/DriverUtils.cpp
+++ b/lld/COFF/DriverUtils.cpp
@@ -862,6 +862,9 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
                 << "', did you mean '" << nearest << "'";
   }
 
+  if (args.hasArg(OPT_link))
+    Warn(ctx) << "ignoring /link, did you pass it multiple times?";
+
   if (args.hasArg(OPT_lib))
     Warn(ctx) << "ignoring /lib since it's not the first argument";
 
diff --git a/lld/COFF/Options.td b/lld/COFF/Options.td
index d77478fc9c987..6c4c7f897513d 100644
--- a/lld/COFF/Options.td
+++ b/lld/COFF/Options.td
@@ -71,6 +71,7 @@ def noimplib : F<"noimplib">,
 def lib : F<"lib">,
     HelpText<"Act like lib.exe; must be first argument if present">;
 def libpath : P<"libpath", "Additional library search path">;
+def link : F<"link">, HelpText<"Ignored for compatibility">;
 def linkrepro : Joined<["/", "-", "/?", "-?"], "linkrepro:">,
     MetaVarName<"directory">,
     HelpText<"Write repro.tar containing inputs and command to reproduce link">;
diff --git a/lld/test/COFF/driver.test b/lld/test/COFF/driver.test
index 8f58ff44e83e3..1c265bff75df5 100644
--- a/lld/test/COFF/driver.test
+++ b/lld/test/COFF/driver.test
@@ -17,6 +17,9 @@ LIBHELP: OVERVIEW: LLVM Lib
 # RUN: env LLD_IN_TEST=1 not lld-link /WX /lib 2>&1 | FileCheck -check-prefix=LIBBAD %s
 LIBBAD: ignoring /lib since it's not the first argument
 
+# RUN: env LLD_IN_TEST=1 not lld-link /link 2>&1 | FileCheck -check-prefix=LINKBAD %s
+LINKBAD: ignoring /link, did you pass it multiple times?
+
 # RUN: yaml2obj %p/Inputs/hello32.yaml -o %t.obj
 # RUN: not lld-link /out:/ %t.obj 2>&1 | FileCheck -check-prefix=DIR %s
 DIR: cannot open output file

}

if (args.hasArg(OPT_link))
Warn(ctx) << "ignoring /link, did you pass it multiple times?";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any value for this message? We can silently ignore the flng and nothing bad will happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this to match link.exe which gives a warning.

@frankier frankier changed the title Add (ignored) /link flag to lld-link for compatibility with MSVC link.exe [lld] Add (ignored) /link flag to lld-link for compatibility with MSVC link.exe Nov 18, 2025
@aganea aganea merged commit 86cbb36 into llvm:main Nov 21, 2025
14 checks passed
@github-actions
Copy link

@frankier Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

aadeshps-mcw pushed a commit to aadeshps-mcw/llvm-project that referenced this pull request Nov 26, 2025
…C link.exe (llvm#168364)

Various build tools may produce command lines invoking clang-cl and
lld-link which contain /link twice like so: e.g. `clang-cl.exe
sanitycheckcpp.cc /Fesanitycheckcpp.exe .... /link /link ...`

If link.exe is used, it ignores the extra `/link` and just issues a
warning, however lld-link tries to treat `/link` as a file name.

This PR adds a flag which is ignored in order to improve compatibility
with link.exe

There's some extra context including an "in-the-wild" example and
reproducer of the problem here:
https://github.com/frankier/meson_clang_win_activation

Co-authored-by: Frankie Robertson <[email protected]>
Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Nov 26, 2025
…C link.exe (llvm#168364)

Various build tools may produce command lines invoking clang-cl and
lld-link which contain /link twice like so: e.g. `clang-cl.exe
sanitycheckcpp.cc /Fesanitycheckcpp.exe .... /link /link ...`

If link.exe is used, it ignores the extra `/link` and just issues a
warning, however lld-link tries to treat `/link` as a file name.

This PR adds a flag which is ignored in order to improve compatibility
with link.exe

There's some extra context including an "in-the-wild" example and
reproducer of the problem here:
https://github.com/frankier/meson_clang_win_activation

Co-authored-by: Frankie Robertson <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants