ziglang / zig

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

macOS 14 Sonoma tracking issue #15963

Closed haze closed 1 year ago

haze commented 1 year ago

Zig Version

0.11.0-dev.3380+7e0a02ee2

Steps to Reproduce and Observed Behavior

On a computer running macOS 14 Sonoma (23A5257q):

MachO Flush... error(link): undefined reference to symbol '_isatty'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '___ulock_wait2'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_getenv'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_abort'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '__dyld_image_count'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_close$NOCANCEL'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_fstat'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_openat'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '___error'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '__dyld_get_image_header'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_pthread_threadid_np'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '__tlv_bootstrap'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_munmap'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_mmap'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_bzero'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_environ'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_sigaction'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_fcntl'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '___stack_chk_fail'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_os_unfair_lock_unlock'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_os_unfair_lock_lock'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_write'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '__dyld_get_image_name'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '__dyld_get_image_vmaddr_slide'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '___stack_chk_guard'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_read'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '_msync'
error(link):   first referenced in '/private/var/folders/q3/j805mc2s23q6pxwv40q2y4680000gn/T/tmp.HczPr83Xf2/main.o'
error(link): undefined reference to symbol '__availability_version_check'
error(link):   first referenced in '/Users/haze/.cache/zig/o/8d59771e4b63a8c5949848778da7ebeb/libcompiler_rt.a(/Users/haze/.cache/zig/o/8d59771e4b63a8c5949848778da7ebeb/libcompiler_rt.a.o)'
error(link): undefined reference to symbol '_sys_icache_invalidate'
error(link):   first referenced in '/Users/haze/.cache/zig/o/8d59771e4b63a8c5949848778da7ebeb/libcompiler_rt.a(/Users/haze/.cache/zig/o/8d59771e4b63a8c5949848778da7ebeb/libcompiler_rt.a.o)'
error(link): undefined reference to symbol 'dyld_stub_binder'
error: UndefinedSymbolReference

I was able to successfully link the programs by using the intermediary object files in zig-cache, or by using build-obj by using zld built from zld HEAD, or the Xcode 15 clang.

When using —-verbose-link and copying the zig ld command (does that even still exist?) and replacing it with zld, it works.

Expected Behavior

The compilation process should succeed.

haze commented 1 year ago

Some more investigation:

```console 7ms /p/var/f/q3/j805…/T/tmp.HczPr83Xf2 edited-zig build-obj --debug-log tapi --debug-log link --debug-log archive src/main.zig debug(link): selected linker mode 'incremental' debug(link): creating main.o.dSYM bundle debug(link): found __TEXT segment (header-only) free space 0x0 to 0x4000 debug(link): found __TEXT1,__text free space 0x4000 to 0x44000 (0x100004000 - 0x100044000) debug(link): found __TEXT2,__stubs free space 0x5c000 to 0x5c00c (0x100044000 - 0x100048000) debug(link): found __TEXT3,__stub_helper free space 0x60000 to 0x60004 (0x100048000 - 0x10004c000) debug(link): found __DATA_CONST,__got free space 0x64000 to 0x64100 (0x10004c000 - 0x100050000) debug(link): found __DATA_CONST1,__const free space 0x68000 to 0x68008 (0x100050000 - 0x100054000) debug(link): found __DATA,__la_symbol_ptr free space 0x6c000 to 0x6c008 (0x100054000 - 0x100058000) debug(link): found __DATA1,__data free space 0x70000 to 0x70008 (0x100058000 - 0x10005c000) debug(link): found __DATA2,__thread_vars free space 0x74000 to 0x74018 (0x10005c000 - 0x100060000) debug(link): found __DATA3,__thread_data free space 0x78000 to 0x78008 (0x100060000 - 0x100064000) debug(link): updateDecl Module.Decl@1504a0390 (zig_backend), type=builtin.CompilerBackend debug(link): (allocating symbol index 1) debug(link): creating ATOM(%1) at index 0 debug(link): allocated atom for builtin.zig_backend at 0x100050000 debug(link): (required alignment 0x8) debug(link): (allocating entry at index 0) debug(link): writing GOT entry 0: @10004c000 => 100050000 debug(link): marking relocs dirty by target: link.MachO.SymbolWithLoc{ .sym_index = 1, .file = null } debug(link): writing atom for symbol builtin.zig_backend at file offset 0x68000 debug(link): relocating 'builtin.zig_backend' debug(link): updateDecl Module.Decl@106946e10 (simplified_logic), type=bool debug(link): (allocating symbol index 2) debug(link): creating ATOM(%2) at index 1 debug(link): allocated atom for start.simplified_logic at 0x100050008 debug(link): (required alignment 0x1) debug(link): (allocating entry at index 1) debug(link): writing GOT entry 1: @10004c008 => 100050008 debug(link): marking relocs dirty by target: link.MachO.SymbolWithLoc{ .sym_index = 2, .file = null } debug(link): writing atom for symbol start.simplified_logic at file offset 0x68008 debug(link): relocating 'start.simplified_logic' debug(link): updateDecl Module.Decl@1504a0428 (output_mode), type=builtin.OutputMode debug(link): (allocating symbol index 3) debug(link): creating ATOM(%3) at index 2 debug(link): allocated atom for builtin.output_mode at 0x100050009 debug(link): (required alignment 0x1) debug(link): (allocating entry at index 2) debug(link): writing GOT entry 2: @10004c010 => 100050009 debug(link): marking relocs dirty by target: link.MachO.SymbolWithLoc{ .sym_index = 3, .file = null } debug(link): writing atom for symbol builtin.output_mode at file offset 0x68009 debug(link): relocating 'builtin.output_mode' debug(link): MachO Zld new_digest=6561333461653535353339366137373433373236646638363766663166333436 error: FileNotFound debug(link): MachO Zld prev_digest= new_digest=6561333461653535353339366137373433373236646638363766663166333436 debug(link): parsing lib path '/Users/haze/zig/lib/libc/darwin/libSystem.14.tbd' debug(link): unknown filetype for a library: '/Users/haze/zig/lib/libc/darwin/libSystem.14.tbd' debug(link): (allocating symbol index 0) debug(link): (allocating symbol index 4) debug(link): (allocating symbol index 1) debug(link): (allocating symbol index 5) error(link): undefined symbol reference 'dyld_stub_binder' error(link): undefined symbol reference '__tlv_bootstrap' error: UndefinedSymbolReference /Users/haze/zig/src/link/MachO.zig:630:9: 0x10302e067 in flushModule (zig) return error.UndefinedSymbolReference; ^ /Users/haze/zig/src/link/MachO.zig:477:25: 0x102e2ef53 in flush (zig) .incremental => return self.flushModule(comp, prog_node), ^ /Users/haze/zig/src/link.zig:800:23: 0x102c45f1b in flush (zig) .macho => return @fieldParentPtr(MachO, "base", base).flush(comp, prog_node), ^ /Users/haze/zig/src/Compilation.zig:2160:21: 0x102c457e7 in flush (zig) else => |e| return e, ^ /Users/haze/zig/src/Compilation.zig:2138:9: 0x102c4934b in update (zig) try comp.flush(main_progress_node); ^ /Users/haze/zig/src/main.zig:3835:9: 0x102c75eff in updateModule (zig) try comp.update(main_progress_node); ^ /Users/haze/zig/src/main.zig:3272:21: 0x102b4caab in buildOutputType (zig) else => |e| return e, ^ /Users/haze/zig/src/main.zig:273:9: 0x102afbe8b in mainArgs (zig) return buildOutputType(gpa, arena, args, .{ .build = .Obj }); ^ /Users/haze/zig/src/main.zig:213:5: 0x102af998f in main (zig) return mainArgs(gpa, arena, args); ^ ```
haze commented 1 year ago

Copying the libSystem.tbd gets us further:

```console debug(link): selected linker mode 'incremental' debug(link): creating main.o.dSYM bundle debug(link): found __TEXT segment (header-only) free space 0x0 to 0x4000 debug(link): found __TEXT1,__text free space 0x4000 to 0x44000 (0x100004000 - 0x100044000) debug(link): found __TEXT2,__stubs free space 0x5c000 to 0x5c00c (0x100044000 - 0x100048000) debug(link): found __TEXT3,__stub_helper free space 0x60000 to 0x60004 (0x100048000 - 0x10004c000) debug(link): found __DATA_CONST,__got free space 0x64000 to 0x64100 (0x10004c000 - 0x100050000) debug(link): found __DATA_CONST1,__const free space 0x68000 to 0x68008 (0x100050000 - 0x100054000) debug(link): found __DATA,__la_symbol_ptr free space 0x6c000 to 0x6c008 (0x100054000 - 0x100058000) debug(link): found __DATA1,__data free space 0x70000 to 0x70008 (0x100058000 - 0x10005c000) debug(link): found __DATA2,__thread_vars free space 0x74000 to 0x74018 (0x10005c000 - 0x100060000) debug(link): found __DATA3,__thread_data free space 0x78000 to 0x78008 (0x100060000 - 0x100064000) debug(link): updateDecl Module.Decl@280560390 (zig_backend), type=builtin.CompilerBackend debug(link): (allocating symbol index 1) debug(link): creating ATOM(%1) at index 0 debug(link): allocated atom for builtin.zig_backend at 0x100050000 debug(link): (required alignment 0x8) debug(link): (allocating entry at index 0) debug(link): writing GOT entry 0: @10004c000 => 100050000 debug(link): marking relocs dirty by target: link.MachO.SymbolWithLoc{ .sym_index = 1, .file = null } debug(link): writing atom for symbol builtin.zig_backend at file offset 0x68000 debug(link): relocating 'builtin.zig_backend' debug(link): updateDecl Module.Decl@155910810 (simplified_logic), type=bool debug(link): (allocating symbol index 2) debug(link): creating ATOM(%2) at index 1 debug(link): allocated atom for start.simplified_logic at 0x100050008 debug(link): (required alignment 0x1) debug(link): (allocating entry at index 1) debug(link): writing GOT entry 1: @10004c008 => 100050008 debug(link): marking relocs dirty by target: link.MachO.SymbolWithLoc{ .sym_index = 2, .file = null } debug(link): writing atom for symbol start.simplified_logic at file offset 0x68008 debug(link): relocating 'start.simplified_logic' debug(link): updateDecl Module.Decl@280560428 (output_mode), type=builtin.OutputMode debug(link): (allocating symbol index 3) debug(link): creating ATOM(%3) at index 2 debug(link): allocated atom for builtin.output_mode at 0x100050009 debug(link): (required alignment 0x1) debug(link): (allocating entry at index 2) debug(link): writing GOT entry 2: @10004c010 => 100050009 debug(link): marking relocs dirty by target: link.MachO.SymbolWithLoc{ .sym_index = 3, .file = null } debug(link): writing atom for symbol builtin.output_mode at file offset 0x68009 debug(link): relocating 'builtin.output_mode' debug(link): MachO Zld new_digest=6561333461653535353339366137373433373236646638363766663166333436 error: FileNotFound debug(link): MachO Zld prev_digest= new_digest=6561333461653535353339366137373433373236646638363766663166333436 debug(link): parsing lib path '/Users/haze/zig/lib/libc/darwin/libSystem.14.tbd' debug(link): parsing shared library '/Users/haze/zig/lib/libc/darwin/libSystem.14.tbd' debug(link): invalid filetype: expected 0x6, found 0x62740a64 debug(tapi): trying to parse as []TbdV4 debug(link): parsing shared library from stub '/Users/haze/zig/lib/libc/darwin/libSystem.14.tbd' debug(link): (install_name '/usr/lib/libSystem.B.dylib') debug(link): (allocating symbol index 0) debug(link): (allocating symbol index 4) debug(link): (allocating symbol index 1) debug(link): (allocating symbol index 5) debug(link): (allocating entry at index 3) debug(link): writing GOT entry 3: @10004c018 => 0 debug(link): marking relocs dirty by target: link.MachO.SymbolWithLoc{ .sym_index = 4, .file = null } debug(link): (allocating symbol index 6) debug(link): creating ATOM(%6) at index 3 debug(link): allocated dyld_private atom at 0x100058000 debug(link): writing atom for symbol at file offset 0x70000 debug(link): relocating '' debug(link): symtab: debug(link): %0: @0 in ord(0), ___u debug(link): %1: builtin.zig_backend @100050000 in sect(6), s___ debug(link): %2: start.simplified_logic @100050008 in sect(6), s___ debug(link): %3: builtin.output_mode @100050009 in sect(6), s___ debug(link): %4: dyld_stub_binder @0 in ord(1), _e_u debug(link): %5: __tlv_bootstrap @0 in ord(1), _e_u debug(link): %6: @100058000 in sect(8), s___ debug(link): globals table: debug(link): dyld_stub_binder => %4 in object(null) debug(link): __tlv_bootstrap => %5 in object(null) debug(link): GOT entries: debug(link): TableSection: 0 => link.MachO.SymbolWithLoc{ .sym_index = 1, .file = null } 1 => link.MachO.SymbolWithLoc{ .sym_index = 2, .file = null } 2 => link.MachO.SymbolWithLoc{ .sym_index = 3, .file = null } 3 => link.MachO.SymbolWithLoc{ .sym_index = 4, .file = null } debug(link): stubs entries: debug(link): TableSection: debug(link): sections: debug(link): sect(1): __TEXT1,__text @4000 (100004000), sizeof(40000) debug(link): sect(2): __TEXT2,__stubs @5c000 (100044000), sizeof(c) debug(link): sect(3): __TEXT3,__stub_helper @60000 (100048000), sizeof(4) debug(link): sect(4): __DATA_CONST,__got @64000 (10004c000), sizeof(20) debug(link): sect(5): __DATA_CONST1,__const @68000 (100050000), sizeof(a) debug(link): sect(6): __DATA,__la_symbol_ptr @6c000 (100054000), sizeof(8) debug(link): sect(7): __DATA1,__data @70000 (100058000), sizeof(8) debug(link): sect(8): __DATA2,__thread_vars @74000 (10005c000), sizeof(18) debug(link): sect(9): __DATA3,__thread_data @78000 (100060000), sizeof(8) debug(link): atoms: debug(link): __DATA_CONST1,__const debug(link): ATOM(%1, 'builtin.zig_backend') @ 100050000 sizeof(8) in object(null) in sect(6) debug(link): ATOM(%2, 'start.simplified_logic') @ 100050008 sizeof(1) in object(null) in sect(6) debug(link): ATOM(%3, 'builtin.output_mode') @ 100050009 sizeof(1) in object(null) in sect(6) debug(link): __DATA1,__data debug(link): ATOM(%6, '') @ 100058000 sizeof(8) in object(null) in sect(8) debug(link): | rebase at 0 debug(link): | rebase at 8 debug(link): | rebase at 10 debug(link): | bind at 18, import('dyld_stub_binder') in dylib(1) debug(link): generating export trie thread 1106744 panic: attempt to use null value /Users/haze/zig/src/link/MachO/Trie.zig:334:33: 0x10507c47f in finalize (zig) try fifo.writeItem(self.root.?); ^ /Users/haze/zig/src/link/MachO.zig:3202:22: 0x1050a7d53 in collectExportData (zig) try trie.finalize(gpa); ^ /Users/haze/zig/src/link/MachO.zig:3225:31: 0x1050a8a9f in writeDyldInfoData (zig) try self.collectExportData(&trie); ^ /Users/haze/zig/src/link/MachO.zig:3036:31: 0x1050ad0bb in writeLinkeditSegmentData (zig) try self.writeDyldInfoData(); ^ /Users/haze/zig/src/link/MachO.zig:694:38: 0x104d12da7 in flushModule (zig) try self.writeLinkeditSegmentData(); ^ /Users/haze/zig/src/link/MachO.zig:477:48: 0x104b12f23 in flush (zig) .incremental => return self.flushModule(comp, prog_node), ^ /Users/haze/zig/src/link.zig:800:72: 0x104929ebf in flush (zig) .macho => return @fieldParentPtr(MachO, "base", base).flush(comp, prog_node), ^ /Users/haze/zig/src/Compilation.zig:2157:24: 0x10492978f in flush (zig) comp.bin_file.flush(comp, prog_node) catch |err| switch (err) { ^ /Users/haze/zig/src/Compilation.zig:2138:23: 0x10492ca37 in update (zig) try comp.flush(main_progress_node); ^ /Users/haze/zig/src/main.zig:3835:24: 0x104959edb in updateModule (zig) try comp.update(main_progress_node); ^ /Users/haze/zig/src/main.zig:3270:17: 0x104830757 in buildOutputType (zig) updateModule(comp) catch |err| switch (err) { ^ /Users/haze/zig/src/main.zig:273:31: 0x1047dfdfb in mainArgs (zig) return buildOutputType(gpa, arena, args, .{ .build = .Obj }); ^ /Users/haze/zig/src/main.zig:213:20: 0x1047dd92f in main (zig) return mainArgs(gpa, arena, args); ^ /Users/haze/zig/build/stage3/lib/zig/std/start.zig:609:37: 0x1047dd647 in main (zig) const result = root.main() catch |err| { ^ ???:?:?: 0x18443d057 in ??? (???) ???:?:?: 0x9e1bffffffffffff in ??? (???) fish: Job 1, 'edited-zig build-obj --debug-lo…' terminated by signal SIGABRT (Abort) ```
haze commented 1 year ago

Oddly enough, non debug versions of the compiler work with libSystem.14.tbd added.

morgangallant commented 1 year ago

Seeing a similar issue on Zig version 0.11.0-dev.3258+7621e5693 running macOS Sonoma. @haze have you been able to find any temporary workarounds here yet that work? If so, mind sending over some instructions?

haze commented 1 year ago

@morgangallant (and for anyone else either brave or forced to upgrade):

I forget whether or not you need to compile zig from source to pick up the new libSystem.tbd files. I always build zig from source. I'm not going to upload the tbd here, but you can easily grab it from your Xcode 15 installation. You can use this command to find the full path, like this:

fd libSystem -e=tbd (xcrun --show-sdk-path)
/Applications/Xcode-15.0.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreTelephony.framework/Support/libSystemDetermination.tbd
/Applications/Xcode-15.0.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem_asan.tbd
/Applications/Xcode-15.0.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.B.tbd
/Applications/Xcode-15.0.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.B_asan.tbd
/Applications/Xcode-15.0.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd

Then you want to copy /Applications/Xcode-15.0.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd to zig/lib/libc/darwin/:

cp /Applications/Xcode-15.0.0-Beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd zig/lib/libc/darwin/libSystem.14.tbd

I'm unsure if there's an edge case that I'm missing. For the most part I've been able to use zig without hassle after copying the tbd file.

rudedogg commented 1 year ago

For the most part I've been able to use zig without hassle after copying the tbd file.

Thanks, this worked for me. I'm using the nightly binary downloads from ziglang.org FWIW.

StanislavNikolov commented 1 year ago

In summary:

$ curl https://ziglang.org/builds/zig-macos-aarch64-0.11.0-dev.3393+34d44e0c1.tar.xz -O
$ tar -xf ./zig-macos-aarch64-0.11.0-dev.3393+34d44e0c1.tar.xz
$ cp /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/lib/libSystem.tbd zig-macos-aarch64-0.11.0-dev.3393+34d44e0c1/lib/libc/darwin/libSystem.14.tbd
$ alias zig='./zig-macos-aarch64-0.11.0-dev.3393+34d44e0c1/zig'

Then zig build run works. Maybe augmenting $PATH would be better.

morgangallant commented 1 year ago

Thank you all! Worked like a charm :)

For those who stumble onto this thread in the future, following @StanislavNikolov's solution to the tee solved the problem. Only step not mentioned was that I had to install the updated Command Line Tools for Xcode 15 Beta (from here) to get the MacOSX14.sdk file.

kubkon commented 1 year ago

I am converting this issue into a tracking issue for macOS 14 Sonoma and related problems.

kubkon commented 1 year ago

16212 will enable building Zig on Sonoma with no tweaks to the compiler provided the SDK is installed. This will also be true for any future release of macOS.

ghost commented 1 year ago

has there been any progress on this?

haze commented 1 year ago

has there been any progress on this?

The PR mentioned above should be rebased off of main. From my experience, nix doesn’t work still, but natively it should work. If you don’t want to compile zig again with the new branch, you can use the workarounds mentioned earlier in the discussion

Solido commented 1 year ago

Thank you team, it worked for me. Just beware my distribution contains libSystem.B.tbd instead.

luizberti commented 1 year ago

@kprotty and myself just found out a couple of days ago that, even with the suggested fix involving moving the libSystem.tbd file to the right place, it seems the Zig compiler is passing the wrong CPU flags.

We found this because I was playing around with some AES primitives from std.crypto but couldn't figure out why it was falling back to the non-accelerated software implementation of it. Passing -Dcpu=apple_latest seems to fix the issue.

/cc @jedisct1

kubkon commented 1 year ago

@kprotty and myself just found out a couple of days ago that, even with the suggested fix involving moving the libSystem.tbd file to the right place, it seems the Zig compiler is passing the wrong CPU flags.

We found this because I was playing around with some AES primitives from std.crypto but couldn't figure out why it was falling back to the non-accelerated software implementation of it. Passing -Dcpu=apple_latest seems to fix the issue.

/cc @jedisct1

This should be filed as a separate issue as it has nothing to do with the OS version.

luizberti commented 1 year ago

This should be filed as a separate issue as it has nothing to do with the OS version. — @kubkon

Given that this only happens in Sonoma, and that if you just zig build without that flag in Ventura everything works like it should, I would say that this actually seems to have something to do with the OS version?

If you still think I should move this into a separate issue just let me know 👍

kubkon commented 1 year ago

This should be filed as a separate issue as it has nothing to do with the OS version. — @kubkon

Given that this only happens in Sonoma, and that if you just zig build without that flag in Ventura everything works like it should, I would say that this actually seems to have something to do with the OS version?

If you still think I should move this into a separate issue just let me know 👍

I would strongly believe that to be a coincidence.

AngusP commented 1 week ago

In summary:

$ curl https://ziglang.org/builds/zig-macos-aarch64-0.11.0-dev.3393+34d44e0c1.tar.xz -O
$ tar -xf ./zig-macos-aarch64-0.11.0-dev.3393+34d44e0c1.tar.xz
$ cp /Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/usr/lib/libSystem.tbd zig-macos-aarch64-0.11.0-dev.3393+34d44e0c1/lib/libc/darwin/libSystem.14.tbd
$ alias zig='./zig-macos-aarch64-0.11.0-dev.3393+34d44e0c1/zig'

Then zig build run works. Maybe augmenting $PATH would be better.

If you don't have full XCode installed and instead just have the command line tools (from xcode-select ...) then you'll find libSystem.tbd here instead:

ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX14.5.sdk/usr/lib/libSystem.tbd /opt/homebrew/Cellar/zig/0.13.0/lib/zig/libc/darwin/libSystem.tbd

⚠️ Note the MacOSX14.5.sdk part of the path and the zig version/location will change over time for newer versions of MacOS and zig, e.g. MacOSX15.1.sdk, and where you've installed zig to