Skip to content

Getting the GC to work #81

@gbaraldi

Description

@gbaraldi

So currently we aren't able to do GC allocations outside of compile which requires a running julia session. Ideally we should be able to link a binary to libjulia or some version of it, instead of having the whole runtime i.e PackageCompiler.
As a hack me and @brenhinkeller managed to link to it and call jl_init, and when calling some functions from the runtime we fail with some stacktraces deep in libjulia which is promising.

Together with JuliaGPU/GPUCompiler.jl#348, the code actually gets into the GC functions and somewhere inside it finally segfaults.

Some of these segfaults are because some global variables like types get initialized as null, and when the sysimg is being processed their actual values are substituted in. In GPUCompiler that doesn't happen so we gt IR with null where it shouldn't be a null.

 %2 = load atomic {}* ({}*, i64)*, {}* ({}*, i64)** bitcast (void ()** @jlplt_ijl_alloc_array_1d_11819_got to {}* ({}*, i64)**) unordered, align 8
  %3 = call nonnull {}* %2({}* null, i64 5)

That leads to a segfault, we need to find a way to turn that null into a pointer to the correct jl_value_t, which should be Array(Int64,1}

The IR before removing the globals looks like:

@"+Core.Array5" = internal global {}* null, !julia.constgv !0

...

 %2 = load {}*, {}** @"+Core.Array5", align 8, !dbg !52, !tbaa !41, !nonnull !0, !dereferenceable !45, !align !47
  %3 = load atomic {}* ({}*, i64)*, {}* ({}*, i64)** bitcast (void ()** @jlplt_ijl_alloc_array_1d_1764_got to {}* ({}*, i64)**) unordered, align 8, !dbg !52
  %4 = call nonnull {}* %3({}* %2, i64 5), !dbg !52

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions