Skip to content

Commit

Permalink
compilers: Do not pass -fuse-ld=lld via -Wl,
Browse files Browse the repository at this point in the history
`-fuse-ld=` is a driver option for selection of a linker; it shall not be
passed to a linker with `-Wl,`.

For the Microsoft compiler and linker, the options for the compiler and those
for the linker are separated by `/LINK`, which looks like `cl /cl-options ...
/link /link-options ...`. Formally, they are passed in the same command line.
When Clang is invoking the Microsoft linker or a Microsoft-style linker (that
is, LLD-LINK), every linker option has to prefixed by `-Wl,` or `-Xlink`.

Previously, using Clang-CL and LLD-LINK, given:

   cc = meson.get_compiler('c')
   assert(cc.has_link_argument('/LTCG'))

This code failed to detect the `/LTCG` option, because `-fuse-ld=lld` was
passed to the linker, as an invalid option:

   Command line: `clang E:\lh_mouse\Desktop\t\build\meson-private\tmpg0221fee\testfile.c -o E:\lh_mouse\Desktop\t\build\meson-private\tmpg0221fee\output.exe -D_FILE_OFFSET_BITS=64 -O0 -Werror=implicit-function-declaration -Wl,-WX -Wl,/LTCG -Wl,-fuse-ld=lld` -> 4044
   stdout:
   LINK : warning LNK4044: unrecognized option '/fuse-ld=lld'; ignored
   LINK : error LNK1218: warning treated as error; no output file generated

However, it should be noted that not all LINK options can be passed with
`-Wl,`. The `/subsystem:windows,6.1` option has a comma, which would be
converted to a space. Therefore, this option must be passed as
`-Xlinker -subsystem:windows,6.1`. This issue is not addressed in this commit.

Signed-off-by: LIU Hao <[email protected]>
  • Loading branch information
lhmouse committed Dec 17, 2024
1 parent bcb6052 commit 1cf0681
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mesonbuild/compilers/mixins/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def get_lto_compile_args(self, *, threads: int = 0, mode: str = 'default') -> T.

def linker_to_compiler_args(self, args: T.List[str]) -> T.List[str]:
if isinstance(self.linker, (ClangClDynamicLinker, MSVCDynamicLinker)):
return [flag if flag.startswith('-Wl,') else f'-Wl,{flag}' for flag in args]
return [flag if flag.startswith('-Wl,') or flag.startswith('-fuse-ld=') else f'-Wl,{flag}' for flag in args]
else:
return args

Expand Down

0 comments on commit 1cf0681

Please sign in to comment.