Skip to content

Commit

Permalink
Fix ASAN/MSAN builds
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi committed Jul 21, 2022
1 parent 9ebd5ce commit b4e44f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
// and feature support (e.g. Windows, JITEventListeners for various profilers,
// etc.). Thus, we currently only use JITLink where absolutely required, that is,
// for Mac/aarch64.
#if defined(_OS_DARWIN_) && defined(_CPU_AARCH64_)

#define JL_USE_NEW_PM

#if defined(_OS_DARWIN_) && defined(_CPU_AARCH64_) || defined(_COMPILER_USE_ASAN_) && defined(JL_USE_NEW_PM) && defined(_OS_LINUX_)
# if JL_LLVM_VERSION < 130000
# pragma message("On aarch64-darwin, LLVM version >= 13 is required for JITLink; fallback suffers from occasional segfaults")
# endif
Expand Down Expand Up @@ -136,7 +139,6 @@ struct AnalysisManagers {

OptimizationLevel getOptLevel(int optlevel);

#define JL_USE_NEW_PM

typedef struct _jl_llvm_functions_t {
std::string functionObject; // jlcall llvm Function name
Expand Down
18 changes: 7 additions & 11 deletions src/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,17 @@ namespace {

#ifdef _COMPILER_MSAN_ENABLED_
auto MSanPass = [&](/*SanitizerMask Mask, */bool CompileKernel) {
// if (LangOpts.Sanitize.has(Mask)) {
// if (LangOpts.Sanitize.has(Mask)) {
// int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
// bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);

// MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
// CodeGenOpts.SanitizeMemoryParamRetval);
MemorySanitizerOptions options{};
#if JL_LLVM_VERSION >= 140000
// CodeGenOpts.SanitizeMemoryParamRetval);
MemorySanitizerOptions options;
MPM.addPass(ModuleMemorySanitizerPass(options));
#endif
FunctionPassManager FPM;
FPM.addPass(MemorySanitizerPass(options));
if (O.getSpeedupLevel() != 0) {
if (O != OptimizationLevel::O0) {
// MemorySanitizer inserts complex instrumentation that mostly
// follows the logic of the original code, but operates on
// "shadow" values. It can benefit from re-running some
Expand All @@ -121,17 +119,15 @@ namespace {
// compiler-rt/test/msan/select_origin.cpp.
}
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
// }
// }
};
MSanPass(/*SanitizerKind::Memory, */false);
// MSanPass(SanitizerKind::KernelMemory, true);
#endif

#ifdef _COMPILER_TSAN_ENABLED_
// if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
#if JL_LLVM_VERSION >= 140000
MPM.addPass(ModuleThreadSanitizerPass());
#endif
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
// }
#endif
Expand All @@ -152,8 +148,8 @@ namespace {
MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
// MPM.addPass(ModuleAddressSanitizerPass(
// Opts, UseGlobalGC, UseOdrIndicator, DestructorKind));
MPM.addPass(ModuleAddressSanitizerPass());
MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass()));
//Let's assume the defaults are actually fine for our purposes
MPM.addPass(ModuleAddressSanitizerPass(AddressSanitizerOptions()));
// }
};
ASanPass(/*SanitizerKind::Address, */false);
Expand Down

0 comments on commit b4e44f0

Please sign in to comment.