authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-27 23:04:27+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-08-29 11:40:20+02:00
log700b1e38ceeb66416a327e4f31969b1e52ba55ef
tree339971ca9589943563bbd7011d4cddc4070df198
parent0353bfd55ed67fa5c1c1d0e3004fcbae7f139b92

macho: fix overalignment of stubs on aarch64


3 files changed, 4 insertions(+), 8 deletions(-)

src/link/MachO.zig+1-5
...@@ -2912,11 +2912,7 @@ fn populateMissingMetadata(self: *MachO) !void {...@@ -2912,11 +2912,7 @@ fn populateMissingMetadata(self: *MachO) !void {
2912 if (self.stub_helper_section_index == null) {2912 if (self.stub_helper_section_index == null) {
2913 self.stub_helper_section_index = try self.allocateSection("__TEXT3", "__stub_helper", .{2913 self.stub_helper_section_index = try self.allocateSection("__TEXT3", "__stub_helper", .{
2914 .size = @sizeOf(u32),2914 .size = @sizeOf(u32),
2915 .alignment = switch (cpu_arch) {2915 .alignment = stubs.stubAlignment(cpu_arch),
2916 .x86_64 => 1,
2917 .aarch64 => @sizeOf(u32),
2918 else => unreachable, // unhandled architecture type
2919 },
2920 .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,2916 .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
2921 .prot = macho.PROT.READ | macho.PROT.EXEC,2917 .prot = macho.PROT.READ | macho.PROT.EXEC,
2922 });2918 });
src/link/MachO/stubs.zig+1-1
...@@ -25,7 +25,7 @@ pub inline fn stubSize(cpu_arch: std.Target.Cpu.Arch) u8 {...@@ -25,7 +25,7 @@ pub inline fn stubSize(cpu_arch: std.Target.Cpu.Arch) u8 {
25pub inline fn stubAlignment(cpu_arch: std.Target.Cpu.Arch) u8 {25pub inline fn stubAlignment(cpu_arch: std.Target.Cpu.Arch) u8 {
26 return switch (cpu_arch) {26 return switch (cpu_arch) {
27 .x86_64 => 1,27 .x86_64 => 1,
28 .aarch64 => 2,28 .aarch64 => 4,
29 else => unreachable, // unhandled architecture type29 else => unreachable, // unhandled architecture type
30 };30 };
31}31}
src/link/MachO/zld.zig+2-2
...@@ -1032,14 +1032,14 @@ fn calcSectionSizes(macho_file: *MachO) !void {...@@ -1032,14 +1032,14 @@ fn calcSectionSizes(macho_file: *MachO) !void {
1032 if (macho_file.stubs_section_index) |sect_id| {1032 if (macho_file.stubs_section_index) |sect_id| {
1033 const header = &macho_file.sections.items(.header)[sect_id];1033 const header = &macho_file.sections.items(.header)[sect_id];
1034 header.size = macho_file.stub_table.count() * stubs.stubSize(cpu_arch);1034 header.size = macho_file.stub_table.count() * stubs.stubSize(cpu_arch);
1035 header.@"align" = stubs.stubAlignment(cpu_arch);1035 header.@"align" = math.log2(stubs.stubAlignment(cpu_arch));
1036 }1036 }
10371037
1038 if (macho_file.stub_helper_section_index) |sect_id| {1038 if (macho_file.stub_helper_section_index) |sect_id| {
1039 const header = &macho_file.sections.items(.header)[sect_id];1039 const header = &macho_file.sections.items(.header)[sect_id];
1040 header.size = macho_file.stub_table.count() * stubs.stubHelperSize(cpu_arch) +1040 header.size = macho_file.stub_table.count() * stubs.stubHelperSize(cpu_arch) +
1041 stubs.stubHelperPreambleSize(cpu_arch);1041 stubs.stubHelperPreambleSize(cpu_arch);
1042 header.@"align" = stubs.stubAlignment(cpu_arch);1042 header.@"align" = math.log2(stubs.stubAlignment(cpu_arch));
1043 }1043 }
10441044
1045 if (macho_file.la_symbol_ptr_section_index) |sect_id| {1045 if (macho_file.la_symbol_ptr_section_index) |sect_id| {