Skip to content

Commit 2a35e62

Browse files
committed
Add -startfiles -stdlib positive versions for GPU
1 parent f0682b7 commit 2a35e62

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,9 +1316,6 @@ defm offload_via_llvm : BoolFOption<"offload-via-llvm",
13161316
BothFlags<[], [ClangOption], " LLVM/Offload as portable offloading runtime.">>;
13171317
}
13181318

1319-
def gpustartfiles : Flag<["-"], "gpustartfiles">, Group<Link_Group>,
1320-
HelpText<"Link the GPU C startup utilities automatically, used for testing.">;
1321-
13221319
// CUDA options
13231320
let Group = cuda_Group in {
13241321
def cuda_include_ptx_EQ : Joined<["--"], "cuda-include-ptx=">,
@@ -5608,6 +5605,7 @@ def noprebind : Flag<["-"], "noprebind">;
56085605
def noprofilelib : Flag<["-"], "noprofilelib">;
56095606
def noseglinkedit : Flag<["-"], "noseglinkedit">;
56105607
def nostartfiles : Flag<["-"], "nostartfiles">, Group<Link_Group>;
5608+
def startfiles : Flag<["-"], "startfiles">, Group<Link_Group>;
56115609
def nostdinc : Flag<["-"], "nostdinc">,
56125610
Visibility<[ClangOption, CLOption, DXCOption]>, Group<IncludePath_Group>,
56135611
HelpText<"Disable both standard system #include directories and builtin #include directories">;
@@ -5620,6 +5618,9 @@ def nostdincxx : Flag<["-"], "nostdinc++">, Visibility<[ClangOption, CC1Option]>
56205618
def nostdlib : Flag<["-"], "nostdlib">,
56215619
Visibility<[ClangOption, CLOption, FlangOption, DXCOption]>,
56225620
Group<Link_Group>;
5621+
def stdlib : Flag<["-"], "stdlib">,
5622+
Visibility<[ClangOption, CLOption, FlangOption, DXCOption]>,
5623+
Group<Link_Group>;
56235624
def nostdlibxx : Flag<["-"], "nostdlib++">;
56245625
def object : Flag<["-"], "object">;
56255626
def o : JoinedOrSeparate<["-"], "o">,

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,15 @@ void amdgpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
648648
Args.MakeArgString("-plugin-opt=-mattr=" + llvm::join(Features, ",")));
649649
}
650650

651-
if (Args.hasArg(options::OPT_gpustartfiles)) {
651+
if (Args.hasArg(options::OPT_stdlib))
652+
CmdArgs.append({"-lc", "-lm"});
653+
if (Args.hasArg(options::OPT_startfiles)) {
652654
auto IncludePath = getToolChain().getStdlibPath();
653655
if (!IncludePath)
654656
IncludePath = "/lib";
655657
SmallString<128> P(*IncludePath);
656658
llvm::sys::path::append(P, "crt1.o");
657-
CmdArgs.append({"-lc", "-lm", Args.MakeArgString(P)});
659+
CmdArgs.push_back(Args.MakeArgString(P));
658660
}
659661

660662
CmdArgs.push_back("-o");

clang/lib/Driver/ToolChains/Cuda.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,15 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
641641
llvm::sys::path::append(DefaultLibPath, CLANG_INSTALL_LIBDIR_BASENAME);
642642
CmdArgs.push_back(Args.MakeArgString(Twine("-L") + DefaultLibPath));
643643

644-
if (Args.hasArg(options::OPT_gpustartfiles)) {
644+
if (Args.hasArg(options::OPT_stdlib))
645+
CmdArgs.append({"-lc", "-lm"});
646+
if (Args.hasArg(options::OPT_startfiles)) {
645647
auto IncludePath = getToolChain().getStdlibPath();
646648
if (!IncludePath)
647649
IncludePath = "/lib";
648650
SmallString<128> P(*IncludePath);
649651
llvm::sys::path::append(P, "crt1.o");
650-
CmdArgs.append({"-lc", "-lm", Args.MakeArgString(P)});
652+
CmdArgs.push_back(Args.MakeArgString(P));
651653
}
652654

653655
C.addCommand(std::make_unique<Command>(

clang/test/Driver/gpustartfiles.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -gpustartfiles \
1+
// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -stdlib -startfiles \
22
// RUN: -nogpulib -nogpuinc -### %s 2>&1 | FileCheck -check-prefix=NVPTX %s
33
// NVPTX: clang-nvlink-wrapper{{.*}}"-lc" "-lm" "{{.*}}crt1.o"
44
//
5-
// RUN: %clang -target amdgcn-amd-amdhsa -march=gfx90a -gpustartfiles \
5+
// RUN: %clang -target amdgcn-amd-amdhsa -march=gfx90a -stdlib -startfiles \
66
// RUN: -nogpulib -nogpuinc -### %s 2>&1 | FileCheck -check-prefix=AMDGPU %s
77
// AMDGPU: ld.lld{{.*}}"-lc" "-lm" "{{.*}}crt1.o"

0 commit comments

Comments
 (0)