Skip to content

Commit

Permalink
Switch to using orc::ObjectLinkingLayer and a smaller code model on…
Browse files Browse the repository at this point in the history
… Darwin

This change is inspired by this comment [0], switching our linking layer
to the newer one as recommended by [1].  With these changes, I can pass
the `Distributions` test suite on aarch64 darwin, and so it appears it
fixes at least one of the segfault issues noted on apple silicon.

[0] #41440 (comment)
[1] https://llvm.org/docs/JITLink.html#jitlink-and-objectlinkinglayer
  • Loading branch information
staticfloat committed Dec 17, 2021
1 parent 55ad2f0 commit 4d6ebfb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8092,11 +8092,14 @@ extern "C" void jl_init_llvm(void)
}
// Allocate a target...
Optional<CodeModel::Model> codemodel =
#ifdef _P64
#if defined(_OS_DARWIN_) && defined(_CPU_AARCH64_)
// Let LLVM pick its default code model on aarch64 darwin
None;
#elif defined(_P64)
// Make sure we are using the large code model on 64bit
// Let LLVM pick a default suitable for jitting on 32bit
CodeModel::Large;
#else
// Let LLVM pick a default suitable for jitting on 32bit
None;
#endif
auto optlevel = CodeGenOptLevelFor(jl_options.opt_level);
Expand Down
4 changes: 4 additions & 0 deletions src/jitlayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ class JuliaOJIT {
#endif

public:
#if defined(_OS_DARWIN_)
typedef orc::RTDyldObjectLinkingLayer ObjLayerT;
#else
typedef orc::ObjectLinkingLayer ObjLayerT;
#endif
typedef orc::IRCompileLayer CompileLayerT;
#if JL_LLVM_VERSION < 120000
typedef RTDyldObjHandleT ModuleHandleT;
Expand Down

4 comments on commit 4d6ebfb

@dnadlinger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the drive-by comment – just saw this linked from #41440 –, but isn't the conditional in jitlayers.h backwards?

@staticfloat
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're completely right. :)

This commit is completely wrong; the segfault was not fixed by this, and indeed if you fix the conditional, it reveals a bunch of other pieces of code that need to change to properly integrate ObjectLinkingLayer. I'm not the best person to work on this, as I'm not super familiar with the LLVM code, but I have an M1 machine, so I have a vested interest. :)

@dnadlinger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm similarly not an expert, but have an interest in getting native M1 builds usable – while I'm reasonably familiar with LLVM, I haven't worked with the JIT code much at all. At first glance, it seems like the sticking point will be the custom memory manager implementation. I might have a few hours to spare on this during the Christmas break – What would be the best point to coordinate efforts on this?

@vchuravy
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the #internals channel on the JuliaLang public slack

Please sign in to comment.