Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NewPM for ASAN/MSAN #49530

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,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 @@ -1776,6 +1777,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 @@ -1927,6 +1929,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 @@ -1936,6 +1939,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) || defined(HAS_SANITIZER)
vchuravy marked this conversation as resolved.
Show resolved Hide resolved
# 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