Skip to content

Commit

Permalink
Load a shared version of compiler-rt in jitlayers
Browse files Browse the repository at this point in the history
LLVM intrinsics either map to instructions or to functions in
compiler-rt. If we can't find a symbol look into a shared version
of compiler-rt and resolve the functions there.

On Darwin we have to use a unmangled version of the function name.
  • Loading branch information
vchuravy committed Dec 27, 2016
1 parent 3b7c6ee commit 9db9c76
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,29 @@ void NotifyDebugger(jit_code_entry *JITCodeEntry)
}
// ------------------------ END OF TEMPORARY COPY FROM LLVM -----------------

// Resolve compiler-rt functions in the shared library that we created from compiler-rt
static uint64_t resolve_compiler_rt(const char *name)
{
static void *compiler_rt_hdl = jl_load_dynamic_library_e("libcompiler-rt",
JL_RTLD_LOCAL | JL_RTLD_LAZY);
static const char *const prefix = "__";
if (!compiler_rt_hdl) {
jl_printf(JL_STDERR, "WARNING: Unable to load compiler-rt\n");
return 0;
}
if (strncmp(name, prefix, strlen(prefix)) != 0)
return 0;
#if defined(_OS_DARWIN_)
// jl_dlsym_e expects an unmangled 'C' symbol name,
// so iff we are on Darwin we strip the leading '_' off.
static const char *const mangled_prefix = "___";
if (strncmp(name, mangled_prefix, strlen(mangled_prefix)) == 0) {
++name;
}
#endif
return (uintptr_t)jl_dlsym_e(compiler_rt_hdl, name);
}

#if defined(_OS_LINUX_)
// Resolve non-lock free atomic functions in the libatomic library.
// This is the library that provides support for c11/c++11 atomic operations.
Expand Down Expand Up @@ -546,6 +569,8 @@ void JuliaOJIT::addModule(std::unique_ptr<Module> M)
if (uint64_t addr = resolve_atomic(Name.c_str()))
return JL_SymbolInfo(addr, JITSymbolFlags::Exported);
#endif
if (uint64_t addr = resolve_compiler_rt(Name.c_str()))
return JL_SymbolInfo(addr, JITSymbolFlags::Exported);
// Return failure code
return JL_SymbolInfo(nullptr);
},
Expand Down

0 comments on commit 9db9c76

Please sign in to comment.