-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Invoking zig cc with wine errors #17535
Comments
I'm going to investigate this... if this is hopefully just a matter of resolving this one issue hopefully this use case can work! (although I just realised it might be tricky to build zig for windows without easy access to windows myself... might need to tackle this one later if I do get access to it at some point...) Just realised it might just be an issue with |
So the bug seems to be in There's specifically this section:
and this assumption is violated as the path returned is of the form |
Edit: Sorry, I was just wrong about this one. The problem here is that I just reported what I think is the source of the problem upstream to wine. Here's a quick program that demonstrates the problem: pub const std = @import("std");
pub fn main() !void {
const image_path_name = std.os.windows.peb().ProcessParameters.ImagePathName;
std.log.info("self path: Length = {}, MaximumLength = {}", .{ image_path_name.Length, image_path_name.MaximumLength });
const buffer = image_path_name.Buffer.?[0..image_path_name.Length];
std.log.info("self path: Buffer = {}", .{std.unicode.fmtUtf16Le(buffer)});
std.debug.dumpHex(std.mem.sliceAsBytes(buffer));
}
The executable path in |
Follow up, my previous post was incorrect, I was simply treating However, I did some further digging and was able to get backtraces working on wine, though I'm pretty sure the logic isn't correct. diff --git a/lib/std/debug/SelfInfo.zig b/lib/std/debug/SelfInfo.zig
index 544cf0ac6f..7f07ea1e8b 100644
--- a/lib/std/debug/SelfInfo.zig
+++ b/lib/std/debug/SelfInfo.zig
@@ -1003,7 +1003,7 @@ fn readCoffDebugInfo(allocator: Allocator, coff_obj: *coff.Coff) !Module {
di.dwarf = dwarf;
}
- const raw_path = try coff_obj.getPdbPath() orelse return di;
+ const raw_path = (coff_obj.getPdbPath() catch return error.InvalidDebugInfo) orelse return di;
const path = blk: {
if (fs.path.isAbsolute(raw_path)) {
break :blk raw_path;
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig
index ceed0618d1..381e722cda 100644
--- a/lib/std/os/windows.zig
+++ b/lib/std/os/windows.zig
@@ -1292,6 +1292,17 @@ pub fn GetFinalPathNameByHandle(
return final_path;
},
.Dos => {
+ // https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-even/c1550f98-a1ce-426a-9991-7509e7c3787c
+ const nt_unc_prefix = std.unicode.utf8ToUtf16LeStringLiteral("\\??\\UNC\\");
+ const nt_prefix = std.unicode.utf8ToUtf16LeStringLiteral("\\??\\");
+ if (mem.startsWith(u16, final_path, nt_unc_prefix)) {
+ // replace the 'C' in "UNC" with a backslash to convert it to DOS UNC syntax `\\servername\``
+ final_path[nt_unc_prefix.len - 2] = '\\';
+ return final_path[nt_unc_prefix.len - 2 ..];
+ } else if (mem.startsWith(u16, final_path, nt_prefix)) {
+ return final_path[nt_prefix.len..];
+ }
+
// parse the string to separate volume path from file path
const expected_prefix = std.unicode.utf8ToUtf16LeStringLiteral("\\Device\\");
I found three articles related to this syntax; a stackoverflow post, a section in Microsoft's EventLog Remoting Protocol, and a blog post on converting win32 paths to NT paths referenced by said stackoverflow post. Okay the more I read the less I understand. Why is diff --git a/lib/std/fs.zig b/lib/std/fs.zig
index 99936e9abd..de81741f15 100644
--- a/lib/std/fs.zig
+++ b/lib/std/fs.zig
@@ -475,8 +475,7 @@ pub fn openSelfExe(flags: File.OpenFlags) OpenSelfExeError!File {
// the file, we can let the openFileW call follow the symlink for us.
const image_path_unicode_string = &windows.peb().ProcessParameters.ImagePathName;
const image_path_name = image_path_unicode_string.Buffer.?[0 .. image_path_unicode_string.Length / 2 :0];
- const prefixed_path_w = try windows.wToPrefixedFileW(null, image_path_name);
- return cwd().openFileW(prefixed_path_w.span(), flags);
+ return cwd().openFileW(image_path_name.span(), flags);
}
// Use of max_path_bytes here is valid as the resulting path is immediately
// opened with no modification. My only thought is that perhaps it was copying |
Relevant pull request: #17541 Relevant wine issue: https://bugs.winehq.org/show_bug.cgi?id=39569 |
Zig Version
0.12.0-dev.890+8c6b0271c
Steps to Reproduce and Observed Behavior
Given a c file (eg. aaa.c):
running:
zig.exe cc aaa.c
but specifically through wine, results in the following error:
Expected Behavior
For zig to execute normally through wine.
Version of wine tested is 8.17 on Fedora.
Main use case is that I'm keen to test windows features on zig but no longer have access to windows.
The text was updated successfully, but these errors were encountered: