Skip to content

Commit 86cbb36

Browse files
frankierFrankie Robertson
andauthored
[lld] Add (ignored) /link flag to lld-link for compatibility with MSVC link.exe (#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]>
1 parent 68ba286 commit 86cbb36

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

lld/COFF/DriverUtils.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,9 @@ opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
862862
<< "', did you mean '" << nearest << "'";
863863
}
864864

865+
if (args.hasArg(OPT_link))
866+
Warn(ctx) << "ignoring /link, did you pass it multiple times?";
867+
865868
if (args.hasArg(OPT_lib))
866869
Warn(ctx) << "ignoring /lib since it's not the first argument";
867870

lld/COFF/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def noimplib : F<"noimplib">,
7171
def lib : F<"lib">,
7272
HelpText<"Act like lib.exe; must be first argument if present">;
7373
def libpath : P<"libpath", "Additional library search path">;
74+
def link : F<"link">, HelpText<"Ignored for compatibility">;
7475
def linkrepro : Joined<["/", "-", "/?", "-?"], "linkrepro:">,
7576
MetaVarName<"directory">,
7677
HelpText<"Write repro.tar containing inputs and command to reproduce link">;

lld/test/COFF/driver.test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ LIBHELP: OVERVIEW: LLVM Lib
1717
# RUN: env LLD_IN_TEST=1 not lld-link /WX /lib 2>&1 | FileCheck -check-prefix=LIBBAD %s
1818
LIBBAD: ignoring /lib since it's not the first argument
1919

20+
# RUN: env LLD_IN_TEST=1 not lld-link /link 2>&1 | FileCheck -check-prefix=LINKBAD %s
21+
LINKBAD: ignoring /link, did you pass it multiple times?
22+
2023
# RUN: yaml2obj %p/Inputs/hello32.yaml -o %t.obj
2124
# RUN: not lld-link /out:/ %t.obj 2>&1 | FileCheck -check-prefix=DIR %s
2225
DIR: cannot open output file

0 commit comments

Comments
 (0)