Segmentation fault when trying to make a custom sysimage

signal (11): Segmentation fault
in expression starting at none:0
uv_write2 at /workspace/srcdir/libuv/src/unix/stream.c:1397
uv_write at /workspace/srcdir/libuv/src/unix/stream.c:1492
jl_uv_write at /buildworker/worker/package_linux64/build/src/jl_uv.c:463
uv_write_async at ./stream.jl:965
uv_write at ./stream.jl:922
unsafe_write at ./stream.jl:1005
write at ./strings/io.jl:183 [inlined]
print at ./strings/io.jl:185 [inlined]
#with_output_color#745 at ./util.jl:76
unknown function (ip: 0x7f14ba987328)
with_output_color##kw at ./util.jl:70 [inlined]
#printstyled#746 at ./util.jl:104 [inlined]
printstyled##kw at ./util.jl:104
unknown function (ip: 0x7f14ba986d07)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2231 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
display_error at ./client.jl:102
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2231 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
display_error at ./client.jl:106
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2231 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1691 [inlined]
do_apply at /buildworker/worker/package_linux64/build/src/builtins.c:674
jl_f__apply_latest at /buildworker/worker/package_linux64/build/src/builtins.c:724
#invokelatest#1 at ./essentials.jl:710 [inlined]
invokelatest at ./essentials.jl:709 [inlined]
exec_options at ./client.jl:298
_start at ./client.jl:506
unknown function (ip: 0x7f14bb0487ab)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2231 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2398
unknown function (ip: 0x401931)
unknown function (ip: 0x401533)
__libc_start_main at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x4015d4)
Allocations: 852167 (Pool: 851690; Big: 477); GC: 1
./myappgcc.sh: line 2: 23268 Segmentation fault      (core dumped) julia --startup-file=no -J"/home/westly/julia/lib/julia/sys.so" --output-o sys.o custom_sysimage.jl

Hi @sonicrules1234 and welcome to the julia discourse! From the stacktrace you posted it’s not possible to say why you’re getting a segmentation fault. Please see Please read: make it easier to help you, for some tips on how to add more information to your post so we can help you track down your problem.

Without knowing more, one question I have is, are you able to run the examples in the PackageCompiler documentation? I’m asking because I’m wondering if your problem is just with the specific sysimage you’re trying to build, or if you’re having trouble getting PackageCompiler to run at all. Also, which platform are you on (e.g. Linux, Windows)?

1 Like

greet.jl

module greetings
export greet
function greet(greeting::String)
    if greeting == "hello" || greeting == "Hello"
        returnmsg = "Good morning"
    elseif greeting == "goodbye"
        returnmsg = "Good night."
    else 
        returnmsg = "What's up"
    end
    return returnmsg
end
end

MyApp.jl

module MyApp
include("greet.jl")

Base.@ccallable function julia_main()::Cint
    try
        real_main()
    catch
        Base.invokelatest(Base.display_error, Base.catch_stack())
        return 1
    end
    return 0
end

function real_main()
    println("Input greeting:")
    greeting = readline()
    println(greetings.greet(greeting))
    return 0
end
if abspath(PROGRAM_FILE) == @__FILE__
    real_main()
end
end # module

custom_sysimg.jl

Base.init_depot_path()
Base.init_load_path()

@eval Module() begin
    Base.include(@__MODULE__, "MyApp.jl")
    for (pkgid, mod) in Base.loaded_modules
        if !(pkgid.name in ("Main", "Core", "Base"))
            eval(@__MODULE__, :(const $(Symbol(mod)) = $mod))
        end
    end
    for statement in readlines("app_precompile.jl")
        try
            Base.include_string(@__MODULE__, statement)
        catch
            # See julia issue #28808
            Core.println("failed to compile statement: ", statement)
        end
    end
end # module

empty!(LOAD_PATH)
empty!(DEPOT_PATH)

I ran

julia --project --startup-file=no --trace-compile=app_precompile.jl MyApp.jl

and then

julia --startup-file=no -J"/home/westly/julia/lib/julia/sys.so" --output-o sys.o custom_sysimage.jl

and it gave me that error.

Edit:
Just tried the CSV example in the PackageCompiler documentation, and that also gave me a segfault.

Ok. I see you’re trying to manually create a custom sysimage without using PackageCompiler. Are doing this in order to understand how sysimage/app creation works under the hood or do you just want to make a relocatable app? If it’s the latter then I would highly recommend using PackageCompiler. See the Creating an app doc section for full instructions. Basically, you can keep your greet.jl function as is and simplify MyApp.jl to

module MyApp
include("greet.jl")
function julia_main()::Cint
    println("Input greeting:")
    greeting = readline()
    println(greetings.greet(greeting))
    return 0
end
end

then create a julia package from these files. The custom_sysimg.jl is not needed at all. Once you have your functionality in a package, you just use PackageCompiler’s create_app function to build your app. I haven’t actually run this with your particular code, but that’s the idea. Also, as mentioned in the docs, there’s a template app available on GitHub that you can use as a starting point.

Unfortunately I’m not sure why you’re getting the segfault you’re getting. I tried the CSV example in the PackageCompiler developer docs and it segfaulted for me as well. It may be worth filing an issue at the PackageCompiler repo. I haven’t had time to properly dig into it and see if there’s a simple fix. But again, this is only relevant to understanding what’s happening under the hood. Normally you should just use PackageCompiler’s nice API and not worry about these details.

1 Like

I was trying to just compile it. I didn’t see the create_app part of the docs. I got it to compile now. Thanks.