Skip to content

Commit

Permalink
cuda: pass static archives to nvcc without -Xlinker= prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
SoapGentoo committed May 7, 2024
1 parent 061f775 commit 620db36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions mesonbuild/backend/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,15 @@ def build_target_link_arguments(self, compiler: 'Compiler', deps: T.List[build.T
continue
if compiler.get_language() == 'd':
arg = '-Wl,' + arg
elif compiler.get_linker_id() == 'nvlink' and arg.endswith('.a'):
# We need to pass static archives without -Xlinker= to nvcc,
# since they may contain relocatable device code. When passing
# the static archive to nvcc with -Xlinker=, we bypass the
# frontend which means we lose the opportunity to perform device
# linking. We only need to do this for static archives, since
# nvcc doesn't support device linking with dynamic libraries:
# https://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#libraries
pass
else:
arg = compiler.get_linker_lib_prefix() + arg
args.append(arg)
Expand Down
5 changes: 4 additions & 1 deletion mesonbuild/compilers/cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,11 @@ def _to_host_flags(self, flags: T.List[str], phase: _Phase = _Phase.COMPILER) ->
# This is ambiguously either an MVSC-style /switch or an absolute path
# to a file. For some magical reason the following works acceptably in
# both cases.
# We only want to prefix arguments that are NOT static archives, since
# the latter could contain relocatable device code (-dc/-rdc=true).
prefix = '' if flag.endswith('.a') else f'-X{phase.value}='
wrap = '"' if ',' in flag else ''
xflags.append(f'-X{phase.value}={wrap}{flag}{wrap}')
xflags.append(f'{prefix}{wrap}{flag}{wrap}')
continue
elif len(flag) >= 2 and flag[0] == '-' and flag[1] in 'IDULlmOxmte':
# This is a single-letter short option. These options (with the
Expand Down

0 comments on commit 620db36

Please sign in to comment.