zig icon indicating copy to clipboard operation
zig copied to clipboard

link: move macOS kernel inode cache invalidation to MachO linker

Open kubkon opened this issue 2 years ago • 0 comments

Since #14647 landed in master, I started experiencing build failures on an M1 mac where it looked as if the output directory handle was getting closed before we could invalidate the kernel cache by moving the final binary in-place. The code responsible for this so far resided in link.makeExecutable but now I am of the opinion that it really is part of the MachO linker only. I have thus moved it and as expected it solved the problems for me.

For the record, here's an example error trace before this change:

zig build-exe zdb Debug native: error: thread 6148693 panic: reached unreachable code                                                                                                                                                                                                                                                                                  
/Users/kubkon/dev/zig/build/stage3/lib/zig/std/os.zig:1725:22: 0x10449d813 in openatZ (zig)                                                                                                                                                                                                                                     
            .BADF => unreachable,                                                                                                                                                                                                                                                                                               
                     ^                                                                                                                                                                                                                                                                                                          
/Users/kubkon/dev/zig/build/stage3/lib/zig/std/fs.zig:1179:32: 0x10426dc7f in openFileZ (zig)                                                                                                                                                                                                                                   
            try os.openatZ(self.fd, sub_path, os_flags, 0);                                                                                                                                                                                                                                                                     
                               ^                                                                                                                                                                                                                                                                                                
/Users/kubkon/dev/zig/build/stage3/lib/zig/std/fs.zig:1113:30: 0x1040e0e2b in openFile (zig)                                                                                                                                                                                                                                    
        return self.openFileZ(&path_c, flags);                                                                                                                                                                                                                                                                                  
                             ^                                                                                                                                                                                                                                                                                                  
/Users/kubkon/dev/zig/build/stage3/lib/zig/std/fs.zig:2563:46: 0x1041a1ffb in copyFile (zig)                                                                                                                                                                                                                                    
        var in_file = try source_dir.openFile(source_path, .{});                                                                                                                                                                                                                                                                
                                             ^                                                                                                                                                                                                                                                                                  
/Users/kubkon/dev/zig/src/link.zig:436:102: 0x1041ef463 in makeExecutable (zig)                                                                                                                                                                                                                                                 
                        try emit.directory.handle.copyFile(emit.sub_path, emit.directory.handle, emit.sub_path, .{});                                                                                                                                                                                                           
                                                                                                     ^                                                                                                                                                                                                                          
/Users/kubkon/dev/zig/src/Compilation.zig:2469:40: 0x1041ef007 in makeBinFileExecutable (zig)                                                                                                                                                                                                                                   
    return self.bin_file.makeExecutable();                                                                                                                                                                                                                                                                                      
                                       ^                                                                                                                                                                                                                                                                                        
/Users/kubkon/dev/zig/src/main.zig:3498:47: 0x104214c5f in serve (zig)                                                                                                                                                                                                                                                          
                try comp.makeBinFileExecutable();                                                                                                                                                                                                                                                                               
                                              ^                                                                                                                                                                                                                                                                                 
/Users/kubkon/dev/zig/src/main.zig:3298:31: 0x1040bbb5f in buildOutputType (zig)                                                                                                                                                                                                                                                
                test_exec_args.items,                                                                                                                                                                                                                                                                                           
                              ^                                                                                                                                                                                                                                                                                                 
/Users/kubkon/dev/zig/src/main.zig:267:31: 0x10408f357 in mainArgs (zig)                                                                                                                                                                                                                                                        
        return buildOutputType(gpa, arena, args, .{ .build = .Exe });                                                                                                                                                                                                                                                           
                              ^                                                                                                                                                                                                                                                                                                 
/Users/kubkon/dev/zig/src/main.zig:211:20: 0x10408eaf7 in main (zig)                                                                                                                                                                                                                                                            
    return mainArgs(gpa, arena, args);                                                                                                                                                                                                                                                                                          
                   ^                                                                                                                                                                                                                                                                                                            
/Users/kubkon/dev/zig/build/stage3/lib/zig/std/start.zig:617:37: 0x104090f13 in main (zig)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x1aa0c3e4f in ??? (???)
???:?:?: 0xde3affffffffffff in ??? (???)

zig build-exe zdb Debug native: error: the following command terminated unexpectedly:
/Users/kubkon/dev/zig/build/stage4/bin/zig build-exe /Users/kubkon/dev/zdb/src/main.zig /Users/kubkon/dev/zdb/src/macos/mach_excUser.c /Users/kubkon/dev/zdb/src/macos/mach_excServer.c --cache-dir /Users/kubkon/dev/zdb/zig-cache --global-cache-dir /Users/kubkon/.cache/zig --name zdb --entitlements resources/Info.plist --mod build_options::/Users/kubkon/dev/zdb/zig-cache/options/Dfs55J_0mL3vKEcBg-fTHWsoD5DNKkw-_hN_otKnahHPKdjb9j_UGtbDK13-7MR5 --deps build_options -I /Users/kubkon/dev/zdb/src --enable-cache --listen=- 
Build Summary: 1/4 steps succeeded; 1 failed (disable with -fno-summary)
install transitive failure
└─ install zdb transitive failure
   └─ zig build-exe zdb Debug native failure
      └─ options success
error: the following build command failed with exit code 1:
/Users/kubkon/dev/zdb/zig-cache/o/d0d7fd31f9d3811bc176313047d275c4/build /Users/kubkon/dev/zig/build/stage4/bin/zig /Users/kubkon/dev/zdb /Users/kubkon/dev/zdb/zig-cache /Users/kubkon/.cache/zig

kubkon avatar Mar 16 '23 16:03 kubkon