Skip to content

[Clang] Suppress missing architecture error when doing LTO #100652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions clang/lib/Driver/ToolChains/Cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,16 @@ void NVPTX::Linker::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-v");

StringRef GPUArch = Args.getLastArgValue(options::OPT_march_EQ);
if (GPUArch.empty()) {
if (GPUArch.empty() && !C.getDriver().isUsingLTO()) {
C.getDriver().Diag(diag::err_drv_offload_missing_gpu_arch)
<< getToolChain().getArchName() << getShortName();
return;
}

CmdArgs.push_back("-arch");
CmdArgs.push_back(Args.MakeArgString(GPUArch));
if (!GPUArch.empty()) {
CmdArgs.push_back("-arch");
CmdArgs.push_back(Args.MakeArgString(GPUArch));
}

if (Args.hasArg(options::OPT_ptxas_path_EQ))
CmdArgs.push_back(Args.MakeArgString(
Expand Down
7 changes: 7 additions & 0 deletions clang/test/Driver/cuda-cross-compiling.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
// MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'ptxas'
// MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'nvlink'

// Do not error when performing LTO.
//
// RUN: %clang -target nvptx64-nvidia-cuda -flto %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=MISSING-LTO %s

// MISSING-LTO-NOT: error: must pass in an explicit nvptx64 gpu architecture to 'nvlink'

// RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
// RUN: | FileCheck -check-prefix=GENERIC %s
// RUN: %clang -target nvptx64-nvidia-cuda -march=sm_52 -march=generic -flto -c %s -### 2>&1 \
Expand Down
7 changes: 7 additions & 0 deletions clang/tools/clang-nvlink-wrapper/ClangNVLinkWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ Expected<StringRef> runPTXAs(StringRef File, const ArgList &Args) {
findProgram(Args, "ptxas", {CudaPath + "/bin", GivenPath});
if (!PTXAsPath)
return PTXAsPath.takeError();
if (!Args.hasArg(OPT_arch))
return createStringError(
"must pass in an explicit nvptx64 gpu architecture to 'ptxas'");

auto TempFileOrErr = createTempFile(
Args, sys::path::stem(Args.getLastArgValue(OPT_o, "a.out")), "cubin");
Expand Down Expand Up @@ -694,6 +697,10 @@ Error runNVLink(ArrayRef<StringRef> Files, const ArgList &Args) {
if (!NVLinkPath)
return NVLinkPath.takeError();

if (!Args.hasArg(OPT_arch))
return createStringError(
"must pass in an explicit nvptx64 gpu architecture to 'nvlink'");

ArgStringList NewLinkerArgs;
for (const opt::Arg *Arg : Args) {
// Do not forward arguments only intended for the linker wrapper.
Expand Down
2 changes: 1 addition & 1 deletion libc/cmake/modules/LLVMLibCLibraryRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function(add_bitcode_entrypoint_library target_name base_target_name)

add_executable(${target_name} ${objects})
target_link_options(${target_name} PRIVATE
"-r" "-nostdlib" "-flto" "-Wl,--lto-emit-llvm" "-march= ")
"-r" "-nostdlib" "-flto" "-Wl,--lto-emit-llvm")
endfunction(add_bitcode_entrypoint_library)

# A rule to build a library from a collection of entrypoint objects.
Expand Down
2 changes: 1 addition & 1 deletion libc/startup/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function(add_startup_object name)
RUNTIME_OUTPUT_DIRECTORY ${LIBC_LIBRARY_DIR}
RUNTIME_OUTPUT_NAME ${name}.o)
target_link_options(${fq_target_name}.exe PRIVATE
"-nostdlib" "-flto" "-Wl,--lto-emit-llvm" "-march= ")
"-nostdlib" "-flto" "-Wl,--lto-emit-llvm")
endif()
endfunction()

Expand Down
Loading