Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/link/MachO/Object.zig
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
},
.SYMTAB => {
const symtab = cmd.cast(macho.symtab_command).?;
self.in_symtab = @ptrCast(
[*]const macho.nlist_64,
@alignCast(@alignOf(macho.nlist_64), &self.contents[symtab.symoff]),
)[0..symtab.nsyms];
// Sadly, SYMTAB may be at an unaligned offset within the object file.
self.in_symtab = @alignCast(@alignOf(macho.nlist_64), @ptrCast(
Copy link
Member

@andrewrk andrewrk Aug 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I don't know how I missed this before but these @alignCast are doing the exact same assertion they were before. This patch effectively does nothing. I have no idea why the stage3 build completed successfully for me, but anyway now it is panicking again. I'll push the fix soon 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm surprised as this fixed it for me locally. I'll re-do the tests then.

[*]align(1) const macho.nlist_64,
self.contents.ptr + symtab.symoff,
))[0..symtab.nsyms];
self.in_strtab = self.contents[symtab.stroff..][0..symtab.strsize];
try self.symtab.appendSlice(allocator, self.in_symtab);
},
Expand Down Expand Up @@ -302,10 +303,10 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32)
const code: ?[]const u8 = if (!sect.isZerofill()) try self.getSectionContents(sect) else null;

// Read section's list of relocations
const relocs = @ptrCast(
[*]const macho.relocation_info,
@alignCast(@alignOf(macho.relocation_info), &self.contents[sect.reloff]),
)[0..sect.nreloc];
const relocs = @alignCast(@alignOf(macho.relocation_info), @ptrCast(
[*]align(1) const macho.relocation_info,
self.contents.ptr + sect.reloff,
))[0..sect.nreloc];

// Symbols within this section only.
const filtered_syms = filterSymbolsByAddress(
Expand Down Expand Up @@ -548,10 +549,10 @@ pub fn parseDataInCode(self: Object) ?[]const macho.data_in_code_entry {
.DATA_IN_CODE => {
const dice = cmd.cast(macho.linkedit_data_command).?;
const ndice = @divExact(dice.datasize, @sizeOf(macho.data_in_code_entry));
return @ptrCast(
[*]const macho.data_in_code_entry,
@alignCast(@alignOf(macho.data_in_code_entry), &self.contents[dice.dataoff]),
)[0..ndice];
return @alignCast(@alignOf(macho.data_in_code_entry), @ptrCast(
[*]align(1) const macho.data_in_code_entry,
self.contents.ptr + dice.dataoff,
))[0..ndice];
},
else => {},
}
Expand Down