Skip to content

Commit

Permalink
Merge pull request JuliaLang#38172 from JuliaLang/tb/jl_get_libllvm
Browse files Browse the repository at this point in the history
Add a function to locate the loaded libLLVM.
  • Loading branch information
maleadt authored Oct 28, 2020
2 parents 29a6e66 + 1246579 commit 28f68eb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/version.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ else
VersionNumber(libllvm_version_string)
end

libllvm() = ccall(:jl_get_libllvm, Any, ())

function banner(io::IO = stdout)
if GIT_VERSION_INFO.tagged_commit
commit_string = TAGGED_RELEASE_BANNER
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,7 @@ JL_DLLEXPORT long jl_getallocationgranularity(void) JL_NOTSAFEPOINT;
JL_DLLEXPORT int jl_is_debugbuild(void) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_sym_t *jl_get_UNAME(void) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_sym_t *jl_get_ARCH(void) JL_NOTSAFEPOINT;
JL_DLLEXPORT jl_value_t *jl_get_libllvm(void) JL_NOTSAFEPOINT;

// environment entries
JL_DLLEXPORT jl_value_t *jl_environ(int i);
Expand Down
22 changes: 22 additions & 0 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@

#include "julia_assert.h"

#include <llvm-c/Core.h>

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -651,6 +653,26 @@ JL_DLLEXPORT int jl_threading_enabled(void)
return 1;
}

JL_DLLEXPORT jl_value_t *jl_get_libllvm(void) JL_NOTSAFEPOINT {
#if defined(_OS_WINDOWS_)
HMODULE mod;
// FIXME: GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS on LLVMContextCreate,
// but that just points to libjulia.dll
if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, "LLVM", &mod))
return jl_nothing;

char path[MAX_PATH];
if (!GetModuleFileNameA(mod, path, sizeof(path)))
return jl_nothing;
return (jl_value_t*) jl_symbol(path);
#else
Dl_info dli;
if (!dladdr(LLVMContextCreate, &dli))
return jl_nothing;
return (jl_value_t*) jl_symbol(dli.dli_fname);
#endif
}

#ifdef __cplusplus
}
#endif
3 changes: 3 additions & 0 deletions test/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
sprint(Base.Sys.cpu_summary)
@test Base.Sys.uptime() > 0
Base.Sys.loadavg()

@test Base.libllvm() isa Symbol
@test contains(String(Base.libllvm()), "LLVM")

0 comments on commit 28f68eb

Please sign in to comment.