Skip to content

Impossible to reinitialize codegen subsystem in julia #59536

@redeemed-sis

Description

@redeemed-sis

I work with embedded julia (I don't use julia interpreter, I use libjulia-* libraries directly) and due to certain problems (forced termination of the adopted thread (it makes with help of jl_adopt_thread() API, which executes julia code)

JL_DLLEXPORT jl_gcframe_t **jl_adopt_thread(void)

It became necessary to reinitialize the code generation subsystem (calling jl_teardown_codegen() and jl_init_codegen()), since julia remained in an incorrect state when the thread was terminated (locks in the code generation subsystem were not released). However, the reinitialization fails due to the "Library already loaded" error in the sys::DynamicLibrary::addPermanentLibrary (

julia/src/jitlayers.cpp

Lines 1945 to 1948 in 7de5585

sys::DynamicLibrary libjulia_internal_dylib = sys::DynamicLibrary::addPermanentLibrary(
jl_libjulia_internal_handle, &ErrorStr);
if(!ErrorStr.empty())
report_fatal_error(llvm::Twine("FATAL: unable to dlopen libjulia-internal\n") + ErrorStr);
), when trying to download libjulia-internal (obviously, because it has already been loaded before) and as a result, abortion is called. Ignoring this error completely solves this problem. The documentation for the addPermanentLibrary function says that it can be safely called many times for the same library.

My suggestion is to ignore this error on initialization step:

sys::DynamicLibrary libjulia_internal_dylib = sys::DynamicLibrary::addPermanentLibrary(
  jl_libjulia_internal_handle, &ErrorStr);
if(!ErrorStr.empty())
    if (ErrorStr != "Library already loaded")
        report_fatal_error(llvm::Twine("FATAL: unable to dlopen libjulia-internal\n") + ErrorStr);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions