Skip to content

Commit f11bfc6

Browse files
vchuravygbaraldipchintalapudi
authored
Use NewPM for ASAN/MSAN (#49530)
Co-authored-by: Gabriel Baraldi <[email protected]> Co-authored-by: Prem Chintalapudi <[email protected]>
1 parent 959902f commit f11bfc6

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

src/aotcompile.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,6 +1775,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
17751775
PM->add(createCFGSimplificationPass(basicSimplifyCFGOptions));
17761776
}
17771777
}
1778+
#if JL_LLVM_VERSION < 150000
17781779
#if defined(_COMPILER_ASAN_ENABLED_)
17791780
PM->add(createAddressSanitizerFunctionPass());
17801781
#endif
@@ -1783,6 +1784,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
17831784
#endif
17841785
#if defined(_COMPILER_TSAN_ENABLED_)
17851786
PM->add(createThreadSanitizerLegacyPassPass());
1787+
#endif
17861788
#endif
17871789
return;
17881790
}
@@ -1934,6 +1936,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
19341936
}
19351937
PM->add(createCombineMulAddPass());
19361938
PM->add(createDivRemPairsPass());
1939+
#if JL_LLVM_VERSION < 150000
19371940
#if defined(_COMPILER_ASAN_ENABLED_)
19381941
PM->add(createAddressSanitizerFunctionPass());
19391942
#endif
@@ -1943,6 +1946,7 @@ void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level,
19431946
#if defined(_COMPILER_TSAN_ENABLED_)
19441947
PM->add(createThreadSanitizerLegacyPassPass());
19451948
#endif
1949+
#endif
19461950
}
19471951

19481952
// An LLVM module pass that just runs all julia passes in order. Useful for

src/cgmemmgr.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -860,8 +860,8 @@ uint8_t *RTDyldMemoryManagerJL::allocateCodeSection(uintptr_t Size,
860860
StringRef SectionName)
861861
{
862862
// allocating more than one code section can confuse libunwind.
863-
#if !defined(_COMPILER_MSAN_ENABLED_)
864-
// TODO: Figure out why msan needs this.
863+
#if !defined(_COMPILER_MSAN_ENABLED_) && !defined(_COMPILER_ASAN_ENABLED_)
864+
// TODO: Figure out why msan and now asan too need this.
865865
assert(!code_allocated);
866866
code_allocated = true;
867867
#endif

src/jitlayers.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@
4242
// and feature support (e.g. Windows, JITEventListeners for various profilers,
4343
// etc.). Thus, we currently only use JITLink where absolutely required, that is,
4444
// for Mac/aarch64.
45-
#if defined(_OS_DARWIN_) && defined(_CPU_AARCH64_) || defined(_COMPILER_ASAN_ENABLED_) || defined(JL_FORCE_JITLINK)
45+
// #define JL_FORCE_JITLINK
46+
47+
#if defined(_COMPILER_ASAN_ENABLED_) || defined(_COMPILER_MSAN_ENABLED_) || defined(_COMPILER_TSAN_ENABLED_)
48+
# define HAS_SANITIZER
49+
#endif
50+
// The sanitizers don't play well with our memory manager
51+
52+
#if defined(_OS_DARWIN_) && defined(_CPU_AARCH64_) || defined(JL_FORCE_JITLINK) || JL_LLVM_VERSION >= 150000 && defined(HAS_SANITIZER)
4653
# if JL_LLVM_VERSION < 130000
4754
# pragma message("On aarch64-darwin, LLVM version >= 13 is required for JITLink; fallback suffers from occasional segfaults")
4855
# endif
@@ -93,7 +100,9 @@ struct OptimizationOptions {
93100
// for middle-end IR optimizations. However, we have not qualified the new
94101
// pass manager on our optimization pipeline yet, so this remains an optional
95102
// define
96-
// #define JL_USE_NEW_PM
103+
#if defined(HAS_SANITIZER) && JL_LLVM_VERSION >= 150000
104+
#define JL_USE_NEW_PM
105+
#endif
97106

98107
struct NewPM {
99108
std::unique_ptr<TargetMachine> TM;

0 commit comments

Comments
 (0)