Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiler assertion with x86_64 native backend #22974

Closed
actondev opened this issue Feb 22, 2025 · 2 comments · Fixed by #22976
Closed

compiler assertion with x86_64 native backend #22974

actondev opened this issue Feb 22, 2025 · 2 comments · Fixed by #22976
Labels
arch-x86_64 64-bit x86 backend-self-hosted bug Observed behavior contradicts documented or intended behavior linking
Milestone

Comments

@actondev
Copy link

Zig Version

0.14.0-dev.3299+31f353cd9

Steps to Reproduce and Observed Behavior

I've been trying lately to see if I can use the native backend in my application, but it keeps crashing.

        const exe = b.addExecutable(.{
            ...
            .use_llvm = optimize != .Debug,
            .use_lld = optimize != .Debug,
});

By compiling latest master, This is what I get.

error: thread 106850 panic: reached unreachable code
/home/actondev/dev/cloned/zig/lib/std/debug.zig:518:14: 0x19327fd in assert (zig)
    if (!ok) unreachable; // assertion failure
             ^
/home/actondev/dev/cloned/zig/src/Value.zig:135:11: 0x1b56d0e in fromInterned (zig)
    assert(i != .none);
          ^
/home/actondev/dev/cloned/zig/src/link/Dwarf.zig:3860:66: 0x2835e05 in updateLazyValue (zig)
                    try wip_nav.blockValue(src_loc, .fromInterned(opt.val));
                                                                 ^
/home/actondev/dev/cloned/zig/src/link/Dwarf.zig:2059:54: 0x23b28dd in updateLazy (zig)
            else => try wip_nav.dwarf.updateLazyValue(wip_nav.pt, src_loc, val, &wip_nav.pending_lazy),
                                                     ^
/home/actondev/dev/cloned/zig/src/link/Dwarf.zig:3124:27: 0x2ccf335 in updateComptimeNavInner (zig)
    try wip_nav.updateLazy(nav_src_loc);
                          ^
/home/actondev/dev/cloned/zig/src/link/Dwarf.zig:2683:34: 0x2797576 in updateComptimeNav (zig)
    return updateComptimeNavInner(dwarf, pt, nav_index) catch |err| switch (err) {
                                 ^
/home/actondev/dev/cloned/zig/src/link/Elf/ZigObject.zig:1601:64: 0x235110c in updateNav (zig)
    } else if (self.dwarf) |*dwarf| try dwarf.updateComptimeNav(pt, nav_index);
                                                               ^
/home/actondev/dev/cloned/zig/src/link/Elf.zig:2382:43: 0x1f47bee in updateNav (zig)
    return self.zigObjectPtr().?.updateNav(self, pt, nav);
                                          ^
/home/actondev/dev/cloned/zig/src/link.zig:706:81: 0x1cf7ae0 in updateNav (zig)
                return @as(*tag.Type(), @fieldParentPtr("base", base)).updateNav(pt, nav_index);
                                                                                ^
/home/actondev/dev/cloned/zig/src/Zcu/PerThread.zig:3128:21: 0x1b54bba in linkerUpdateNav (zig)
        lf.updateNav(pt, nav_index) catch |err| switch (err) {
                    ^
/home/actondev/dev/cloned/zig/src/link.zig:1566:35: 0x22d036d in doTask (zig)
                pt.linkerUpdateNav(nav_index) catch |err| switch (err) {
                                  ^
/home/actondev/dev/cloned/zig/src/link.zig:1384:34: 0x1ef7da2 in flushTaskQueue (zig)
        for (tasks) |task| doTask(comp, tid, task);
                                 ^
/home/actondev/dev/cloned/zig/lib/std/Thread/Pool.zig:182:50: 0x1ef7fb9 in runFn (zig)
            @call(.auto, func, .{id.?} ++ closure.arguments);
                                                 ^
/home/actondev/dev/cloned/zig/lib/std/Thread/Pool.zig:295:32: 0x1ea75a4 in worker (zig)
            run_node.data.runFn(&run_node.data, id);
                               ^
/home/actondev/dev/cloned/zig/lib/std/Thread.zig:488:13: 0x1c88dba in callFn__anon_171278 (zig)
            @call(.auto, f, args);
            ^
/home/actondev/dev/cloned/zig/lib/std/Thread.zig:757:30: 0x1b0b634 in entryFn (zig)
                return callFn(f, args_ptr.*);
                             ^
???:?:?: 0x73f6c56a3709 in ??? (libc.so.6)
Unwind information for `libc.so.6:0x73f6c56a3709` was not available, trace may be incomplete

I'm linking with c & c++ libraries FYI. I don't have my application open source anywhere. Let me know if I can help debugging this some way.

Expected Behavior

Compilation should work

@actondev actondev added the bug Observed behavior contradicts documented or intended behavior label Feb 22, 2025
@actondev actondev changed the title compiler assertion with x86 native backend compiler assertion with x86_64 native backend Feb 22, 2025
@mlugg
Copy link
Member

mlugg commented Feb 22, 2025

cc @jacobly0 -- normally I'd close this as an incomplete repro, but the logic on Dwarf.zig:3860 does look obviously wrong to me?

@mlugg mlugg added this to the 0.14.0 milestone Feb 22, 2025
@actondev
Copy link
Author

@mlugg managed to figure out a reproduction

// foo.zig
const Cb = fn (x: anytype) anyerror!void;

const Opts = struct {
    cb: ?*const Cb = null,
};
pub fn Foo(comptime opts: Opts) type {
    return struct {
        const opts_ = opts;
    };
}

test "foo" {
    const FooT = Foo(.{});
    _ = FooT;
}

zig test foo.zig -fno-llvm -fno-lld

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x86_64 64-bit x86 backend-self-hosted bug Observed behavior contradicts documented or intended behavior linking
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants