forked from OSchip/llvm-project
[AMDPU][Sanitizer] Refactor sanitizer options handling for AMDGPU Toolchain
authored by amit.pandey@amd.com ampandey-AMD Differential Revision: https://reviews.llvm.org/D122781
This commit is contained in:
parent
fbeb0db54f
commit
cc2139524f
|
@ -68,6 +68,9 @@ def err_drv_no_rocm_device_lib : Error<
|
|||
"cannot find ROCm device library%select{| for %1|for ABI version %1}0; provide its path via "
|
||||
"'--rocm-path' or '--rocm-device-lib-path', or pass '-nogpulib' to build "
|
||||
"without ROCm device library">;
|
||||
def err_drv_no_asan_rt_lib : Error<
|
||||
"AMDGPU address sanitizer runtime library (asanrtl) is not found. "
|
||||
"Please install ROCm device library which supports address sanitizer">;
|
||||
def err_drv_no_hip_runtime : Error<
|
||||
"cannot find HIP runtime; provide its path via '--rocm-path', or pass "
|
||||
"'-nogpuinc' to build without HIP runtime">;
|
||||
|
|
|
@ -911,6 +911,42 @@ RocmInstallationDetector::getCommonBitcodeLibs(
|
|||
return BCLibs;
|
||||
}
|
||||
|
||||
bool AMDGPUToolChain::shouldSkipSanitizeOption(
|
||||
const ToolChain &TC, const llvm::opt::ArgList &DriverArgs,
|
||||
StringRef TargetID, const llvm::opt::Arg *A) const {
|
||||
// For actions without targetID, do nothing.
|
||||
if (TargetID.empty())
|
||||
return false;
|
||||
Option O = A->getOption();
|
||||
if (!O.matches(options::OPT_fsanitize_EQ))
|
||||
return false;
|
||||
|
||||
if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
|
||||
options::OPT_fno_gpu_sanitize, true))
|
||||
return true;
|
||||
|
||||
auto &Diags = TC.getDriver().getDiags();
|
||||
|
||||
// For simplicity, we only allow -fsanitize=address
|
||||
SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
|
||||
if (K != SanitizerKind::Address)
|
||||
return true;
|
||||
|
||||
llvm::StringMap<bool> FeatureMap;
|
||||
auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
|
||||
|
||||
assert(OptionalGpuArch && "Invalid Target ID");
|
||||
(void)OptionalGpuArch;
|
||||
auto Loc = FeatureMap.find("xnack");
|
||||
if (Loc == FeatureMap.end() || !Loc->second) {
|
||||
Diags.Report(
|
||||
clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
|
||||
<< A->getAsString(DriverArgs) << TargetID << "xnack+";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AMDGPUToolChain::shouldSkipArgument(const llvm::opt::Arg *A) const {
|
||||
Option O = A->getOption();
|
||||
if (O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie))
|
||||
|
|
|
@ -99,6 +99,12 @@ public:
|
|||
/// Needed for translating LTO options.
|
||||
const char *getDefaultLinker() const override { return "ld.lld"; }
|
||||
|
||||
/// Should skip Sanitize options
|
||||
bool shouldSkipSanitizeOption(const ToolChain &TC,
|
||||
const llvm::opt::ArgList &DriverArgs,
|
||||
StringRef TargetID,
|
||||
const llvm::opt::Arg *A) const;
|
||||
|
||||
/// Should skip argument.
|
||||
bool shouldSkipArgument(const llvm::opt::Arg *Arg) const;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "clang/Driver/DriverDiagnostic.h"
|
||||
#include "clang/Driver/InputInfo.h"
|
||||
#include "clang/Driver/Options.h"
|
||||
#include "clang/Driver/SanitizerArgs.h"
|
||||
#include "clang/Driver/Tool.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
|
@ -304,7 +305,8 @@ llvm::opt::DerivedArgList *AMDGPUOpenMPToolChain::TranslateArgs(
|
|||
|
||||
if (DeviceOffloadKind == Action::OFK_OpenMP) {
|
||||
for (Arg *A : Args)
|
||||
if (!llvm::is_contained(*DAL, A))
|
||||
if (!shouldSkipSanitizeOption(*this, Args, BoundArch, A) &&
|
||||
!llvm::is_contained(*DAL, A))
|
||||
DAL->append(A);
|
||||
|
||||
std::string Arch = DAL->getLastArgValue(options::OPT_march_EQ).str();
|
||||
|
|
|
@ -93,6 +93,10 @@ public:
|
|||
|
||||
SanitizerMask getSupportedSanitizers() const override;
|
||||
|
||||
RocmInstallationDetector getRocmInstallationLoc() const {
|
||||
return RocmInstallation;
|
||||
}
|
||||
|
||||
VersionTuple
|
||||
computeMSVCVersion(const Driver *D,
|
||||
const llvm::opt::ArgList &Args) const override;
|
||||
|
|
|
@ -35,43 +35,6 @@ using namespace llvm::opt;
|
|||
#define NULL_FILE "/dev/null"
|
||||
#endif
|
||||
|
||||
static bool shouldSkipSanitizeOption(const ToolChain &TC,
|
||||
const llvm::opt::ArgList &DriverArgs,
|
||||
StringRef TargetID,
|
||||
const llvm::opt::Arg *A) {
|
||||
// For actions without targetID, do nothing.
|
||||
if (TargetID.empty())
|
||||
return false;
|
||||
Option O = A->getOption();
|
||||
if (!O.matches(options::OPT_fsanitize_EQ))
|
||||
return false;
|
||||
|
||||
if (!DriverArgs.hasFlag(options::OPT_fgpu_sanitize,
|
||||
options::OPT_fno_gpu_sanitize, true))
|
||||
return true;
|
||||
|
||||
auto &Diags = TC.getDriver().getDiags();
|
||||
|
||||
// For simplicity, we only allow -fsanitize=address
|
||||
SanitizerMask K = parseSanitizerValue(A->getValue(), /*AllowGroups=*/false);
|
||||
if (K != SanitizerKind::Address)
|
||||
return true;
|
||||
|
||||
llvm::StringMap<bool> FeatureMap;
|
||||
auto OptionalGpuArch = parseTargetID(TC.getTriple(), TargetID, &FeatureMap);
|
||||
|
||||
assert(OptionalGpuArch && "Invalid Target ID");
|
||||
(void)OptionalGpuArch;
|
||||
auto Loc = FeatureMap.find("xnack");
|
||||
if (Loc == FeatureMap.end() || !Loc->second) {
|
||||
Diags.Report(
|
||||
clang::diag::warn_drv_unsupported_option_for_offload_arch_req_feature)
|
||||
<< A->getAsString(DriverArgs) << TargetID << "xnack+";
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void AMDGCN::Linker::constructLldCommand(Compilation &C, const JobAction &JA,
|
||||
const InputInfoList &Inputs,
|
||||
const InputInfo &Output,
|
||||
|
@ -337,12 +300,7 @@ HIPAMDToolChain::getHIPDeviceLibs(const llvm::opt::ArgList &DriverArgs) const {
|
|||
getSanitizerArgs(DriverArgs).needsAsanRt()) {
|
||||
auto AsanRTL = RocmInstallation.getAsanRTLPath();
|
||||
if (AsanRTL.empty()) {
|
||||
unsigned DiagID = getDriver().getDiags().getCustomDiagID(
|
||||
DiagnosticsEngine::Error,
|
||||
"AMDGPU address sanitizer runtime library (asanrtl) is not found. "
|
||||
"Please install ROCm device library which supports address "
|
||||
"sanitizer");
|
||||
getDriver().Diag(DiagID);
|
||||
getDriver().Diag(diag::err_drv_no_asan_rt_lib);
|
||||
return {};
|
||||
} else
|
||||
BCLibs.push_back({AsanRTL.str(), /*ShouldInternalize=*/false});
|
||||
|
|
|
@ -62,7 +62,7 @@
|
|||
// RDC: {{"[^"]*clang[^"]*".* "-emit-llvm-bc".* "-fcuda-is-device".* "-mlink-bitcode-file" ".*asanrtl.bc".* "-mlink-builtin-bitcode" ".*hip.bc".* "-fsanitize=address".*}} "-o" "[[OUT:[^"]*.bc]]"
|
||||
// RDC-NOT: {{"[^"]*lld(\.exe){0,1}".*}} "[[OUT]]" {{".*asanrtl.bc" ".*hip.bc"}}
|
||||
|
||||
// FAIL: AMDGPU address sanitizer runtime library (asanrtl) is not found. Please install ROCm device library which supports address sanitizer
|
||||
// FAIL: error: AMDGPU address sanitizer runtime library (asanrtl) is not found. Please install ROCm device library which supports address sanitizer
|
||||
|
||||
// XNACK-DAG: warning: ignoring '-fsanitize=leak' option as it is not currently supported for target 'amdgcn-amd-amdhsa'
|
||||
// XNACK-DAG: warning: ignoring '-fsanitize=address' option as it is not currently supported for offload arch 'gfx900:xnack-'. Use it with an offload arch containing 'xnack+' instead
|
||||
|
|
Loading…
Reference in New Issue