Skip to content

Commit c69be3f

Browse files
[Driver][ROCm][OpenMP] Fix default ockl linking for OpenMP. (#126186)
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 83af335 commit c69be3f

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,17 +1014,20 @@ 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;
10211026
BCLibs.emplace_back(BCLib);
10221027
};
10231028
auto AddSanBCLibs = [&]() {
10241029
if (GPUSanEnabled()) {
1025-
auto SanArgs = std::get<const SanitizerArgs>(GPUSan);
1026-
if (SanArgs.needsAsanRt())
1027-
AddBCLib(getAsanRTLPath(), false);
1030+
AddBCLib(getAsanRTLPath(), false);
10281031
}
10291032
};
10301033

@@ -1066,7 +1069,7 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
10661069
// them all?
10671070
std::tuple<bool, const SanitizerArgs> GPUSan(
10681071
DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
1069-
options::OPT_fno_gpu_sanitize, false),
1072+
options::OPT_fno_gpu_sanitize, true),
10701073
getSanitizerArgs(DriverArgs));
10711074
bool DAZ = DriverArgs.hasFlag(options::OPT_fgpu_flush_denormals_to_zero,
10721075
options::OPT_fno_gpu_flush_denormals_to_zero,
@@ -1099,7 +1102,7 @@ bool AMDGPUToolChain::shouldSkipSanitizeOption(
10991102
return false;
11001103

11011104
if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
1102-
options::OPT_fno_gpu_sanitize, false))
1105+
options::OPT_fno_gpu_sanitize, true))
11031106
return true;
11041107

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

clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ llvm::opt::DerivedArgList *AMDGPUOpenMPToolChain::TranslateArgs(
6868
Action::OffloadKind DeviceOffloadKind) const {
6969
DerivedArgList *DAL =
7070
HostTC.TranslateArgs(Args, BoundArch, DeviceOffloadKind);
71-
if (!DAL)
71+
if (!DAL || Args.hasArg(options::OPT_fsanitize_EQ))
7272
DAL = new DerivedArgList(Args.getBaseArgs());
7373

7474
const OptTable &Opts = getDriver().getOpts();
Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// REQUIRES: x86-registered-target, amdgpu-registered-target
2-
31
// Fail on invalid ROCm Path.
42
// RUN: not %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ -fsanitize=address -fgpu-sanitize -nogpuinc --rocm-path=%S/Inputs/rocm-invalid %s 2>&1 \
53
// RUN: | FileCheck --check-prefix=FAIL %s
@@ -13,53 +11,52 @@
1311
// RUN: | FileCheck --check-prefix=NOTSUPPORTED %s
1412

1513
// GPU ASan Enabled Test Cases
16-
// ASan enabled for amdgpu-arch [gfx908]
17-
// 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 \
18-
// RUN: | FileCheck -check-prefixes=NOXNACK,GPUSAN %s
19-
20-
// GPU ASan enabled for amdgpu-arch [gfx908:xnack-]
21-
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack- -fsanitize=address -fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
22-
// RUN: | FileCheck -check-prefixes=XNACKNEG,GPUSAN %s
2314

2415
// GPU ASan enabled for amdgpu-arch [gfx908:xnack+]
2516
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ -fsanitize=address -fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
26-
// RUN: | FileCheck -check-prefixes=GPUSAN %s
17+
// RUN: | FileCheck -check-prefixes=HOSTSAN,GPUSAN,SAN %s
18+
19+
// GPU ASan enabled through '-fsanitize=address' flag without '-fgpu-sanitize' for amdgpu-arch [gfx908:xnack+]
20+
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ -fsanitize=address --rocm-path=%S/Inputs/rocm %s 2>&1 \
21+
// RUN: | FileCheck -check-prefixes=HOSTSAN,GPUSAN,SAN %s
2722

2823
// ASan enabled for multiple amdgpu-arch [gfx908:xnack+,gfx900:xnack+]
2924
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ --offload-arch=gfx900:xnack+ -fsanitize=address -fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
30-
// RUN: | FileCheck -check-prefixes=GPUSAN %s
25+
// RUN: | FileCheck -check-prefixes=HOSTSAN,GPUSAN,SAN %s
3126

3227
// GPU ASan Disabled Test Cases
33-
// ASan disabled for amdgpu-arch [gfx908]
34-
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908 -fsanitize=address -fno-gpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
35-
// RUN: | FileCheck -check-prefixes=NOGPUSAN %s
28+
29+
// GPU ASan disabled through '-fsanitize=address' without '-fgpu-sanitize' flag for amdgpu-arch [gfx908]
30+
// 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 \
31+
// RUN: | FileCheck -check-prefixes=NOXNACK,HOSTSAN,NOGPUSAN,SAN %s
32+
33+
// GPU ASan disabled for amdgpu-arch [gfx908]
34+
// 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 \
35+
// RUN: | FileCheck -check-prefixes=NOXNACK,HOSTSAN,NOGPUSAN,SAN %s
3636

3737
// GPU ASan disabled for amdgpu-arch [gfx908:xnack-]
38-
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack- -fsanitize=address -fno-gpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
39-
// RUN: | FileCheck -check-prefixes=NOGPUSAN %s
38+
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack- -fsanitize=address -fgpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
39+
// RUN: | FileCheck -check-prefixes=XNACKNEG,HOSTSAN,NOGPUSAN,SAN %s
4040

41-
// GPU ASan disabled for amdgpu-arch [gfx908:xnack+]
41+
// GPU ASan disabled using '-fno-gpu-sanitize' for amdgpu-arch [gfx908:xnack+]
4242
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ -fsanitize=address -fno-gpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
43-
// RUN: | FileCheck -check-prefixes=NOGPUSAN %s
43+
// RUN: | FileCheck -check-prefixes=HOSTSAN,NOGPUSAN,SAN %s
4444

45-
// ASan disabled for amdgpu-arch [gfx908:xnack+,gfx900:xnack+]
45+
// GPU ASan disabled for multiple amdgpu-arch [gfx908:xnack+,gfx900:xnack+]
4646
// RUN: %clang -no-canonical-prefixes -### --target=x86_64-unknown-linux-gnu -fopenmp=libomp --offload-arch=gfx908:xnack+ --offload-arch=gfx900:xnack+ -fsanitize=address -fno-gpu-sanitize --rocm-path=%S/Inputs/rocm %s 2>&1 \
47-
// RUN: | FileCheck -check-prefixes=NOGPUSAN %s
47+
// RUN: | FileCheck -check-prefixes=HOSTSAN,NOGPUSAN,SAN %s
4848

4949
// FAIL-DAG: error: cannot find ROCm device library for ABI version 5; provide its path via '--rocm-path' or '--rocm-device-lib-path', or pass '-nogpulib' to build without ROCm device library
5050
// NOTSUPPORTED-DAG: warning: ignoring '-fsanitize=leak' option as it is not currently supported for target 'amdgcn-amd-amdhsa'
5151

5252
// NOXNACK: warning: ignoring '-fsanitize=address' option for offload arch 'gfx908' as it is not currently supported there. Use it with an offload arch containing 'xnack+' instead
5353
// XNACKNEG: warning: ignoring '-fsanitize=address' option for offload arch 'gfx908:xnack-' as it is not currently supported there. Use it with an offload arch containing 'xnack+' instead
5454

55-
// GPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "-fopenmp-targets=amdgcn-amd-amdhsa".* "-x" "c".*}}
56-
// GPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu".* "-emit-llvm-bc".* "-target-cpu" "(gfx908|gfx900)".* "-fopenmp".* "-fsanitize=address".* "-x" "c".*}}
57-
// GPUSAN: {{"[^"]*clang-offload-packager[^"]*" "-o".* "--image=file=.*.bc,triple=amdgcn-amd-amdhsa,arch=gfx908(:xnack\-|:xnack\+)?,kind=openmp(,feature=(\-xnack|\+xnack))?"}}
58-
// GPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "-fopenmp-targets=amdgcn-amd-amdhsa".* "-x" "ir".*}}
59-
// GPUSAN: {{"[^"]*clang-linker-wrapper[^"]*".* "--host-triple=x86_64-unknown-linux-gnu".* "--linker-path=[^"]*".* "--whole-archive" "[^"]*(libclang_rt.asan_static.a|libclang_rt.asan_static-x86_64.a)".* "--whole-archive" "[^"]*(libclang_rt.asan.a|libclang_rt.asan-x86_64.a)".*}}
55+
// HOSTSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "-fopenmp-targets=amdgcn-amd-amdhsa".* "-x" "c".*}}
6056

61-
// NOGPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "-fopenmp-targets=amdgcn-amd-amdhsa".* "-x" "c".*}}
57+
// GPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu".* "-emit-llvm-bc".* "-mlink-bitcode-file" "[^"]*asanrtl.bc".* "-mlink-bitcode-file" "[^"]*ockl.bc".* "-target-cpu" "(gfx908|gfx900)".* "-fopenmp".* "-fsanitize=address".* "-x" "c".*}}
6258
// NOGPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "amdgcn-amd-amdhsa" "-aux-triple" "x86_64-unknown-linux-gnu".* "-emit-llvm-bc".* "-target-cpu" "(gfx908|gfx900)".* "-fopenmp".* "-x" "c".*}}
63-
// NOGPUSAN: {{"[^"]*clang-offload-packager[^"]*" "-o".* "--image=file=.*.bc,triple=amdgcn-amd-amdhsa,arch=gfx908(:xnack\-|:xnack\+)?,kind=openmp(,feature=(\-xnack|\+xnack))?"}}
64-
// NOGPUSAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "-fopenmp-targets=amdgcn-amd-amdhsa".* "-x" "ir".*}}
65-
// NOGPUSAN: {{"[^"]*clang-linker-wrapper[^"]*".* "--host-triple=x86_64-unknown-linux-gnu".* "--linker-path=[^"]*".* "--whole-archive" "[^"]*(libclang_rt.asan_static.a|libclang_rt.asan_static-x86_64.a)".* "--whole-archive" "[^"]*(libclang_rt.asan.a|libclang_rt.asan-x86_64.a)".*}}
59+
60+
// SAN: {{"[^"]*clang-offload-packager[^"]*" "-o".* "--image=file=.*.bc,triple=amdgcn-amd-amdhsa,arch=gfx908(:xnack\-|:xnack\+)?,kind=openmp(,feature=(\-xnack|\+xnack))?"}}
61+
// SAN: {{"[^"]*clang[^"]*" "-cc1" "-triple" "x86_64-unknown-linux-gnu".* "-fopenmp".* "-fsanitize=address".* "-fopenmp-targets=amdgcn-amd-amdhsa".* "-x" "ir".*}}
62+
// SAN: {{"[^"]*clang-linker-wrapper[^"]*".* "--host-triple=x86_64-unknown-linux-gnu".* "--linker-path=[^"]*".* "--whole-archive" "[^"]*(libclang_rt.asan_static.a|libclang_rt.asan_static-x86_64.a)".* "--whole-archive" "[^"]*(libclang_rt.asan.a|libclang_rt.asan-x86_64.a)".*}}

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)