Skip to content

Commit d754e1d

Browse files
jhuber6yuxuanchen1997
authored andcommitted
[Clang] Correctly forward --cuda-path to the nvlink wrapper (#100170)
Summary: This was not forwarded properly as it would try to pass it to `nvlink`. Fixes #100168 Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251134
1 parent 70f3ac9 commit d754e1d

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
609609
CmdArgs.push_back(Args.MakeArgString(
610610
"--pxtas-path=" + Args.getLastArgValue(options::OPT_ptxas_path_EQ)));
611611

612+
if (Args.hasArg(options::OPT_cuda_path_EQ))
613+
CmdArgs.push_back(Args.MakeArgString(
614+
"--cuda-path=" + Args.getLastArgValue(options::OPT_cuda_path_EQ)));
615+
612616
// Add paths specified in LIBRARY_PATH environment variable as -L options.
613617
addDirectoryList(Args, CmdArgs, "-L", "LIBRARY_PATH");
614618

clang/test/Driver/linker-wrapper-passes.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// Check various clang-linker-wrapper pass options after -offload-opt.
22

3-
// REQUIRES: llvm-plugins, llvm-examples
4-
// REQUIRES: x86-registered-target
5-
// REQUIRES: amdgpu-registered-target
6-
73
// Setup.
84
// RUN: mkdir -p %t
95
// RUN: %clang -cc1 -emit-llvm-bc -o %t/host-x86_64-unknown-linux-gnu.bc \
@@ -23,14 +19,14 @@
2319
// RUN: %t/host-x86_64-unknown-linux-gnu.s
2420

2521
// Check plugin, -passes, and no remarks.
26-
// RUN: clang-linker-wrapper -o a.out --embed-bitcode \
22+
// RUN: clang-linker-wrapper -o a.out --embed-bitcode --dry-run \
2723
// RUN: --linker-path=/usr/bin/true %t/host-x86_64-unknown-linux-gnu.o \
2824
// RUN: %offload-opt-loadbye --offload-opt=-wave-goodbye \
2925
// RUN: --offload-opt=-passes="function(goodbye),module(inline)" 2>&1 | \
3026
// RUN: FileCheck -match-full-lines -check-prefixes=OUT %s
3127

3228
// Check plugin, -p, and remarks.
33-
// RUN: clang-linker-wrapper -o a.out --embed-bitcode \
29+
// RUN: clang-linker-wrapper -o a.out --embed-bitcode --dry-run \
3430
// RUN: --linker-path=/usr/bin/true %t/host-x86_64-unknown-linux-gnu.o \
3531
// RUN: %offload-opt-loadbye --offload-opt=-wave-goodbye \
3632
// RUN: --offload-opt=-p="function(goodbye),module(inline)" \
@@ -43,7 +39,7 @@
4339
// RUN: -check-prefixes=YML %s
4440

4541
// Check handling of bad plugin.
46-
// RUN: not clang-linker-wrapper \
42+
// RUN: not clang-linker-wrapper --dry-run \
4743
// RUN: --offload-opt=-load-pass-plugin=%t/nonexistent.so 2>&1 | \
4844
// RUN: FileCheck -match-full-lines -check-prefixes=BAD-PLUGIN %s
4945

clang/test/Driver/nvlink-wrapper.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,10 @@ int baz() { return y + x; }
6363
// RUN: -arch sm_52 -o a.out 2>&1 | FileCheck %s --check-prefix=LTO
6464
// LTO: ptxas{{.*}} -m64 -c [[PTX:.+]].s -O3 -arch sm_52 -o [[CUBIN:.+]].cubin
6565
// LTO: nvlink{{.*}} -arch sm_52 -o a.out [[CUBIN]].cubin {{.*}}-u-{{.*}}.cubin {{.*}}-y-{{.*}}.cubin
66+
67+
//
68+
// Check that we don't forward some arguments.
69+
//
70+
// RUN: clang-nvlink-wrapper --dry-run %t.o %t-u.o %t-y.a \
71+
// RUN: -arch sm_52 --cuda-path/opt/cuda -o a.out 2>&1 | FileCheck %s --check-prefix=PATH
72+
// PATH-NOT: --cuda-path=/opt/cuda

clang/tools/clang-nvlink-wrapper/NVLinkOpts.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def verbose : Flag<["-"], "v">, HelpText<"Print verbose information">;
1212
def version : Flag<["--"], "version">,
1313
HelpText<"Display the version number and exit">;
1414

15-
def cuda_path_EQ : Joined<["--"], "cuda-path=">,
15+
def cuda_path_EQ : Joined<["--"], "cuda-path=">, Flags<[WrapperOnlyOption]>,
1616
MetaVarName<"<dir>">, HelpText<"Set the system CUDA path">;
17-
def ptxas_path_EQ : Joined<["--"], "ptxas-path=">,
17+
def ptxas_path_EQ : Joined<["--"], "ptxas-path=">, Flags<[WrapperOnlyOption]>,
1818
MetaVarName<"<dir>">, HelpText<"Set the 'ptxas' path">;
1919

2020
def o : JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,

0 commit comments

Comments
 (0)