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 {
29122912 if (self.stub_helper_section_index == null) {
29132913 self.stub_helper_section_index = try self.allocateSection("__TEXT3", "__stub_helper", .{
29142914 .size = @sizeOf(u32),
2915 .alignment = switch (cpu_arch) {
2916 .x86_64 => 1,
2917 .aarch64 => @sizeOf(u32),
2918 else => unreachable, // unhandled architecture type
2919 },
2915 .alignment = stubs.stubAlignment(cpu_arch),
29202916 .flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
29212917 .prot = macho.PROT.READ | macho.PROT.EXEC,
29222918 });
src/link/MachO/stubs.zig+1-1
......@@ -25,7 +25,7 @@ pub inline fn stubSize(cpu_arch: std.Target.Cpu.Arch) u8 {
2525pub inline fn stubAlignment(cpu_arch: std.Target.Cpu.Arch) u8 {
2626 return switch (cpu_arch) {
2727 .x86_64 => 1,
28 .aarch64 => 2,
28 .aarch64 => 4,
2929 else => unreachable, // unhandled architecture type
3030 };
3131}
src/link/MachO/zld.zig+2-2
......@@ -1032,14 +1032,14 @@ fn calcSectionSizes(macho_file: *MachO) !void {
10321032 if (macho_file.stubs_section_index) |sect_id| {
10331033 const header = &macho_file.sections.items(.header)[sect_id];
10341034 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));
10361036 }
10371037
10381038 if (macho_file.stub_helper_section_index) |sect_id| {
10391039 const header = &macho_file.sections.items(.header)[sect_id];
10401040 header.size = macho_file.stub_table.count() * stubs.stubHelperSize(cpu_arch) +
10411041 stubs.stubHelperPreambleSize(cpu_arch);
1042 header.@"align" = stubs.stubAlignment(cpu_arch);
1042 header.@"align" = math.log2(stubs.stubAlignment(cpu_arch));
10431043 }
10441044
10451045 if (macho_file.la_symbol_ptr_section_index) |sect_id| {