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

Can't use --path-link - panic: reached unreachable code #114

Closed
tech189 opened this issue Mar 11, 2024 · 7 comments
Closed

Can't use --path-link - panic: reached unreachable code #114

tech189 opened this issue Mar 11, 2024 · 7 comments

Comments

@tech189
Copy link

tech189 commented Mar 11, 2024

Not sure how to use the --path-link argument, I'd like to put the zig.exe symlink that points to the default compiler in the specified directory but I get this error:

❯ zigup 0.11.0 --path-link "C:Users\$USER\scoop\apps\zigup\current\zig\"
install directory 'C:\Users\$USER\scoop\apps\zigup\current\zig'
mkdir "C:\Users\$USER\scoop\apps\zigup\current\zig"
compiler 'C:\Users\$USER\scoop\apps\zigup\current\zig\0.11.0' already installed
thread 25068 panic: reached unreachable code
???:?:?: 0x7ff66fd4537c in ??? (zigup.exe)
???:?:?: 0x7ff66fd11357 in ??? (zigup.exe)
???:?:?: 0x7ff66fcdecd8 in ??? (zigup.exe)
???:?:?: 0x7ff66fce148b in ??? (zigup.exe)
???:?:?: 0x7ff66fce3baa in ??? (zigup.exe)
???:?:?: 0x7ff66fce489d in ??? (zigup.exe)
???:?:?: 0x7ff66fce9de2 in ??? (zigup.exe)
???:?:?: 0x7ff66fcea2f5 in ??? (zigup.exe)
???:?:?: 0x7ff66fcea3f3 in ??? (zigup.exe)
???:?:?: 0x7ff8c4ab257c in ??? (KERNEL32.DLL)
???:?:?: 0x7ff8c524aa57 in ??? (ntdll.dll)
@marler8997
Copy link
Owner

--path-link should be a filename rather than a directory name, i.e.

> zigup 0.11.0 --path-link "C:Users\$USER\scoop\apps\zigup\current\zig\zig.exe"

@tech189
Copy link
Author

tech189 commented Mar 12, 2024

Same error when I specify a filename:

❯ .\zig-out\bin\zigup.exe 0.11.0 --path-link "C:Users\$USER\scoop\apps\zigup\current\zig\zig.exe"
install directory 'C:\Users\$USER\Documents\GitHub\zigup\zig-out\bin\zig'
mkdir "C:\Users\$USER\Documents\GitHub\zigup\zig-out\bin\zig"
compiler 'C:\Users\$USER\Documents\GitHub\zigup\zig-out\bin\zig\0.11.0' already installed
thread 8752 panic: reached unreachable code
C:\Users\$USER\scoop\apps\zigup\current\zig\0.11.0\files\lib\std\os\windows.zig:131:37: 0x7ff602d363ae in OpenFile (zigup.exe.obj)
            .OBJECT_NAME_INVALID => unreachable,
                                    ^
C:\Users\$USER\scoop\apps\zigup\current\zig\0.11.0\files\lib\std\fs.zig:1403:46: 0x7ff602d01e17 in createFileW (zigup.exe.obj)
            .handle = try os.windows.OpenFile(sub_path_w, .{
                                             ^
C:\Users\$USER\scoop\apps\zigup\current\zig\0.11.0\files\lib\std\fs.zig:1286:36: 0x7ff602ccf7d8 in createFile (zigup.exe.obj)
            return self.createFileW(path_w.span(), flags);
                                   ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:875:41: 0x7ff602cd1f8b in createExeLink (zigup.exe.obj)
    const file = std.fs.cwd().createFile(path_link, .{}) catch |err| switch (err) {
                                        ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:682:26: 0x7ff602cd46aa in setDefaultCompiler (zigup.exe.obj)
        try createExeLink(link_target, path_link);
                         ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:395:31: 0x7ff602cd5335 in fetchCompiler (zigup.exe.obj)
        try setDefaultCompiler(allocator, compiler_dir, .existence_verified);
                              ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:308:26: 0x7ff602cda85f in main2 (zigup.exe.obj)
        try fetchCompiler(allocator, args[0], .set_default);
                         ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:175:17: 0x7ff602cdad75 in main (zigup.exe.obj)
    return main2() catch |e| switch (e) {
                ^
C:\Users\$USER\scoop\apps\zigup\current\zig\0.11.0\files\lib\std\start.zig:339:65: 0x7ff602cdae73 in WinStartup (zigup.exe.obj)
    std.os.windows.kernel32.ExitProcess(initEventLoopAndCallMain());
                                                                ^
???:?:?: 0x7ff8c4ab257c in ??? (KERNEL32.DLL)
???:?:?: 0x7ff8c524aa57 in ??? (ntdll.dll)

@marler8997
Copy link
Owner

There's a few interesting things going on here. First it looks like your pathname is invalid. It should start with C:\Users not C:Users and you've also got a $ in your pathname. However, it looks this pathname is triggering an unreachable in the zig std module which is likely a problem in std. The problem is on my 2 windows machines, I don't get this error code, I'm guessing you might be running a different version of windows? On my systems I get OBJECT_PATH_NOT_FOUND which std handles, but on your system we seem to be getting OBJECT_NAME_INVALID which triggers an unreachable in std. We can reproduce this from a small test program:

const std = @import("std");

pub fn main() !void {
    const filename = "C:Users\\$USER\\scoop\\apps\\zigup\\current\\zig\\zig.exe";
    std.log.info("creating file '{s}'", .{filename});
    _ = try std.fs.cwd().createFile(filename, .{});
}

Here's what I get:

>zig run bug.zig
info: creating file 'C:Users\$USER\scoop\apps\zigup\current\zig\zig.exe'
error: FileNotFound
D:\tools\zig\0.12.0-dev.80+014d88ef6\files\lib\std\os\windows.zig:133:39: 0x7ff79f643116 in OpenFile (bug.exe.obj)
            .OBJECT_PATH_NOT_FOUND => return error.FileNotFound,
                                      ^
D:\tools\zig\0.12.0-dev.80+014d88ef6\files\lib\std\fs.zig:1403:23: 0x7ff79f615622 in createFileW (bug.exe.obj)
            .handle = try os.windows.OpenFile(sub_path_w, .{
                      ^
D:\tools\zig\0.12.0-dev.80+014d88ef6\files\lib\std\fs.zig:1286:13: 0x7ff79f611273 in createFile (bug.exe.obj)
            return self.createFileW(path_w.span(), flags);
            ^
C:\temp\zig-windows-bad-path\bug.zig:6:9: 0x7ff79f611073 in main (bug.exe.obj)
    _ = try std.fs.cwd().createFile(filename, .{});
        ^

Could you run this same test program and copy/paste the output so we can confirm you're getting OBJECT_NAME_INVALID in this situation? If we can confirm, we might need to update zig's std module to handle this error code. Also could you share which version of windows you are running?

Aside from this, to address your immediate issue, try updating your pathname by changing the start to C:\Users and removing the $USER and replace it with your username.

@tech189
Copy link
Author

tech189 commented Mar 13, 2024

Thank you for investigating this! I ran the program you pasted and got the following output, so it looks like a zig std library bug:

❯ zig run bug.zig
info: creating file 'C:Users\$USER\scoop\apps\zigup\current\zig\zig.exe'
thread 18816 panic: reached unreachable code
C:\Users\$USER\scoop\apps\zigup\current\zig\0.10.0\files\lib\std\os\windows.zig:125:33: 0x7ff6e14f1e60 in OpenFile (bug.exe.obj)
        .OBJECT_NAME_INVALID => unreachable,
                                ^
C:\Users\$USER\scoop\apps\zigup\current\zig\0.10.0\files\lib\std\fs.zig:1393:26: 0x7ff6e14c3c90 in createFileW (bug.exe.obj)
                else if (flags.truncate)
                         ^
C:\Users\$USER\scoop\apps\zigup\current\zig\0.10.0\files\lib\std\fs.zig:1264:48: 0x7ff6e14c1478 in createFile (bug.exe.obj)
            return self.createFileW(path_w.span(), flags);
                                               ^
C:/Users/$USER/Documents/GitHub/bug.zig:6:45: 0x7ff6e14c12d0 in main (bug.exe.obj)
                    _ = try std.fs.cwd().createFile(filename, .{});
                                            ^
C:\Users\$USER\scoop\apps\zigup\current\zig\0.10.0\files\lib\std\start.zig:377:41: 0x7ff6e14c15e7 in WinStartup (bug.exe.obj)
    std.debug.maybeEnableSegfaultHandler();
                                        ^
???:?:?: 0x7ff8c4ab257c in ??? (???)
???:?:?: 0x7ff8c524aa57 in ??? (???)

I am running Windows 11 (22H2) Build 22621.3155

Also yes, I did forget to put a \ in my path, but I still get an error when I correct this, or when I use my real username in the path rather than the PowerShell variable $env:USERNAME (I was writing $USER for short):

❯ .\zigup\zig-out\bin\zigup.exe 0.10.0 --path-link "C:\Users\$USER\scoop\apps\zigup\current\zig\zig.exe"
install directory 'C:\Users\$USER\Documents\GitHub\zigup\zig-out\bin\zig'
mkdir "C:\Users\$USER\Documents\GitHub\zigup\zig-out\bin\zig"
compiler 'C:\Users\$USER\Documents\GitHub\zigup\zig-out\bin\zig\0.10.0' already installed
error: AccessDenied
C:\Users\$USER\scoop\apps\zigup\current\zig\0.11.0\files\lib\std\fs.zig:1822:31: 0x7ff7f800750d in openDirAccessMaskW (zigup.exe.obj)
            .ACCESS_DENIED => return error.AccessDenied,
                              ^
C:\Users\$USER\scoop\apps\zigup\current\zig\0.11.0\files\lib\std\fs.zig:1755:19: 0x7ff7f7fa9596 in openDirW (zigup.exe.obj)
        var dir = try self.openDirAccessMaskW(sub_path_w, flags, args.no_follow);
                  ^
C:\Users\$USER\scoop\apps\zigup\current\zig\0.11.0\files\lib\std\fs.zig:1660:13: 0x7ff7f7f729e6 in openDir (zigup.exe.obj)
            return self.openDirW(sub_path_w.span().ptr, args, false);
            ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:774:21: 0x7ff7f7f727aa in compareDir (zigup.exe.obj)
        else => |e| return e,
                    ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:730:21: 0x7ff7f7f73452 in verifyPathLink (zigup.exe.obj)
            switch (try compareDir(path_link_dir_id, path)) {
                    ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:687:5: 0x7ff7f7f747a6 in setDefaultCompiler (zigup.exe.obj)
    try verifyPathLink(allocator, path_link);
    ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:395:9: 0x7ff7f7f753a9 in fetchCompiler (zigup.exe.obj)
        try setDefaultCompiler(allocator, compiler_dir, .existence_verified);
        ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:308:9: 0x7ff7f7f7a891 in main2 (zigup.exe.obj)
        try fetchCompiler(allocator, args[0], .set_default);
        ^
C:\Users\$USER\Documents\GitHub\zigup\zigup.zig:177:17: 0x7ff7f7f7adc2 in main (zigup.exe.obj)
        else => return e,
                ^

@marler8997
Copy link
Owner

I've create a PR to fix the first issue in zig here: ziglang/zig#19288

I've also created a zigup PR to fix the second issue here: #115 .

Do you mind trying out the zigup PR #115 and see if it fixes the issue for you?

@tech189
Copy link
Author

tech189 commented Mar 13, 2024

Thank you, when I use the branch for #115 I don't get an error anymore!

@marler8997
Copy link
Owner

Fix released here: https://github.com/marler8997/zigup/releases/tag/v2024_03_13

andrewrk pushed a commit to ziglang/zig that referenced this issue Mar 14, 2024
It's been seen on Windows 11 (22H2) Build 22621.3155 that NtCreateFile
will return the OBJECT_NAME_INVALID error code with certain path names.
The path name we saw this with started with `C:Users` (rather than
`C:\Users`) and also contained a `$` character.  This PR updates our
OpenFile wrapper to propagate this error code as `error.BadPathName`
instead of making it `unreachable`.

see marler8997/zigup#114 (comment)
RossComputerGuy pushed a commit to ExpidusOS-archive/zig that referenced this issue Mar 20, 2024
It's been seen on Windows 11 (22H2) Build 22621.3155 that NtCreateFile
will return the OBJECT_NAME_INVALID error code with certain path names.
The path name we saw this with started with `C:Users` (rather than
`C:\Users`) and also contained a `$` character.  This PR updates our
OpenFile wrapper to propagate this error code as `error.BadPathName`
instead of making it `unreachable`.

see marler8997/zigup#114 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants