From 1cf06813abbf2c91ab093731d9bf134ba8acf479 Mon Sep 17 00:00:00 2001 From: LIU Hao Date: Mon, 16 Dec 2024 12:04:37 +0800 Subject: [PATCH] compilers: Do not pass `-fuse-ld=lld` via `-Wl,` `-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 --- mesonbuild/compilers/mixins/clang.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py index 41b35c041336..82df325ec01e 100644 --- a/mesonbuild/compilers/mixins/clang.py +++ b/mesonbuild/compilers/mixins/clang.py @@ -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