Skip to content

Commit cffc508

Browse files
committed
Refactor initialization slightly in cases where we have a handle
1 parent 8471442 commit cffc508

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

src/init.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ JL_DLLEXPORT void *jl_libjulia_internal_handle;
383383
JL_DLLEXPORT void *jl_libjulia_handle;
384384
JL_DLLEXPORT void *jl_RTLD_DEFAULT_handle;
385385
JL_DLLEXPORT void *jl_exe_handle;
386+
JL_DLLEXPORT void *jl_image_handle = NULL;
386387
#ifdef _OS_WINDOWS_
387388
void *jl_ntdll_handle;
388389
void *jl_kernel32_handle;
@@ -872,11 +873,12 @@ static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_
872873

873874
// loads sysimg if available, and conditionally sets jl_options.cpu_target
874875
jl_image_buf_t sysimage = { JL_IMAGE_KIND_NONE };
875-
if (rel == JL_IMAGE_IN_MEMORY) {
876+
if (jl_image_handle) {
877+
sysimage = jl_set_sysimg_so(jl_image_handle);
878+
} else if (rel == JL_IMAGE_IN_MEMORY) {
876879
sysimage = jl_set_sysimg_so(jl_exe_handle);
877880
jl_options.image_file = jl_options.julia_bin;
878-
}
879-
else if (jl_options.image_file)
881+
} else if (jl_options.image_file)
880882
sysimage = jl_preload_sysimg(jl_options.image_file);
881883

882884
if (sysimage.kind == JL_IMAGE_KIND_SO)

src/julia_internal.h

+1
Original file line numberDiff line numberDiff line change
@@ -1592,6 +1592,7 @@ JL_DLLEXPORT uint64_t jl_rand(void) JL_NOTSAFEPOINT;
15921592
JL_DLLEXPORT void jl_srand(uint64_t) JL_NOTSAFEPOINT;
15931593
JL_DLLEXPORT void jl_init_rand(void);
15941594

1595+
JL_DLLEXPORT extern void *jl_image_handle;
15951596
JL_DLLEXPORT extern void *jl_exe_handle;
15961597
JL_DLLEXPORT extern void *jl_libjulia_handle;
15971598
JL_DLLEXPORT extern void *jl_libjulia_internal_handle;

src/staticdata.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3736,8 +3736,9 @@ JL_DLLEXPORT jl_image_buf_t jl_set_sysimg_so(void *handle)
37363736
{
37373737
if (jl_sysimage_buf.kind != JL_IMAGE_KIND_NONE)
37383738
return jl_sysimage_buf;
3739-
37403739
jl_sysimage_buf = get_image_buf(handle, /* is_pkgimage */ 0);
3740+
if (jl_image_handle == NULL)
3741+
jl_image_handle = handle;
37413742
return jl_sysimage_buf;
37423743
}
37433744

src/threading.c

+1
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ JL_DLLEXPORT jl_gcframe_t **jl_autoinit_and_adopt_thread(void)
456456
if (!jl_is_initialized()) {
457457
void *retaddr = __builtin_extract_return_addr(__builtin_return_address(0));
458458
void *handle = jl_find_dynamic_library_by_addr(retaddr, 0);
459+
jl_image_handle = handle;
459460
if (handle == NULL) {
460461
fprintf(stderr, "error: runtime auto-initialization failed due to bad sysimage lookup\n"
461462
" (this should not happen, please file a bug report)\n");

0 commit comments

Comments
 (0)