@@ -950,6 +950,11 @@ void ROCMToolChain::addClangTargetOptions(
950
950
ABIVer))
951
951
return ;
952
952
953
+ std::tuple<bool , const SanitizerArgs> GPUSan (
954
+ DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
955
+ options::OPT_fno_gpu_sanitize, true ),
956
+ getSanitizerArgs (DriverArgs));
957
+
953
958
bool Wave64 = isWave64 (DriverArgs, Kind);
954
959
955
960
// TODO: There are way too many flags that change this. Do we need to check
@@ -965,21 +970,19 @@ void ROCMToolChain::addClangTargetOptions(
965
970
DriverArgs.hasArg (options::OPT_cl_fp32_correctly_rounded_divide_sqrt);
966
971
967
972
// Add the OpenCL specific bitcode library.
968
- llvm::SmallVector<std::string , 12 > BCLibs;
969
- BCLibs.push_back (RocmInstallation->getOpenCLPath ().str ());
973
+ llvm::SmallVector<BitCodeLibraryInfo , 12 > BCLibs;
974
+ BCLibs.emplace_back (RocmInstallation->getOpenCLPath ().str ());
970
975
971
976
// Add the generic set of libraries.
972
977
BCLibs.append (RocmInstallation->getCommonBitcodeLibs (
973
978
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
974
- FastRelaxedMath, CorrectSqrt, ABIVer, false ));
979
+ FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, false ));
975
980
976
- if (getSanitizerArgs (DriverArgs).needsAsanRt ()) {
977
- CC1Args.push_back (" -mlink-bitcode-file" );
978
- CC1Args.push_back (
979
- DriverArgs.MakeArgString (RocmInstallation->getAsanRTLPath ()));
980
- }
981
- for (StringRef BCFile : BCLibs) {
982
- CC1Args.push_back (" -mlink-builtin-bitcode" );
981
+ for (auto [BCFile, Internalize] : BCLibs) {
982
+ if (Internalize)
983
+ CC1Args.push_back (" -mlink-builtin-bitcode" );
984
+ else
985
+ CC1Args.push_back (" -mlink-bitcode-file" );
983
986
CC1Args.push_back (DriverArgs.MakeArgString (BCFile));
984
987
}
985
988
}
@@ -1002,18 +1005,35 @@ bool RocmInstallationDetector::checkCommonBitcodeLibs(
1002
1005
return true ;
1003
1006
}
1004
1007
1005
- llvm::SmallVector<std::string , 12 >
1008
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo , 12 >
1006
1009
RocmInstallationDetector::getCommonBitcodeLibs (
1007
1010
const llvm::opt::ArgList &DriverArgs, StringRef LibDeviceFile, bool Wave64,
1008
1011
bool DAZ, bool FiniteOnly, bool UnsafeMathOpt, bool FastRelaxedMath,
1009
- bool CorrectSqrt, DeviceLibABIVersion ABIVer, bool isOpenMP = false ) const {
1010
- llvm::SmallVector<std::string, 12 > BCLibs;
1011
-
1012
- auto AddBCLib = [&](StringRef BCFile) { BCLibs.push_back (BCFile.str ()); };
1012
+ bool CorrectSqrt, DeviceLibABIVersion ABIVer,
1013
+ const std::tuple<bool , const SanitizerArgs> &GPUSan,
1014
+ bool isOpenMP = false ) const {
1015
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12 > BCLibs;
1016
+
1017
+ auto GPUSanEnabled = [GPUSan]() { return std::get<bool >(GPUSan); };
1018
+ auto AddBCLib = [&](ToolChain::BitCodeLibraryInfo BCLib,
1019
+ bool Internalize = true ) {
1020
+ BCLib.ShouldInternalize = Internalize;
1021
+ BCLibs.emplace_back (BCLib);
1022
+ };
1023
+ auto AddSanBCLibs = [&]() {
1024
+ if (GPUSanEnabled ()) {
1025
+ auto SanArgs = std::get<const SanitizerArgs>(GPUSan);
1026
+ if (SanArgs.needsAsanRt ())
1027
+ AddBCLib (getAsanRTLPath (), false );
1028
+ }
1029
+ };
1013
1030
1031
+ AddSanBCLibs ();
1014
1032
AddBCLib (getOCMLPath ());
1015
1033
if (!isOpenMP)
1016
1034
AddBCLib (getOCKLPath ());
1035
+ else if (GPUSanEnabled () && isOpenMP)
1036
+ AddBCLib (getOCKLPath (), false );
1017
1037
AddBCLib (getDenormalsAreZeroPath (DAZ));
1018
1038
AddBCLib (getUnsafeMathPath (UnsafeMathOpt || FastRelaxedMath));
1019
1039
AddBCLib (getFiniteOnlyPath (FiniteOnly || FastRelaxedMath));
@@ -1027,7 +1047,7 @@ RocmInstallationDetector::getCommonBitcodeLibs(
1027
1047
return BCLibs;
1028
1048
}
1029
1049
1030
- llvm::SmallVector<std::string , 12 >
1050
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo , 12 >
1031
1051
ROCMToolChain::getCommonDeviceLibNames (const llvm::opt::ArgList &DriverArgs,
1032
1052
const std::string &GPUArch,
1033
1053
bool isOpenMP) const {
@@ -1044,6 +1064,10 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
1044
1064
// If --hip-device-lib is not set, add the default bitcode libraries.
1045
1065
// TODO: There are way too many flags that change this. Do we need to check
1046
1066
// them all?
1067
+ std::tuple<bool , const SanitizerArgs> GPUSan (
1068
+ DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
1069
+ options::OPT_fno_gpu_sanitize, true ),
1070
+ getSanitizerArgs (DriverArgs));
1047
1071
bool DAZ = DriverArgs.hasFlag (options::OPT_fgpu_flush_denormals_to_zero,
1048
1072
options::OPT_fno_gpu_flush_denormals_to_zero,
1049
1073
getDefaultDenormsAreZeroForTarget (Kind));
@@ -1061,7 +1085,7 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
1061
1085
1062
1086
return RocmInstallation->getCommonBitcodeLibs (
1063
1087
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
1064
- FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
1088
+ FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, isOpenMP);
1065
1089
}
1066
1090
1067
1091
bool AMDGPUToolChain::shouldSkipSanitizeOption (
0 commit comments