From 431b6ba65c12c5b7c23376f91a46ae5db795d27d Mon Sep 17 00:00:00 2001 From: Petr Vana Date: Sun, 7 Aug 2022 14:23:29 +0200 Subject: [PATCH] Initialize name generator to provide unique names while building a chained system image --- src/codegen-stubs.c | 1 + src/codegen.cpp | 5 +++++ src/init.c | 7 +++++++ src/jl_exported_funcs.inc | 1 + src/julia_internal.h | 1 + 5 files changed, 15 insertions(+) diff --git a/src/codegen-stubs.c b/src/codegen-stubs.c index 0e837095e0891..f1a8c58f8bff6 100644 --- a/src/codegen-stubs.c +++ b/src/codegen-stubs.c @@ -25,6 +25,7 @@ JL_DLLEXPORT void *jl_LLVMCreateDisasm_fallback(const char *TripleName, void *Di JL_DLLEXPORT size_t jl_LLVMDisasmInstruction_fallback(void *DC, uint8_t *Bytes, uint64_t BytesSize, uint64_t PC, char *OutString, size_t OutStringSize) UNAVAILABLE JL_DLLEXPORT void jl_init_codegen_fallback(void) { } +JL_DLLEXPORT void jl_init_codegen_name_generator_fallback(int init_value) { } JL_DLLEXPORT int jl_getFunctionInfo_fallback(jl_frame_t **frames, uintptr_t pointer, int skipC, int noInline) { diff --git a/src/codegen.cpp b/src/codegen.cpp index 848e448c2f9cf..3a9f16a25cacf 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -8661,6 +8661,11 @@ extern "C" JL_DLLEXPORT void jl_init_codegen_impl(void) init_jit_functions(); } +extern "C" JL_DLLEXPORT void jl_init_codegen_name_generator_impl(int init_value) +{ + globalUniqueGeneratedNames.store(init_value); +} + extern "C" JL_DLLEXPORT void jl_teardown_codegen_impl() { // output LLVM timings and statistics diff --git a/src/init.c b/src/init.c index a5632fc66a45a..232fa5a818d55 100644 --- a/src/init.c +++ b/src/init.c @@ -797,6 +797,13 @@ static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_ if (jl_options.handle_signals == JL_OPTIONS_HANDLE_SIGNALS_ON) jl_install_sigint_handler(); + + if (jl_options.image_file) { + // TODO: set the number of existing symbols more precisely + // This is probably important to do at the end because some symbols + // depend on the specific order of its initialization. + jl_init_codegen_name_generator(80000); + } } static jl_value_t *core(const char *name) diff --git a/src/jl_exported_funcs.inc b/src/jl_exported_funcs.inc index d82c33da0c5cb..c7361225c6578 100644 --- a/src/jl_exported_funcs.inc +++ b/src/jl_exported_funcs.inc @@ -538,6 +538,7 @@ YY(jl_LLVMCreateDisasm) \ YY(jl_LLVMDisasmInstruction) \ YY(jl_init_codegen) \ + YY(jl_init_codegen_name_generator) \ YY(jl_getFunctionInfo) \ YY(jl_register_fptrs) \ YY(jl_generate_fptr) \ diff --git a/src/julia_internal.h b/src/julia_internal.h index 72b2208abd761..6055752e30988 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -760,6 +760,7 @@ void jl_init_common_symbols(void); void jl_init_primitives(void) JL_GC_DISABLED; void jl_init_llvm(void); void jl_init_codegen(void); +void jl_init_codegen_name_generator(int); void jl_init_runtime_ccall(void); void jl_init_intrinsic_functions(void); void jl_init_intrinsic_properties(void);