From 9908b10d928a12731a288bd59068151d386efdac Mon Sep 17 00:00:00 2001 From: Paulo Duarte Date: Sun, 28 Jun 2026 15:18:48 +0100 Subject: [PATCH] MachO: apply default header padding for codesign When no headerpad_size parameter is passed, Zig doesn't reserve enough space for a codesign signature. Signing the binary corrupts the first bytes of __text, causing it to crash. The crash only affects x86_64 since aarch64 binaries are signed by the linker by default, so a new signature just replaces the existing one. This is a regression introduced by 7588eeccea on 2024-01-10. The fix restores the behavior prior to the regression by applying the default value. Fixes #31428. --- src/link/MachO/load_commands.zig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/link/MachO/load_commands.zig b/src/link/MachO/load_commands.zig index 758475f06f0f0489bd128c0b7009ba597d9ce218..ec556b16bb9a7a50ada47fe9740c25aea9fc775b 100644 --- a/src/link/MachO/load_commands.zig +++ b/src/link/MachO/load_commands.zig @@ -164,7 +164,8 @@ pub fn calcLoadCommandsSizeObject(macho_file: *MachO) u32 { } pub fn calcMinHeaderPadSize(macho_file: *MachO) !u32 { - var padding: u32 = (try calcLoadCommandsSize(macho_file, false)) + (macho_file.headerpad_size orelse 0); + var padding: u32 = (try calcLoadCommandsSize(macho_file, false)) + + (macho_file.headerpad_size orelse MachO.default_headerpad_size); log.debug("minimum requested headerpad size 0x{x}", .{padding + @sizeOf(macho.mach_header_64)}); if (macho_file.headerpad_max_install_names) { -- 2.54.0