Skip to content

Stack trace not printed when panicking in imported function #16975

@ghost

Description

Zig Version

0.12.0-dev.168+a31748b29

Steps to Reproduce and Observed Behavior

exe.zig

extern fn panic() void;

pub fn main() void {
    panic();
}

lib.zig

export fn panic() void {
    @panic("panic");
}

build.zig

const std = @import("std");

pub fn build(b: *std.Build) !void {
    const target = b.standardTargetOptions(.{});
    const optimize = b.standardOptimizeOption(.{});

    const lib = b.addStaticLibrary(.{
        .name = "lib",
        .root_source_file = .{ .path = "lib.zig" },
        .target = target,
        .optimize = optimize,
    });

    const exe = b.addExecutable(.{
        .name = "exe",
        .root_source_file = .{ .path = "exe.zig" },
        .target = target,
        .optimize = optimize,
    });

    exe.linkLibrary(lib);

    b.installArtifact(exe);

    const run_cmd = b.addRunArtifact(exe);
    run_cmd.step.dependOn(b.getInstallStep());
    const run_step = b.step("run", "Run");
    run_step.dependOn(&run_cmd.step);
}
$ zig build run
steps [2/6] zig build-exe exe Debug native... LLVM Emit Object... thread 143239 panic: panic
Panicked during a panic. Aborting.

Expected Behavior

$ zig build run
steps [2/6] zig build-exe exe Debug native... LLVM Emit Object... thread 142400 panic: panic
lib.zig:2:5: 0x21ea65 in main (exe)
    @panic("panic");
    ^

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions