macho: fix overalignment of stubs on aarch64

This commit is contained in:
Jakub Konka
2023-08-27 23:04:27 +02:00
parent 0353bfd55e
commit 700b1e38ce
3 changed files with 4 additions and 8 deletions

View File

@@ -2912,11 +2912,7 @@ fn populateMissingMetadata(self: *MachO) !void {
if (self.stub_helper_section_index == null) {
self.stub_helper_section_index = try self.allocateSection("__TEXT3", "__stub_helper", .{
.size = @sizeOf(u32),
.alignment = switch (cpu_arch) {
.x86_64 => 1,
.aarch64 => @sizeOf(u32),
else => unreachable, // unhandled architecture type
},
.alignment = stubs.stubAlignment(cpu_arch),
.flags = macho.S_REGULAR | macho.S_ATTR_PURE_INSTRUCTIONS | macho.S_ATTR_SOME_INSTRUCTIONS,
.prot = macho.PROT.READ | macho.PROT.EXEC,
});

View File

@@ -25,7 +25,7 @@ pub inline fn stubSize(cpu_arch: std.Target.Cpu.Arch) u8 {
pub inline fn stubAlignment(cpu_arch: std.Target.Cpu.Arch) u8 {
return switch (cpu_arch) {
.x86_64 => 1,
.aarch64 => 2,
.aarch64 => 4,
else => unreachable, // unhandled architecture type
};
}

View File

@@ -1032,14 +1032,14 @@ fn calcSectionSizes(macho_file: *MachO) !void {
if (macho_file.stubs_section_index) |sect_id| {
const header = &macho_file.sections.items(.header)[sect_id];
header.size = macho_file.stub_table.count() * stubs.stubSize(cpu_arch);
header.@"align" = stubs.stubAlignment(cpu_arch);
header.@"align" = math.log2(stubs.stubAlignment(cpu_arch));
}
if (macho_file.stub_helper_section_index) |sect_id| {
const header = &macho_file.sections.items(.header)[sect_id];
header.size = macho_file.stub_table.count() * stubs.stubHelperSize(cpu_arch) +
stubs.stubHelperPreambleSize(cpu_arch);
header.@"align" = stubs.stubAlignment(cpu_arch);
header.@"align" = math.log2(stubs.stubAlignment(cpu_arch));
}
if (macho_file.la_symbol_ptr_section_index) |sect_id| {