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 <ps@pks.im>
This commit is contained in:
Patrick Steinhardt 2025-03-08 15:28:51 +01:00 committed by Eli Schwartz
parent 35ebae5541
commit 42a8cfc32b
1 changed files with 2 additions and 1 deletions

View File

@ -818,5 +818,6 @@ class CudaCompiler(Compiler):
return self.compiles('int main(void) { return 0; }', env, extra_args=args, mode=CompileCheckMode.COMPILE) 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]: 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) return self.compiles('int main(void) { return 0; }', env, extra_args=args, mode=CompileCheckMode.LINK)