ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
35.03k stars 2.56k forks source link

0.14.0 regression: Segmentation fault when using an invalid zig lib directory #20564

Closed gooncreeper closed 1 month ago

gooncreeper commented 4 months ago

Zig Version

0.14.0-dev.208+854e86c56

Steps to Reproduce and Observed Behavior

Run

mkdir abc
touch test.zig
zig test test.zig --zig-lib-dir abc

Result

[1]    184048 segmentation fault (core dumped)  zig test test.zig --zig-lib-dir abc

When using a compiler with safety enabled, the following assertion fails which is likely the problem

thread 185412 panic: reached unreachable code
Unwind error at address `exe:0x8d6a413` (error.MissingFDE), trace may be incomplete

/home/dev/git/gooncreeper/zig/lib/std/debug.zig:415:14: 0x8004b53 in assert ()
    if (!ok) unreachable; // assertion failure
             ^
/home/dev/git/gooncreeper/zig/src/Zcu.zig:2346:15: 0x83a7c41 in resolveBaseNode ()
        assert(file.zir_loaded);
              ^
/home/dev/git/gooncreeper/zig/src/Zcu.zig:2368:54: 0x82f1ab1 in upgrade ()
        const file, const base_node = resolveBaseNode(lazy.base_node_inst, zcu);
                                                     ^
/home/dev/git/gooncreeper/zig/src/Compilation.zig:3174:55: 0x80c0ebf in addModuleErrorMsg ()
    const err_src_loc = module_err_msg.src_loc.upgrade(mod);
                                                      ^
/home/dev/git/gooncreeper/zig/src/Compilation.zig:2980:38: 0x80c8fff in getAllErrorsAlloc ()
                try addModuleErrorMsg(zcu, &bundle, msg.*, &all_references);
                                     ^
/home/dev/git/gooncreeper/zig/src/main.zig:4407:44: 0x80cdd15 in updateModule ()
    var errors = try comp.getAllErrorsAlloc();
                                           ^
/home/dev/git/gooncreeper/zig/src/main.zig:3422:21: 0x80f7af4 in buildOutputType ()
        updateModule(comp, color, root_prog_node) catch |err| switch (err) {
                    ^
/home/dev/git/gooncreeper/zig/src/main.zig:269:31: 0x8135546 in mainArgs ()
        return buildOutputType(gpa, arena, args, .zig_test);
                              ^
/home/dev/git/gooncreeper/zig/src/main.zig:209:20: 0x8002822 in main ()
    return mainArgs(gpa, arena, args);
                   ^
/home/dev/git/gooncreeper/zig/lib/std/start.zig:515:37: 0x8000653 in posixCallMainAndExit ()
            const result = root.main() catch |err| {
                                    ^
/home/dev/git/gooncreeper/zig/lib/std/start.zig:258:5: 0x800001a in _start ()
    asm volatile (switch (native_arch) {
    ^
[1]    185412 IOT instruction (core dumped)  zig test test.zig --zig-lib-dir abc

The result of using 0.13.0 is

error: sub-compilation of zig_libc failed
    note: unable to load 'abc/std/std.zig': FileNotFound
error: sub-compilation of compiler_rt failed
    note: unable to load 'abc/std/std.zig': FileNotFound
error: unable to load 'abc/std/std.zig': FileNotFound

Expected Behavior

I expect the compiler to not segmentation fault!

Vexu commented 4 months ago

Regressed in 1eaeb4a0a838a783d2060f4e5b3b26b483b26009 @mlugg

WillLillis commented 2 months ago

This no longer reproduces on the latest master. It now outputs:

error: unable to open zig lib directory 'abc': FileNotFound