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.
  • Loading branch information
vchuravy committed Sep 30, 2016
1 parent b9ad81d commit 37f9286
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ 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);
static const char *const prefix = "__";
if (!compiler_rt_hdl)
return 0;
if (strncmp(name, prefix, strlen(prefix)) != 0)
return 0;
return (uintptr_t)jl_dlsym_e(compiler_rt_hdl, name);
}

#ifdef _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 @@ -542,6 +555,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 37f9286

Please sign in to comment.