Skip to content

Compiler segfaults instead of printing an error #24155

Open
@Jarred-Sumner

Description

@Jarred-Sumner

Zig Version

0.14.1

Steps to Reproduce and Observed Behavior

  1. git init bun-temp && cd bun-temp && git remote add origin https://github.com/oven-sh/bun.git && git fetch origin 8f0d75f00a6889adcf4d1fdb522b81b694b02889 --depth 1 && git checkout 8f0d75f00a6889adcf4d1fdb522b81b694b02889
  2. bun run build
error: the following command terminated unexpectedly:
<path-to-zig>/zig build-obj -freference-trace=16 -fllvm -fno-lld -fno-strip -fno-omit-frame-pointer -fsanitize-address -fPIC -ODebug -target aarch64-macos.13.0-none -mcpu apple_m1 --dep bun -Mroot=<bun-folder>/src/main.zig --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -Mbun=<bun-folder>/src/bun.zig --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -Mbuild_options=<cache>/zig/local/c/2ce8a8d113a0d4a9e2856aac727a86c7/options.zig --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -Mtranslated-c-headers=<cache>/zig/local/o/24a6e346caf804a6157e36c5c0630ba8/c-headers-for-zig.zig --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -Mzlib-internal=<bun-folder>/src/deps/zlib.posix.zig --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -Masync=<bun-folder>/src/async/posix_event_loop.zig --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -MZigGeneratedClasses=<build-folder>/codegen/ZigGeneratedClasses.zig --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -MResolvedSourceTag=<build-folder>/codegen/ResolvedSourceTag.zig --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -MErrorCode=<build-folder>/codegen/ErrorCode.zig --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -Mcompletions-bash=<bun-folder>/completions/bun.bash --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -Mcompletions-zsh=<bun-folder>/completions/bun.zsh --dep bun --dep build_options --dep translated-c-headers --dep zlib-internal --dep async --dep ZigGeneratedClasses --dep ResolvedSourceTag --dep ErrorCode --dep completions-bash --dep completions-zsh --dep completions-fish -Mcompletions-fish=<bun-folder>/completions/bun.fish -lc++ -lc --cache-dir <cache>/zig/local --global-cache-dir <cache>/zig/global --name bun-debug -fno-compiler-rt -fno-ubsan-rt --zig-lib-dir /<path-to-zig>/lib/ --listen=-
Build Summary: 2/5 steps succeeded; 1 failed
obj transitive failure
├─ zig build-obj bun-debug Debug aarch64-macos.13.0-none failure
│  ├─ options cached
│  └─ translate-c cached 34ms MaxRSS:35M
└─ install generated to bun-zig.o transitive failure
   └─ zig build-obj bun-debug Debug aarch64-macos.13.0-none (+2 more reused dependencies)
error: the following build command failed with exit code 1:
<cache>/zig/local/o/73a26231e1c9ebb645536fd66e30e934/build /<path-to-zig>/zig /<path-to-zig>/lib <bun-folder> <cache>/zig/local <cache>/zig/global --seed 0xa5421364 -Zf3a2228e956a080d obj --prefix <build-folder> -Dobj_format=obj -Dtarget=aarch64-macos-none -Doptimize=Debug -Dcpu=apple_m1 -Denable_logs=true -Denable_asan=true -Dversion=1.2.16 -Dreported_nodejs_version=22.6.0 -Dcanary=1 -Dcodegen_path=<build-folder>/codegen -Dcodegen_embed=false --prominent-compile-errors --summary all -Dsha=504f9b6c85be00427305ffa9afcc609e4ea2556b
FAILED: bun-zig.o <build-folder>/bun-zig.o
cd <bun-folder> && /<path-to-zig>/zig build obj --cache-dir <cache>/zig/local --global-cache-dir <cache>/zig/global --zig-lib-dir /<path-to-zig>/lib --prefix <build-folder> -Dobj_format=obj -Dtarget=aarch64-macos-none -Doptimize=Debug -Dcpu=apple_m1 -Denable_logs=true -Denable_asan=true -Dversion=1.2.16 -Dreported_nodejs_version=22.6.0 -Dcanary=1 -Dcodegen_path=<build-folder>/codegen -Dcodegen_embed=false --prominent-compile-errors --summary all -Dsha=504f9b6c85be00427305ffa9afcc609e4ea2556b
ninja: build stopped: subcommand failed.
  cmake took 0.53 seconds
  Command exited: code 1
error: script "build:debug" exited with code 1
error: script "build" exited with code 1

If you run the printed build-obj command with a debug build of Zig it should produce a more useful stack trace. I suggest running bun run build once to get the codegen scripts and everything into a state where it can build, then copy-pasting the command on your local machine replacing the path that contains vendor/zig to your debug build of Zig. Or you could symlink vendor/zig to your local zig folder.

Here's what lldb reports:

* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x52963389c)
    frame #0: 0x0000000104de2d3c zig`codegen.llvm.Object.lowerDebugType + 9696
zig`codegen.llvm.Object.lowerDebugType:
->  0x104de2d3c <+9696>: ldr    w20, [x8, w24, uxtw #2]
    0x104de2d40 <+9700>: str    w20, [sp, #0x9e0]
    0x104de2d44 <+9704>: add    x0, sp, #0xd10
    0x104de2d48 <+9708>: mov    x1, x20
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x52963389c)
  * frame #0: 0x0000000104de2d3c zig`codegen.llvm.Object.lowerDebugType + 9696
    frame #1: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #2: 0x0000000104de3fbc zig`codegen.llvm.Object.lowerDebugType + 14432
    frame #3: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #4: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #5: 0x0000000104de3fbc zig`codegen.llvm.Object.lowerDebugType + 14432
    frame #6: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #7: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #8: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #9: 0x0000000104de3fbc zig`codegen.llvm.Object.lowerDebugType + 14432
    frame #10: 0x0000000104de358c zig`codegen.llvm.Object.lowerDebugType + 11824
    frame #11: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #12: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #13: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #14: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #15: 0x0000000104de3fbc zig`codegen.llvm.Object.lowerDebugType + 14432
    frame #16: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #17: 0x0000000104de3fbc zig`codegen.llvm.Object.lowerDebugType + 14432
    frame #18: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #19: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #20: 0x0000000104de204c zig`codegen.llvm.Object.lowerDebugType + 6384
    frame #21: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #22: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #23: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #24: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #25: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #26: 0x0000000104de3fbc zig`codegen.llvm.Object.lowerDebugType + 14432
    frame #27: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #28: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #29: 0x0000000104de204c zig`codegen.llvm.Object.lowerDebugType + 6384
    frame #30: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #31: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #32: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #33: 0x0000000104de2e48 zig`codegen.llvm.Object.lowerDebugType + 9964
    frame #34: 0x0000000104de56b0 zig`codegen.llvm.Object.lowerDebugType + 20308
    frame #35: 0x0000000105339590 zig`codegen.llvm.FuncGen.genBody + 51420
    frame #36: 0x000000010532b704 zig`codegen.llvm.Object.updateFunc + 8680
    frame #37: 0x000000010509b564 zig`link.doTask + 3504
    frame #38: 0x0000000104dcf074 zig`Compilation.performAllTheWorkInner + 18724
    frame #39: 0x0000000104d1249c zig`Compilation.update + 7816
    frame #40: 0x0000000104d311b4 zig`main.updateModule + 52
    frame #41: 0x0000000104d7619c zig`main.buildOutputType + 103680
    frame #42: 0x0000000104cc95ec zig`main + 2680
    frame #43: 0x0000000188b64274 dyld`start + 2840

Expected Behavior

It should print an error explaining the mistake(s) I made in the branch instead of segfaulting before printing an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions