Compiler: process terminated unexpectedly

I was refactoring a substantial portion of the code. I don’t use watch to catch compilation errors during development - especially since I wouldn’t want to see a flood of errors while the code is still incomplete. So, after several days of work, I finally finished this part and was ready to build the project, expecting the compiler to show me any remaining errors so I could fix them.

But instead of error messages, I just got a generic failure notification for a specific build step… I spent two hours experimenting with various compiler flags, but nothing helped - there were absolutely no clues.

Then I switched to Windows and tried building there as well, only to get the same result - though this time I did get an error code: 5! Honestly, that didn’t help me pinpoint the issue at all.

Back on Linux, I tried switching from version 0.15.2 to the master branch. During the rebuild, I encountered a few errors in other modules (since I haven’t fully ported everything to the new I/O yet). However, the problematic module (the one that previously failed to compile entirely), this time, caused the compiler to hang during semantic analysis. Oddly, the file where the hang occurred hadn’t been modified in half a year and doesn’t reference any of my new code at all. It was a complete dead end.

I interrupted the build and restarted it - and got the exact same problem again:

qemu
└─ run qemu-system-x86_64
   └─ install generated to bamos.iso
      └─ run mkbootimg (bamos.iso)
         └─ install bamos.elf
            └─ compile exe bamos.elf ReleaseSafe x86_64-freestanding
               └─ compile obj bamos ReleaseSafe x86_64-freestanding failure
error: process terminated unexpectedly
failed command: /home/whkostya/.local/share/zigup/0.16.0-dev.1484+d0ba6642b/files/zig build-obj -fllvm -ofmt=elf -fno-omit-frame-pointer -fno-error-tracing -fPIC -OReleaseSafe -mcmodel kernel -target x86_64-freestanding -mcpu baseline -I /home/whkostya/assembly/bamos-zig/third-party/boot --dep dbg-info -Mroot=/home/whkostya/assembly/bamos-zig/src/kernel/main.zig -fstrip -mno-red-zone -OReleaseSafe -target x86_64-freestanding -mcpu baseline -Mdbg-info=/home/whkostya/assembly/bamos-zig/build-tools/dbg-make/dbg.zig --cache-dir .zig-cache --global-cache-dir /home/whkostya/.cache/zig --name bamos --zig-lib-dir /home/whkostya/.local/share/zigup/0.16.0-dev.1484+d0ba6642b/files/lib/ --listen=-

Build Summary: 4/16 steps succeeded (3 failed)
qemu transitive failure
└─ run qemu-system-x86_64 transitive failure
   ├─ run mkbootimg (bamos.iso) transitive failure
   │  ├─ run exe zip (mkbootimg) transitive failure
   │  │  └─ compile exe zip ReleaseFast native 1 errors
   │  ├─ compile exe bamos.elf ReleaseSafe x86_64-freestanding transitive failure
   │  │  ├─ compile obj bamos ReleaseSafe x86_64-freestanding failure
   │  │  ├─ compile obj dbg-script ReleaseSafe x86_64-freestanding transitive failure
   │  │  │  └─ run exe dbg-make (debug.sym) transitive failure
   │  │  │     ├─ compile exe dbg-make ReleaseFast native 1 errors
   │  │  │     └─ compile obj bamos ReleaseSafe x86_64-freestanding (reused)
   │  │  ├─ compile obj bamos ReleaseSafe x86_64-freestanding (reused)
   │  │  └─ compile obj dbg-script ReleaseSafe x86_64-freestanding (+1 more reused dependencies)
   │  └─ install bamos.elf transitive failure
   │     └─ compile exe bamos.elf ReleaseSafe x86_64-freestanding (+6 more reused dependencies)
   └─ install generated to bamos.iso transitive failure
      └─ run mkbootimg (bamos.iso) (+4 more reused dependencies)

error: the following build command failed with exit code 1:
.zig-cache/o/435f97f5ef3e9347a2922a94fc55fe8e/build /home/whkostya/.local/share/zigup/0.16.0-dev.1484+d0ba6642b/files/zig /home/whkostya/.local/share/zigup/0.16.0-dev.1484+d0ba6642b/files/lib /home/whkostya/assembly/bamos-zig .zig-cache /home/whkostya/.cache/zig --seed 0x67e9a2e7 -Z1a476aaf79b21061 qemu --release=safe -Dqemu-drives=nvme.img

Additional details:

  • The LLVM backend is being used (the code contains many inline assembly blocks, and the new backend produces numerous syntax errors).
  • The issue occurs regardless of build mode (ReleaseSafe, ReleaseFast, Debug).
  • The problem occurs on both Windows and Linux hosts.

If anyone has a Zig compiler built with the --debug* options enabled, please let me know. I’d really prefer not to spend time building Zig from source myself (LLVM is really huge).

It’s not that bad, I compile zig all the time. Once you have it, creating the stage4 debug build is pretty quick and is basically a super power and you should possess it.

Okay, the painless way was to install all the LLVM dependencies via the package manager (I’m using Ubuntu):

sudo apt install llvm-20-dev libclang-20-dev liblld-20-dev

Now all that’s left is to build Zig 0.15.2 in debug mode and track down the root cause of the issue.

1 Like

I got a trace:

Trace
install
└─ install generated to bamos.iso
   └─ run mkbootimg (bamos.iso)
      └─ compile exe bamos.elf Debug x86_64-freestanding
         └─ compile obj dbg-script Debug x86_64-freestanding
            └─ run exe dbg-make (debug.sym)
               └─ compile obj bamos Debug x86_64-freestanding failure
error: thread 50728 panic: reached unreachable code
/local-drive-d/zig-workspace/zig/src/InternPool.zig:3702:32: 0x2abafc4 in toInt (main.zig)
                .unresolved => unreachable,
                               ^
/local-drive-d/zig-workspace/zig/src/InternPool.zig:4140:72: 0x2419630 in next (main.zig)
                return it.struct_type.runtime_order.get(it.ip)[i].toInt();
                                                                       ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:2382:31: 0x23e1162 in lowerDebugType (main.zig)
                while (it.next()) |field_index| {
                              ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:1995:59: 0x23d81b6 in lowerDebugType (main.zig)
                const debug_elem_ty = try o.lowerDebugType(pt, Type.fromInterned(ptr_info.child));
                                                          ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:2395:45: 0x23e1805 in lowerDebugType (main.zig)
                        try o.lowerDebugType(pt, field_ty),
                                            ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:1995:59: 0x23d81b6 in lowerDebugType (main.zig)
                const debug_elem_ty = try o.lowerDebugType(pt, Type.fromInterned(ptr_info.child));
                                                          ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:2491:45: 0x23e4024 in lowerDebugType (main.zig)
                        try o.lowerDebugType(pt, Type.fromInterned(field_ty)),
                                            ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:2395:45: 0x23e1805 in lowerDebugType (main.zig)
                        try o.lowerDebugType(pt, field_ty),
                                            ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:1995:59: 0x23d81b6 in lowerDebugType (main.zig)
                const debug_elem_ty = try o.lowerDebugType(pt, Type.fromInterned(ptr_info.child));
                                                          ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:2395:45: 0x23e1805 in lowerDebugType (main.zig)
                        try o.lowerDebugType(pt, field_ty),
                                            ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:1995:59: 0x23d81b6 in lowerDebugType (main.zig)
                const debug_elem_ty = try o.lowerDebugType(pt, Type.fromInterned(ptr_info.child));
                                                          ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:2133:69: 0x23db12c in lowerDebugType (main.zig)
                    const debug_optional_type = try o.lowerDebugType(pt, child_ty);
                                                                    ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:2395:45: 0x23e1805 in lowerDebugType (main.zig)
                        try o.lowerDebugType(pt, field_ty),
                                            ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:1995:59: 0x23d81b6 in lowerDebugType (main.zig)
                const debug_elem_ty = try o.lowerDebugType(pt, Type.fromInterned(ptr_info.child));
                                                          ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:2618:84: 0x23e8420 in lowerDebugType (main.zig)
                        debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, param_ty));
                                                                                   ^
/local-drive-d/zig-workspace/zig/src/codegen/llvm.zig:1447:57: 0x29cf84e in updateFunc (main.zig)
            const debug_decl_type = try o.lowerDebugType(pt, fn_ty);
                                                        ^
/local-drive-d/zig-workspace/zig/src/Zcu/PerThread.zig:4499:35: 0x29d9223 in runCodegenInner (main.zig)
        try llvm_object.updateFunc(pt, func_index, air, &liveness);
                                  ^
/local-drive-d/zig-workspace/zig/src/Zcu/PerThread.zig:4395:46: 0x2390acd in runCodegen (main.zig)
    const success: bool = if (runCodegenInner(pt, func_index, air)) |mir| success: {
                                             ^
/local-drive-d/zig-workspace/zig/src/Compilation.zig:5094:34: 0x210bdc3 in processOneJob (main.zig)
                    pt.runCodegen(func.func, &air, shared_mir);
                                 ^
/local-drive-d/zig-workspace/zig/src/Compilation.zig:5017:30: 0x1f0baec in performAllTheWork (main.zig)
            try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job);
                             ^
/local-drive-d/zig-workspace/zig/src/Compilation.zig:3097:31: 0x1da5fd8 in update (main.zig)
    try comp.performAllTheWork(main_progress_node);
                              ^
/local-drive-d/zig-workspace/zig/src/main.zig:4149:32: 0x1c53e08 in serve (main.zig)
                try comp.update(main_progress_node);
                               ^
/local-drive-d/zig-workspace/zig/src/main.zig:3586:22: 0x1c8aef9 in buildOutputType (main.zig)
            try serve(
                     ^
/local-drive-d/zig-workspace/zig/src/main.zig:270:31: 0x1cefc98 in mainArgs (main.zig)
        return buildOutputType(gpa, arena, args, .{ .build = .Obj });
                              ^
/local-drive-d/zig-workspace/zig/src/main.zig:205:20: 0x1bd4309 in main (main.zig)
    return mainArgs(gpa, arena, args);
                   ^
/local-drive-d/zig-workspace/zig/lib/std/start.zig:627:37: 0x1bd1d01 in main (std.zig)
            const result = root.main() catch |err| {
                                    ^
../sysdeps/nptl/libc_start_call_main.h:58:16: 0x751f5a42a577 in __libc_start_call_main (../sysdeps/x86/libc-start.c)
../csu/libc-start.c:360:3: 0x751f5a42a63a in __libc_start_main_impl (../sysdeps/x86/libc-start.c)
???:?:?: 0x705a034 in ??? (???)
???:?:?: 0x0 in ??? (???)