Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair jl_init. #38950

Merged
merged 2 commits into from
Dec 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Export jl_get_libdir and use it from jl_init to find libjulia.
  • Loading branch information
GunnarFarneback committed Dec 20, 2020
commit ba3131606f95a9eac6b624389dac43d6c9a70853
20 changes: 12 additions & 8 deletions cli/loader_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,28 @@ static void * lookup_symbol(const void * lib_handle, const char * symbol_name) {
}

char lib_dir[PATH_MAX];
const char * get_libdir()
JL_DLLEXPORT const char * jl_get_libdir()
{
// Reuse the path if this is not the first call.
if (lib_dir[0] != 0) {
return lib_dir;
}
#if defined(_OS_WINDOWS_)
// On Windows, we use GetModuleFileNameW
wchar_t libjulia_path[PATH_MAX];
HMODULE libjulia_internal = NULL;
HMODULE libjulia = NULL;

// Get a handle to libjulia internal
if (!utf8_to_wchar(LIBJULIA_NAME, libjulia_path, PATH_MAX)) {
jl_loader_print_stderr3("ERROR: Unable to convert path ", LIBJULIA_NAME, " to wide string!\n");
exit(1);
}
libjulia_internal = LoadLibraryW(libjulia_path);
if (libjulia_internal == NULL) {
libjulia = LoadLibraryW(libjulia_path);
if (libjulia == NULL) {
jl_loader_print_stderr3("ERROR: Unable to load ", LIBJULIA_NAME, "!\n");
exit(1);
}
if (!GetModuleFileName(libjulia_internal, libjulia_path, PATH_MAX)) {
if (!GetModuleFileName(libjulia, libjulia_path, PATH_MAX)) {
GunnarFarneback marked this conversation as resolved.
Show resolved Hide resolved
jl_loader_print_stderr("ERROR: GetModuleFileName() failed\n");
exit(1);
}
Expand All @@ -107,8 +111,8 @@ const char * get_libdir()
#else
// On all other platforms, use dladdr()
Dl_info info;
if (!dladdr(&get_libdir, &info)) {
jl_loader_print_stderr("ERROR: Unable to dladdr(&get_libdir)!\n");
if (!dladdr(&jl_get_libdir, &info)) {
jl_loader_print_stderr("ERROR: Unable to dladdr(&jl_get_libdir)!\n");
jl_loader_print_stderr3("Message:", dlerror(), "\n");
exit(1);
}
Expand All @@ -126,7 +130,7 @@ const char * get_libdir()
void * libjulia_internal = NULL;
__attribute__((constructor)) void jl_load_libjulia_internal(void) {
// Introspect to find our own path
const char * lib_dir = get_libdir();
const char * lib_dir = jl_get_libdir();

// Pre-load libraries that libjulia-internal needs.
int deps_len = strlen(dep_libs);
Expand Down
16 changes: 2 additions & 14 deletions src/jlapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,9 @@ JL_DLLEXPORT void jl_init(void)
{
char *libbindir = NULL;
#ifdef _OS_WINDOWS_
void *hdl = (void*)jl_load_dynamic_library(NULL, JL_RTLD_DEFAULT, 0);
if (hdl) {
char *to_free = (char*)jl_pathname_for_handle(hdl);
if (to_free) {
libbindir = strdup(dirname(to_free));
free(to_free);
}
}
libbindir = strdup(jl_get_libdir());
#else
Dl_info dlinfo;
if (dladdr((void*)jl_init, &dlinfo) != 0 && dlinfo.dli_fname) {
char *to_free = strdup(dlinfo.dli_fname);
(void)asprintf(&libbindir, "%s" PATHSEPSTRING ".." PATHSEPSTRING "%s", dirname(to_free), "bin");
free(to_free);
}
(void)asprintf(&libbindir, "%s" PATHSEPSTRING ".." PATHSEPSTRING "%s", jl_get_libdir(), "bin");
#endif
if (!libbindir) {
printf("jl_init unable to find libjulia!\n");
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,7 @@ typedef enum {
#define jl_init jl_init__threading
#define jl_init_with_image jl_init_with_image__threading

JL_DLLEXPORT const char *jl_get_libdir(void);
JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel);
JL_DLLEXPORT void jl_init(void);
JL_DLLEXPORT void jl_init_with_image(const char *julia_bindir,
Expand Down