# Segmentation fault in executable after compilation with juliac including --trim --experimental arguments

**URL:** https://discourse.julialang.org/t/segmentation-fault-in-executable-after-compilation-with-juliac-including-trim-experimental-arguments/125303
**Category:** General Usage
**Tags:** compilation, juliac
**Created:** [January 28, 2025, 2:49pm UTC](https://discourse.julialang.org/t/segmentation-fault-in-executable-after-compilation-with-juliac-including-trim-experimental-arguments/125303 "2025-01-28T14:49:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![borisjo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/borisjo/32/214188_2.png) [@borisjo](https://discourse.julialang.org/u/borisjo)
#### Post date: [January 28, 2025, 2:49pm UTC](https://discourse.julialang.org/t/segmentation-fault-in-executable-after-compilation-with-juliac-including-trim-experimental-arguments/125303/1 "2025-01-28T14:49:18Z")

</div>

I’m trying out the juliac compilation functionality and I’m getting segmentation faults in my executable.

My code I try to compile:

```julia
module ABCD

Base.@ccallable function main()::Cint
    return 0
end

end # Module ABCD

```

I then try to compile using the following command:

> julia +nightly juliac.jl --output-exe try --trim --experimental tryJuliaC.jl

Firstly, I already get a warning using the latest nightly julia version:

```julia
WARNING: Detected access to binding `ABCD.main` in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.

```

But the executable is still created, when trying to execute it with `./try`, I’m getting the following output:

```julia
[12211] signal 11 (1): Segmentation fault
in expression starting at none:0
jl_symbol_name_ at /cache/build/tester-amdci5-9/julialang/julia-master/src/julia.h:1429 [inlined]
jl_generate_ccallable at /cache/build/tester-amdci5-9/julialang/julia-master/src/codegen.cpp:8053
jl_compile_extern_c_impl at /cache/build/tester-amdci5-9/julialang/julia-master/src/jitlayers.cpp:810
jl_compile_extern at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:2475 [inlined]
jl_reinit_ccallable at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:2487 [inlined]
jl_restore_system_image_from_stream_ at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:3981
jl_restore_system_image_from_stream at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:4154 [inlined]
ijl_restore_system_image_data at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:4219
jl_load_sysimg_so at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:663 [inlined]
ijl_restore_system_image at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:4190
_finish_julia_init at /cache/build/tester-amdci5-9/julialang/julia-master/src/init.c:884
julia_init at /cache/build/tester-amdci5-9/julialang/julia-master/src/init.c:864
static_init at /tmp/jl_lCDPQt/init.c:5
__libc_csu_init at ./try (unknown line)
__libc_start_main at /lib64/libc.so.6 (unknown line)
_start at ./try (unknown line)
Allocations: 0 (Pool: 0; Big: 0); GC: 0

[12211] signal 11 (1): Segmentation fault
in expression starting at none:0
jl_symbol_name_ at /cache/build/tester-amdci5-9/julialang/julia-master/src/julia.h:1429 [inlined]
jl_generate_ccallable at /cache/build/tester-amdci5-9/julialang/julia-master/src/codegen.cpp:8053
jl_compile_extern_c_impl at /cache/build/tester-amdci5-9/julialang/julia-master/src/jitlayers.cpp:810
jl_compile_extern at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:2475 [inlined]
jl_reinit_ccallable at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:2487 [inlined]
jl_restore_system_image_from_stream_ at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:3981
jl_restore_system_image_from_stream at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:4154 [inlined]
ijl_restore_system_image_data at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:4219
jl_load_sysimg_so at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:663 [inlined]
ijl_restore_system_image at /cache/build/tester-amdci5-9/julialang/julia-master/src/staticdata.c:4190
_finish_julia_init at /cache/build/tester-amdci5-9/julialang/julia-master/src/init.c:884
julia_init at /cache/build/tester-amdci5-9/julialang/julia-master/src/init.c:864
static_init at /tmp/jl_lCDPQt/init.c:5
__libc_csu_init at ./try (unknown line)
__libc_start_main at /lib64/libc.so.6 (unknown line)
_start at ./try (unknown line)
Allocations: 0 (Pool: 0; Big: 0); GC: 0
Segmentation fault (core dumped)

```

Interestingly, if I compile without `--trim --experimental` I still get the warning, but I do not get the segmentation faults anymore.  
Does anyone have an idea on how to solve this?

---

<div class="post-metadata">

### Author: ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)
#### Post date: [January 28, 2025, 3:08pm UTC](https://discourse.julialang.org/t/segmentation-fault-in-executable-after-compilation-with-juliac-including-trim-experimental-arguments/125303/2 "2025-01-28T15:08:34Z")

</div>

Welcome! I highly suspect this is a recent regression in the nightlies — two new experimental features are colliding here. I would wager that trimming doesn’t know about binding partitions yet.

This is worth submitting as [an issue on GitHub](https://github.com/JuliaLang/julia/issues/new/choose) — I haven’t seen it reported yet.

In the meantime, you could try a slightly older nightly; I happen to have one that’s 54 days old and works as you expected.

---

<div class="post-metadata">

### Author: ![asprionj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asprionj/32/6856_2.png) [@asprionj](https://discourse.julialang.org/u/asprionj)
#### Post date: [August 18, 2025, 9:23am UTC](https://discourse.julialang.org/t/segmentation-fault-in-executable-after-compilation-with-juliac-including-trim-experimental-arguments/125303/3 "2025-08-18T09:23:42Z")

</div>

Has an Issue been opened for this?

---

<div class="post-metadata">

### Author: ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)
#### Post date: [August 18, 2025, 3:08pm UTC](https://discourse.julialang.org/t/segmentation-fault-in-executable-after-compilation-with-juliac-including-trim-experimental-arguments/125303/4 "2025-08-18T15:08:29Z")

</div>

This example works with a little bit change:

```julia
module ABCD

function (@main)(args::Vector{String})::Cint
    return 0
end

end # Module ABCD

import .ABCD.main

```

The main function should be imported outside of the module.

The modified Makefile and the `abcd.jl` example is updated in my `juliac` repo:

> **[GitHub - jbytecode/juliac: Examples for Julia's generating small binary...](https://github.com/jbytecode/juliac)**
>
> Examples for Julia's generating small binary executables and libraries feature.

It can be tested using

```shell
# make abcd

```

and it can be run using

```shell
# ./abcd

```

---

<div class="post-metadata">

### Author: ![asprionj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asprionj/32/6856_2.png) [@asprionj](https://discourse.julialang.org/u/asprionj)
#### Post date: [August 18, 2025, 9:10pm UTC](https://discourse.julialang.org/t/segmentation-fault-in-executable-after-compilation-with-juliac-including-trim-experimental-arguments/125303/5 "2025-08-18T21:10:39Z")

</div>

Does this workaround also hold for when other packages are used (`using` or `importing` them)? See my description here: [Creating fully self-contained and pre-compiled library - #14 by asprionj](https://discourse.julialang.org/t/creating-fully-self-contained-and-pre-compiled-library/131374/14).

Would these be added inside the `Module`, I assume? And also added to an environment of which the path to `Project.toml` would be specified to the `julia --project=<path> juliac.jl ...` call?
