Skip to content

Commit

Permalink
Use NewPM for ASAN/MSAN (#49530)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Baraldi <baraldigabriel@gmail.com>
Co-authored-by: Prem Chintalapudi <prem.chintalapudi@gmail.com>
  • Loading branch information
3 people authored Apr 27, 2023
1 parent 959902f commit f11bfc6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,6 +1775,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
}
}
#if JL_LLVM_VERSION < 150000
#if defined(_COMPILER_ASAN_ENABLED_)
PM->add(createAddressSanitizerFunctionPass());
#endif
Expand All @@ -1783,6 +1784,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
#endif
#if defined(_COMPILER_TSAN_ENABLED_)
PM->add(createThreadSanitizerLegacyPassPass());
#endif
#endif
return;
}
Expand Down Expand Up @@ -1934,6 +1936,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
}
PM->add(createCombineMulAddPass());
PM->add(createDivRemPairsPass());
#if JL_LLVM_VERSION < 150000
#if defined(_COMPILER_ASAN_ENABLED_)
PM->add(createAddressSanitizerFunctionPass());
#endif
Expand All @@ -1943,6 +1946,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
#if defined(_COMPILER_TSAN_ENABLED_)
PM->add(createThreadSanitizerLegacyPassPass());
#endif
#endif
}

// An LLVM module pass that just runs all julia passes in order. Useful for
Expand Down
4 changes: 2 additions & 2 deletions src/cgmemmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ uint8_t *RTDyldMemoryManagerJL::allocateCodeSection(uintptr_t Size,
StringRef SectionName)
{
// allocating more than one code section can confuse libunwind.
#if !defined(_COMPILER_MSAN_ENABLED_)
// TODO: Figure out why msan needs this.
#if !defined(_COMPILER_MSAN_ENABLED_) && !defined(_COMPILER_ASAN_ENABLED_)
// TODO: Figure out why msan and now asan too need this.
assert(!code_allocated);
code_allocated = true;
#endif
Expand Down
13 changes: 11 additions & 2 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@
// 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_) || defined(_COMPILER_ASAN_ENABLED_) || defined(JL_FORCE_JITLINK)
// #define JL_FORCE_JITLINK

#if defined(_COMPILER_ASAN_ENABLED_) || defined(_COMPILER_MSAN_ENABLED_) || defined(_COMPILER_TSAN_ENABLED_)
# define HAS_SANITIZER
#endif
// The sanitizers don't play well with our memory manager

#if defined(_OS_DARWIN_) && defined(_CPU_AARCH64_) || defined(JL_FORCE_JITLINK) || JL_LLVM_VERSION >= 150000 && defined(HAS_SANITIZER)
# 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 @@ -93,7 +100,9 @@ struct OptimizationOptions {
// for middle-end IR optimizations. However, we have not qualified the new
// pass manager on our optimization pipeline yet, so this remains an optional
// define
// #define JL_USE_NEW_PM
#if defined(HAS_SANITIZER) && JL_LLVM_VERSION >= 150000
#define JL_USE_NEW_PM
#endif

struct NewPM {
std::unique_ptr<TargetMachine> TM;
Expand Down

0 comments on commit f11bfc6

Please sign in to comment.