@@ -721,9 +721,10 @@ void amdgpu::getAMDGPUTargetFeatures(const Driver &D,
721
721
options::OPT_m_amdgpu_Features_Group);
722
722
}
723
723
724
- llvm::SmallVector<std::string, 12 > amdgpu::dlr::getCommonDeviceLibNames (
725
- const llvm::opt::ArgList &DriverArgs, const Driver &D,
726
- const std::string &GPUArch, bool isOpenMP,
724
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12 >
725
+ amdgpu::dlr::getCommonDeviceLibNames (
726
+ const llvm::opt::ArgList &DriverArgs, const SanitizerArgs &SanArgs,
727
+ const Driver &D, const std::string &GPUArch, bool isOpenMP,
727
728
const RocmInstallationDetector &RocmInstallation) {
728
729
auto Kind = llvm::AMDGPU::parseArchAMDGCN (GPUArch);
729
730
const StringRef CanonArch = llvm::AMDGPU::getArchNameAMDGCN (Kind);
@@ -732,13 +733,17 @@ llvm::SmallVector<std::string, 12> amdgpu::dlr::getCommonDeviceLibNames(
732
733
auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion (
733
734
getAMDGPUCodeObjectVersion (D, DriverArgs));
734
735
bool noGPULib = DriverArgs.hasArg (options::OPT_nogpulib);
735
- if (!RocmInstallation.checkCommonBitcodeLibs (CanonArch, LibDeviceFile,
736
- ABIVer, noGPULib))
736
+ if (!RocmInstallation.checkCommonBitcodeLibs (CanonArch, LibDeviceFile, ABIVer,
737
+ noGPULib))
737
738
return {};
738
739
739
740
// If --hip-device-lib is not set, add the default bitcode libraries.
740
741
// TODO: There are way too many flags that change this. Do we need to check
741
742
// them all?
743
+ std::tuple<bool , const SanitizerArgs> GPUSan (
744
+ DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
745
+ options::OPT_fno_gpu_sanitize, true ),
746
+ SanArgs);
742
747
bool DAZ = DriverArgs.hasFlag (
743
748
options::OPT_fgpu_flush_denormals_to_zero,
744
749
options::OPT_fno_gpu_flush_denormals_to_zero,
@@ -757,7 +762,7 @@ llvm::SmallVector<std::string, 12> amdgpu::dlr::getCommonDeviceLibNames(
757
762
758
763
return RocmInstallation.getCommonBitcodeLibs (
759
764
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
760
- FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
765
+ FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, isOpenMP);
761
766
}
762
767
763
768
// / AMDGPU Toolchain
@@ -1003,6 +1008,11 @@ void ROCMToolChain::addClangTargetOptions(
1003
1008
ABIVer, noGPULib))
1004
1009
return ;
1005
1010
1011
+ std::tuple<bool , const SanitizerArgs> GPUSan (
1012
+ DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
1013
+ options::OPT_fno_gpu_sanitize, true ),
1014
+ getSanitizerArgs ((DriverArgs)));
1015
+
1006
1016
bool Wave64 = isWave64 (DriverArgs, Kind);
1007
1017
1008
1018
// TODO: There are way too many flags that change this. Do we need to check
@@ -1018,21 +1028,19 @@ void ROCMToolChain::addClangTargetOptions(
1018
1028
DriverArgs.hasArg (options::OPT_cl_fp32_correctly_rounded_divide_sqrt);
1019
1029
1020
1030
// Add the OpenCL specific bitcode library.
1021
- llvm::SmallVector<std::string , 12 > BCLibs;
1022
- BCLibs.push_back (RocmInstallation->getOpenCLPath ().str ());
1031
+ llvm::SmallVector<BitCodeLibraryInfo , 12 > BCLibs;
1032
+ BCLibs.emplace_back (RocmInstallation->getOpenCLPath ().str ());
1023
1033
1024
1034
// Add the generic set of libraries.
1025
1035
BCLibs.append (RocmInstallation->getCommonBitcodeLibs (
1026
1036
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
1027
- FastRelaxedMath, CorrectSqrt, ABIVer, false ));
1037
+ FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, false ));
1028
1038
1029
- if (getSanitizerArgs (DriverArgs).needsAsanRt ()) {
1030
- CC1Args.push_back (" -mlink-bitcode-file" );
1031
- CC1Args.push_back (
1032
- DriverArgs.MakeArgString (RocmInstallation->getAsanRTLPath ()));
1033
- }
1034
- for (StringRef BCFile : BCLibs) {
1035
- CC1Args.push_back (" -mlink-builtin-bitcode" );
1039
+ for (auto [BCFile, Internalize] : BCLibs) {
1040
+ if (Internalize)
1041
+ CC1Args.push_back (" -mlink-builtin-bitcode" );
1042
+ else
1043
+ CC1Args.push_back (" -mlink-bitcode-file" );
1036
1044
CC1Args.push_back (DriverArgs.MakeArgString (BCFile));
1037
1045
}
1038
1046
}
@@ -1058,15 +1066,31 @@ bool RocmInstallationDetector::checkCommonBitcodeLibs(
1058
1066
return true ;
1059
1067
}
1060
1068
1061
- llvm::SmallVector<std::string , 12 >
1069
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo , 12 >
1062
1070
RocmInstallationDetector::getCommonBitcodeLibs (
1063
1071
const llvm::opt::ArgList &DriverArgs, StringRef LibDeviceFile, bool Wave64,
1064
1072
bool DAZ, bool FiniteOnly, bool UnsafeMathOpt, bool FastRelaxedMath,
1065
- bool CorrectSqrt, DeviceLibABIVersion ABIVer, bool isOpenMP = false ) const {
1066
- llvm::SmallVector<std::string, 12 > BCLibs;
1067
-
1068
- auto AddBCLib = [&](StringRef BCFile) { BCLibs.push_back (BCFile.str ()); };
1073
+ bool CorrectSqrt, DeviceLibABIVersion ABIVer,
1074
+ const std::tuple<bool , const SanitizerArgs> &GPUSan,
1075
+ bool isOpenMP = false ) const {
1076
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12 > BCLibs;
1077
+
1078
+ auto GPUSanEnabled = [GPUSan]() {
1079
+ return std::get<bool >(GPUSan) &&
1080
+ std::get<const SanitizerArgs>(GPUSan).needsAsanRt ();
1081
+ };
1082
+ auto AddBCLib = [&](ToolChain::BitCodeLibraryInfo BCLib,
1083
+ bool Internalize = true ) {
1084
+ BCLib.ShouldInternalize = Internalize;
1085
+ BCLibs.push_back (BCLib);
1086
+ };
1087
+ auto AddSanBCLibs = [&]() {
1088
+ if (GPUSanEnabled ()) {
1089
+ AddBCLib (getAsanRTLPath (), false );
1090
+ }
1091
+ };
1069
1092
1093
+ AddSanBCLibs ();
1070
1094
AddBCLib (getOCMLPath ());
1071
1095
// FIXME: OpenMP has ockl and ocml contained in libomptarget.bc. However,
1072
1096
// we cannot exclude ocml here because of the crazy always-compile clang
@@ -1076,6 +1100,8 @@ RocmInstallationDetector::getCommonBitcodeLibs(
1076
1100
// __BUILD_MATH_BUILTINS_LIB__ turning static libm functions to extern.
1077
1101
if (!isOpenMP)
1078
1102
AddBCLib (getOCKLPath ());
1103
+ else if (GPUSanEnabled () && isOpenMP)
1104
+ AddBCLib (getOCKLPath (), false );
1079
1105
AddBCLib (getDenormalsAreZeroPath (DAZ));
1080
1106
AddBCLib (getUnsafeMathPath (UnsafeMathOpt || FastRelaxedMath));
1081
1107
AddBCLib (getFiniteOnlyPath (FiniteOnly || FastRelaxedMath));
@@ -1096,14 +1122,15 @@ bool AMDGPUToolChain::shouldSkipArgument(const llvm::opt::Arg *A) const {
1096
1122
return false ;
1097
1123
}
1098
1124
1099
- llvm::SmallVector<std::string , 12 >
1125
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo , 12 >
1100
1126
ROCMToolChain::getCommonDeviceLibNames (const llvm::opt::ArgList &DriverArgs,
1101
1127
const std::string &GPUArch,
1102
1128
bool isOpenMP) const {
1103
1129
RocmInstallationDetector RocmInstallation (getDriver (), getTriple (),
1104
1130
DriverArgs, true , true );
1105
- return amdgpu::dlr::getCommonDeviceLibNames (DriverArgs, getDriver (), GPUArch,
1106
- isOpenMP, RocmInstallation);
1131
+ return amdgpu::dlr::getCommonDeviceLibNames (
1132
+ DriverArgs, getSanitizerArgs (DriverArgs), getDriver (), GPUArch, isOpenMP,
1133
+ RocmInstallation);
1107
1134
}
1108
1135
1109
1136
bool AMDGPUToolChain::shouldSkipSanitizeOption (
@@ -1117,7 +1144,7 @@ bool AMDGPUToolChain::shouldSkipSanitizeOption(
1117
1144
return false ;
1118
1145
1119
1146
if (!DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
1120
- options::OPT_fno_gpu_sanitize, false ))
1147
+ options::OPT_fno_gpu_sanitize, true ))
1121
1148
return true ;
1122
1149
1123
1150
auto &Diags = TC.getDriver ().getDiags ();
0 commit comments