zig icon indicating copy to clipboard operation
zig copied to clipboard

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

Open gooncreeper opened this issue 1 year ago • 1 comments

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!

gooncreeper avatar Jul 09 '24 19:07 gooncreeper

Regressed in 1eaeb4a0a838a783d2060f4e5b3b26b483b26009 @mlugg

Vexu avatar Jul 15 '24 11:07 Vexu

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

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

WillLillis avatar Sep 10 '24 02:09 WillLillis

this issue should be re-opened.

It reproduces for me on any directory that exists. I think @WillLillis did not use a directory that exists but was still an otherwise invalid zlg lib directory

zig version: 0.14.0-dev.2362+a47aa9dd9 host: x86_64 linux

jeffective avatar Dec 01 '24 02:12 jeffective

Can you give updated reproduction steps?

$ zig-dev version
0.14.0-dev.2367+aa7d13846
$ mkdir abc
$ touch test.zig
$ zig-dev test test.zig --zig-lib-dir abc
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

Vexu avatar Dec 01 '24 10:12 Vexu

@Vexu You're right I couldn't get the exact same reproduction. Since the steps have changed, I created a separate issue: https://github.com/ziglang/zig/issues/22122

jeffective avatar Dec 02 '24 05:12 jeffective