Skip to content

Commit 7890d06

Browse files
vchuravyvtjnash
authored andcommitted
Prevent tainting native code loading from propagating (JuliaLang#53457)
When we use options like code coverage, we can't use the native code present in the cache file since it is not instrumented. PR JuliaLang#52123 introduced the capability of skipping the native code during loading, but created the issue that subsequent packages could have an explicit or implicit dependency on the native code. PR JuliaLang#53439 tainted the current process by setting `use_sysimage_native_code`, but this flag is propagated to subprocesses and lead to a regression in test time. Move this to a process local flag to avoid the regression. In the future we might be able to change the calling convention for cross-image calls to `invoke(ci::CodeInstance, args...)` instead of `ci.fptr(args...)` to handle native code not being present. --------- Co-authored-by: Jameson Nash <[email protected]>
1 parent ef70cf3 commit 7890d06

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/staticdata.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -3066,6 +3066,11 @@ JL_DLLEXPORT void jl_set_sysimg_so(void *handle)
30663066
extern void rebuild_image_blob_tree(void);
30673067
extern void export_jl_small_typeof(void);
30683068

3069+
// When an image is loaded with ignore_native, all subsequent image loads must ignore
3070+
// native code in the cache-file since we can't gurantuee that there are no call edges
3071+
// into the native code of the image. See https://github.com/JuliaLang/julia/pull/52123#issuecomment-1959965395.
3072+
int IMAGE_NATIVE_CODE_TAINTED = 0;
3073+
30693074
static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl_array_t *depmods, uint64_t checksum,
30703075
/* outputs */ jl_array_t **restored, jl_array_t **init_order,
30713076
jl_array_t **extext_methods, jl_array_t **internal_methods,
@@ -3092,9 +3097,10 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
30923097

30933098
// in --build mode only use sysimg data, not precompiled native code
30943099
int imaging_mode = jl_generating_output() && !jl_options.incremental;
3095-
if (imaging_mode || jl_options.use_sysimage_native_code != JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_YES) {
3100+
if (imaging_mode || jl_options.use_sysimage_native_code != JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_YES || IMAGE_NATIVE_CODE_TAINTED) {
30963101
memset(&image->fptrs, 0, sizeof(image->fptrs));
30973102
image->gvars_base = NULL;
3103+
IMAGE_NATIVE_CODE_TAINTED = 1;
30983104
}
30993105

31003106
// step 1: read section map
@@ -3772,7 +3778,7 @@ JL_DLLEXPORT jl_value_t *jl_restore_package_image_from_file(const char *fname, j
37723778
// Must disable using native code in possible downstream users of this code:
37733779
// https://github.com/JuliaLang/julia/pull/52123#issuecomment-1959965395.
37743780
// The easiest way to do that is to disable it in all of them.
3775-
jl_options.use_sysimage_native_code = JL_OPTIONS_USE_SYSIMAGE_NATIVE_CODE_NO;
3781+
IMAGE_NATIVE_CODE_TAINTED = 1;
37763782
}
37773783

37783784
jl_value_t* mod = jl_restore_incremental_from_buf(pkgimg_handle, pkgimg_data, &pkgimage, *plen, depmods, completeinfo, pkgname, 0);

0 commit comments

Comments
 (0)