summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLIU Hao <lh_mouse@126.com>2024-12-16 12:04:37 +0800
committerEli Schwartz <eschwartz93@gmail.com>2024-12-19 12:38:22 -0500
commit6eac0158cd4e62ec835a5fa38fd619d6f3958353 (patch)
tree74596071687cbe5666621115426b4dc99aeefea1
parent1f1a6d3a45ab968bbc28854c4733dc1303abb176 (diff)
downloadmeson-6eac0158cd4e62ec835a5fa38fd619d6f3958353.tar.gz
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 <lh_mouse@126.com>
-rw-r--r--mesonbuild/compilers/mixins/clang.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/mesonbuild/compilers/mixins/clang.py b/mesonbuild/compilers/mixins/clang.py
index 41b35c041..82df325ec 100644
--- a/mesonbuild/compilers/mixins/clang.py
+++ b/mesonbuild/compilers/mixins/clang.py
@@ -187,7 +187,7 @@ class ClangCompiler(GnuLikeCompiler):
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