Skip to content

Commit a1a255f

Browse files
committed
[Driver][ROCm][OpenMP] Fix default ockl linking for OpenMP.
ASan gpu runtime (asanrtl.bc) linking is dependent on 'ockl.bc'. Link 'ockl.bc' only when ASan is enabled for openmp amdgpu offloading application.
1 parent 083686d commit a1a255f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,12 @@ RocmInstallationDetector::getCommonBitcodeLibs(
10141014
bool isOpenMP = false) const {
10151015
llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12> BCLibs;
10161016

1017-
auto GPUSanEnabled = [GPUSan]() { return std::get<bool>(GPUSan); };
1017+
// GPU Sanitizer currently only supports ASan and is enabled through host
1018+
// ASan.
1019+
auto GPUSanEnabled = [GPUSan]() {
1020+
return std::get<bool>(GPUSan) &&
1021+
std::get<const SanitizerArgs>(GPUSan).needsAsanRt();
1022+
};
10181023
auto AddBCLib = [&](ToolChain::BitCodeLibraryInfo BCLib,
10191024
bool Internalize = true) {
10201025
BCLib.ShouldInternalize = Internalize;
@@ -1066,7 +1071,7 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
10661071
// them all?
10671072
std::tuple<bool, const SanitizerArgs> GPUSan(
10681073
DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
1069-
options::OPT_fno_gpu_sanitize, false),
1074+
options::OPT_fno_gpu_sanitize, true),
10701075
getSanitizerArgs(DriverArgs));
10711076
bool DAZ = DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
10721077
options::OPT_fno_gpu_flush_denormals_to_zero,
@@ -1099,7 +1104,7 @@ bool AMDGPUToolChain::shouldSkipSanitizeOption(
10991104
return false;
11001105

11011106
if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
1102-
options::OPT_fno_gpu_sanitize, false))
1107+
options::OPT_fno_gpu_sanitize, true))
11031108
return true;
11041109

11051110
auto &Diags = TC.getDriver().getDiags();

clang/test/Driver/amdgpu-openmp-sanitize-options.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
// RUN: | FileCheck --check-prefix=NOTSUPPORTED %s
1414

1515
// GPU ASan Enabled Test Cases
16+
17+
// GPU ASan enabled through -fsanitize=address flag for amdgpu-arch [gfx908]
18+
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908 -fsanitize=address --rocm-path=%S/Inputs/rocm %s 2>&1 \
19+
// RUN: | FileCheck -check-prefixes=NOXNACK,GPUSAN %s
20+
1621
// ASan enabled for amdgpu-arch [gfx908]
1722
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908 -fsanitize=address -fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
1823
// RUN: | FileCheck -check-prefixes=NOXNACK,GPUSAN %s

clang/test/Driver/hip-sanitize-options.hip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %clang -### --target=x86_64-unknown-linux-gnu --offload-arch=gfx900:xnack+ \
2-
// RUN: -fsanitize=address -fgpu-sanitize \
2+
// RUN: -fsanitize=address \
33
// RUN: -nogpuinc --rocm-path=%S/Inputs/rocm \
44
// RUN: %s 2>&1 | FileCheck -check-prefixes=NORDC %s
55

0 commit comments

Comments
 (0)