std: Apple Silicon: no fstat$INODE64 symbol found#6842
std: Apple Silicon: no fstat$INODE64 symbol found#6842kubkon merged 2 commits intoziglang:masterfrom
Conversation
It seems that Apple has finally got rid of the 32bit versions of `fstat` and `fstatat`, and instead, only 64bit versions are available on BigSur and Apple Silicon. The tweak in this commit is required to make Zig stage1 compile on BigSur + aarch64.
lib/std/c.zig
Outdated
| pub usingnamespace switch (builtin.arch) { | ||
| .aarch64 => struct { | ||
| pub extern "c" fn fstatat(dirfd: fd_t, path: [*:0]const u8, stat_buf: *Stat, flags: u32) c_int; | ||
| }, | ||
| else => struct { | ||
| pub const fstatat = @"fstatat$INODE64"; | ||
| }, | ||
| }; |
There was a problem hiding this comment.
Would it maybe be cleaner to simply list both functions and rely on lazy evaluation?
pub const fstatat = switch (builtin.arch) {
.aarch64 => fstatat,
else => @"fstatat$INODE64",
};There was a problem hiding this comment.
Hmm, any ideas if there's a way to avoid overriding the previous definition, i.e., fstatat has already been defined by pub extern "c" fn fstatat...?
There was a problem hiding this comment.
Take a step back and reorganize things. Is the previous definition correct already? Can just use that. If not, sounds like fstatat needs to become one of the functions that moves from the common file to OS-specific files.
There was a problem hiding this comment.
Let's try to keep all the os-related conditional definitions/renames in the switch below.
Hmm, any ideas if there's a way to avoid overriding the previous definition, i.e., fstatat has already been defined by pub extern "c" fn fstatat...?
You can handle it the same way fstat is handled below: define fstatat in c/darwin.zig together with its weird cousin fstatat$INODE64 (and add a comment explaining why it's defined there) and then export the correct fstat symbol below. Other platforms get the usual pub extern "c" fn fstatat(..) ..., it's a bit repetitive but I couldn't figure out a nicer looking way to handle this symbol mess.
There was a problem hiding this comment.
Addressed in 4f50958. Have a look and lemme know if that's what you had in mind.
There was a problem hiding this comment.
Looks good.
Perhaps it's time to think of moving all the c definitions in a separate file for each os.
There was a problem hiding this comment.
Orrr... we could resurrect Andrew's idea of an @extern suggested in #3971 and augment it with a way to specify a comptime string as symbol name. This way we finally get the weak-symbol mechanism and gain a cleaner way to deal with those nasty renames.
There was a problem hiding this comment.
Hmm, after a quick browse I think I'm partial to the second solution of weak-symbol mechanism. This would indeed make a lot of things cleaner and more elegant.
|
Looks good. Thanks a lot for bringing Zig to Apple Silicon! |
ad360e1 to
4f50958
Compare
|
Don't forget to update |
Yep, but I'll make it the subject of a subsequent PR. |
It seems that Apple has finally got rid of the 32bit versions of
fstatandfstatat, and instead, only 64bit versions are availableon BigSur and Apple Silicon.
The tweak in this commit is required to make Zig stage1 compile on
BigSur + aarch64.