@@ -946,8 +946,12 @@ void ROCMToolChain::addClangTargetOptions(
946
946
StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile (CanonArch);
947
947
auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion (
948
948
getAMDGPUCodeObjectVersion (getDriver (), DriverArgs));
949
+ std::tuple<bool , const SanitizerArgs> GPUSan (
950
+ DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
951
+ options::OPT_fno_gpu_sanitize, true ),
952
+ getSanitizerArgs (DriverArgs));
949
953
if (!RocmInstallation->checkCommonBitcodeLibs (CanonArch, LibDeviceFile,
950
- ABIVer))
954
+ ABIVer, GPUSan ))
951
955
return ;
952
956
953
957
bool Wave64 = isWave64 (DriverArgs, Kind);
@@ -965,28 +969,32 @@ void ROCMToolChain::addClangTargetOptions(
965
969
DriverArgs.hasArg (options::OPT_cl_fp32_correctly_rounded_divide_sqrt);
966
970
967
971
// Add the OpenCL specific bitcode library.
968
- llvm::SmallVector<std::string , 12 > BCLibs;
969
- BCLibs.push_back (RocmInstallation->getOpenCLPath ().str ());
972
+ llvm::SmallVector<BitCodeLibraryInfo , 12 > BCLibs;
973
+ BCLibs.emplace_back (RocmInstallation->getOpenCLPath ().str ());
970
974
971
975
// Add the generic set of libraries.
972
976
BCLibs.append (RocmInstallation->getCommonBitcodeLibs (
973
977
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
974
- FastRelaxedMath, CorrectSqrt, ABIVer, false ));
978
+ FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, false ));
975
979
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" );
980
+ for (auto [BCFile, Internalize] : BCLibs) {
981
+ if (Internalize)
982
+ CC1Args.push_back (" -mlink-builtin-bitcode" );
983
+ else
984
+ CC1Args.push_back (" -mlink-bitcode-file" );
983
985
CC1Args.push_back (DriverArgs.MakeArgString (BCFile));
984
986
}
985
987
}
986
988
987
989
bool RocmInstallationDetector::checkCommonBitcodeLibs (
988
- StringRef GPUArch, StringRef LibDeviceFile,
989
- DeviceLibABIVersion ABIVer) const {
990
+ StringRef GPUArch, StringRef LibDeviceFile, DeviceLibABIVersion ABIVer,
991
+ std::tuple<bool , const SanitizerArgs> &GPUSan) const {
992
+ if (std::get<bool >(GPUSan))
993
+ if (std::get<const SanitizerArgs>(GPUSan).needsAsanRt () &&
994
+ getAsanRTLPath ().empty ()) {
995
+ D.Diag (diag::err_drv_no_asan_rt_lib);
996
+ return false ;
997
+ }
990
998
if (!hasDeviceLibrary ()) {
991
999
D.Diag (diag::err_drv_no_rocm_device_lib) << 0 ;
992
1000
return false ;
@@ -1002,18 +1010,35 @@ bool RocmInstallationDetector::checkCommonBitcodeLibs(
1002
1010
return true ;
1003
1011
}
1004
1012
1005
- llvm::SmallVector<std::string , 12 >
1013
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo , 12 >
1006
1014
RocmInstallationDetector::getCommonBitcodeLibs (
1007
1015
const llvm::opt::ArgList &DriverArgs, StringRef LibDeviceFile, bool Wave64,
1008
1016
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 ()); };
1017
+ bool CorrectSqrt, DeviceLibABIVersion ABIVer,
1018
+ const std::tuple<bool , const SanitizerArgs> &GPUSan,
1019
+ bool isOpenMP = false ) const {
1020
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo, 12 > BCLibs;
1021
+
1022
+ auto GPUSanEnabled = [GPUSan]() { return std::get<bool >(GPUSan); };
1023
+ auto AddBCLib = [&](ToolChain::BitCodeLibraryInfo BCLib,
1024
+ bool Internalize = true ) {
1025
+ BCLib.ShouldInternalize = Internalize;
1026
+ BCLibs.emplace_back (BCLib);
1027
+ };
1028
+ auto AddSanBCLibs = [&]() {
1029
+ auto SanArgs = std::get<const SanitizerArgs>(GPUSan);
1030
+ if (GPUSanEnabled ()) {
1031
+ if (SanArgs.needsAsanRt ())
1032
+ AddBCLib (getAsanRTLPath (), false );
1033
+ }
1034
+ };
1013
1035
1036
+ AddSanBCLibs ();
1014
1037
AddBCLib (getOCMLPath ());
1015
1038
if (!isOpenMP)
1016
1039
AddBCLib (getOCKLPath ());
1040
+ else if (GPUSanEnabled () && isOpenMP)
1041
+ AddBCLib (getOCKLPath (), false );
1017
1042
AddBCLib (getDenormalsAreZeroPath (DAZ));
1018
1043
AddBCLib (getUnsafeMathPath (UnsafeMathOpt || FastRelaxedMath));
1019
1044
AddBCLib (getFiniteOnlyPath (FiniteOnly || FastRelaxedMath));
@@ -1027,7 +1052,7 @@ RocmInstallationDetector::getCommonBitcodeLibs(
1027
1052
return BCLibs;
1028
1053
}
1029
1054
1030
- llvm::SmallVector<std::string , 12 >
1055
+ llvm::SmallVector<ToolChain::BitCodeLibraryInfo , 12 >
1031
1056
ROCMToolChain::getCommonDeviceLibNames (const llvm::opt::ArgList &DriverArgs,
1032
1057
const std::string &GPUArch,
1033
1058
bool isOpenMP) const {
@@ -1037,8 +1062,12 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
1037
1062
StringRef LibDeviceFile = RocmInstallation->getLibDeviceFile (CanonArch);
1038
1063
auto ABIVer = DeviceLibABIVersion::fromCodeObjectVersion (
1039
1064
getAMDGPUCodeObjectVersion (getDriver (), DriverArgs));
1065
+ std::tuple<bool , const SanitizerArgs> GPUSan (
1066
+ DriverArgs.hasFlag (options::OPT_fgpu_sanitize,
1067
+ options::OPT_fno_gpu_sanitize, true ),
1068
+ getSanitizerArgs (DriverArgs));
1040
1069
if (!RocmInstallation->checkCommonBitcodeLibs (CanonArch, LibDeviceFile,
1041
- ABIVer))
1070
+ ABIVer, GPUSan ))
1042
1071
return {};
1043
1072
1044
1073
// If --hip-device-lib is not set, add the default bitcode libraries.
@@ -1061,7 +1090,7 @@ ROCMToolChain::getCommonDeviceLibNames(const llvm::opt::ArgList &DriverArgs,
1061
1090
1062
1091
return RocmInstallation->getCommonBitcodeLibs (
1063
1092
DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
1064
- FastRelaxedMath, CorrectSqrt, ABIVer, isOpenMP);
1093
+ FastRelaxedMath, CorrectSqrt, ABIVer, GPUSan, isOpenMP);
1065
1094
}
1066
1095
1067
1096
bool AMDGPUToolChain::shouldSkipSanitizeOption (
0 commit comments