From 42a8cfc32b71b0d0c8c75e1337482b4a86922efa Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Sat, 8 Mar 2025 15:28:51 +0100 Subject: [PATCH] compilers/cuda: fix checking for multiple linker args When checking for multiple linker args we convert the supplied args to flags that the compiler understands. But besides these supplied args, we also try to convert linker flags that convert warnings into errors. This mechanism causes an error though because we don't know to convert these flags to linker flags: gcc: error: unrecognized command-line option '--warning-as-error'; did you mean '--warn-no-error'? ----------- ERROR: Linker nvcc does not support sanitizer arguments ['-Xcompiler=-fsanitize=address\\,undefined'] As you can see, the flag is passed to the underlying compiler, not to the underlying linker. The obvious fix would be to convert them to linker flags, which we can do by using `-Xlinker=` instead of `-Xcompiler=`. But that is incorrect, too: /nix/store/j7p46r8v9gcpbxx89pbqlh61zhd33gzv-binutils-2.43.1/bin/ld: unrecognized option '--warning-as-error' /nix/store/j7p46r8v9gcpbxx89pbqlh61zhd33gzv-binutils-2.43.1/bin/ld: use the --help option for usage information collect2: error: ld returned 1 exit status ----------- ERROR: Linker nvcc does not support sanitizer arguments ['-Xcompiler=-fsanitize=address\\,undefined'] Now we ended up passing the flag to the underlying linker, but the `--warning-as-error` flag isn't known by it. What we really ought to do is to pass on the flag to nvlink, which is the linker driver that controls the underlying linker. Do so by using `-Xnvlink=`, which fixes the bug. Signed-off-by: Patrick Steinhardt --- mesonbuild/compilers/cuda.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mesonbuild/compilers/cuda.py b/mesonbuild/compilers/cuda.py index b987a9bb2..134cd4ede 100644 --- a/mesonbuild/compilers/cuda.py +++ b/mesonbuild/compilers/cuda.py @@ -818,5 +818,6 @@ class CudaCompiler(Compiler): return self.compiles('int main(void) { return 0; }', env, extra_args=args, mode=CompileCheckMode.COMPILE) def has_multi_link_arguments(self, args: T.List[str], env: Environment) -> T.Tuple[bool, bool]: - args = self._to_host_flags(self.linker.fatal_warnings() + args, phase=Phase.LINKER) + args = ['-Xnvlink='+self._shield_nvcc_list_arg(s) for s in self.linker.fatal_warnings()] + args += self._to_host_flags(args, phase=Phase.LINKER) return self.compiles('int main(void) { return 0; }', env, extra_args=args, mode=CompileCheckMode.LINK)