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 35b4042
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ $(BUILDDIR)/builtins.o $(BUILDDIR)/builtins.dbg.obj: $(SRCDIR)/iddict.c $(SRCDIR
$(BUILDDIR)/codegen.o $(BUILDDIR)/codegen.dbg.obj: $(addprefix $(SRCDIR)/,\
intrinsics.cpp jitlayers.h debug-registry.h intrinsics.h codegen_shared.h cgutils.cpp ccall.cpp abi_*.cpp processor.h builtin_proto.h)
$(BUILDDIR)/debuginfo.o $(BUILDDIR)/debuginfo.dbg.obj: $(addprefix $(SRCDIR)/,debuginfo.h processor.h jitlayers.h debug-registry.h)
$(BUILDDIR)/disasm.o $(BUILDDIR)/disasm.dbg.obj: $(SRCDIR)/debuginfo.h $(SRCDIR)/processor.h
$(BUILDDIR)/disasm.o $(BUILDDIR)/disasm.dbg.obj: $(SRCDIR)/debuginfo.h $(SRCDIR)/processor.h $(SRCDIR)/jitlayers.h
$(BUILDDIR)/dump.o $(BUILDDIR)/dump.dbg.obj: $(addprefix $(SRCDIR)/,common_symbols1.inc common_symbols2.inc builtin_proto.h serialize.h)
$(BUILDDIR)/gc-debug.o $(BUILDDIR)/gc-debug.dbg.obj: $(SRCDIR)/gc.h
$(BUILDDIR)/gc-pages.o $(BUILDDIR)/gc-pages.dbg.obj: $(SRCDIR)/gc.h
Expand Down
7 changes: 5 additions & 2 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <llvm/Target/TargetMachine.h>
#include "julia_assert.h"
#include "debug-registry.h"
#include "platform.h"

#include <stack>
#include <queue>
Expand All @@ -40,7 +41,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_ASAN_ENABLED_) && 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 +140,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 35b4042

Please sign in to comment.