Skip to content

Commit cc56400

Browse files
committed
Revert "macho: allow unaligned offsets in object files"
This reverts commit 45c444f.
1 parent 74673b7 commit cc56400

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/link/MachO/Object.zig

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,10 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
9999
},
100100
.SYMTAB => {
101101
const symtab = cmd.cast(macho.symtab_command).?;
102-
// Sadly, SYMTAB may be at an unaligned offset within the object file.
103-
self.in_symtab = @alignCast(@alignOf(macho.nlist_64), @ptrCast(
104-
[*]align(1) const macho.nlist_64,
105-
self.contents.ptr + symtab.symoff,
106-
))[0..symtab.nsyms];
102+
self.in_symtab = @ptrCast(
103+
[*]const macho.nlist_64,
104+
@alignCast(@alignOf(macho.nlist_64), &self.contents[symtab.symoff]),
105+
)[0..symtab.nsyms];
107106
self.in_strtab = self.contents[symtab.stroff..][0..symtab.strsize];
108107
try self.symtab.appendSlice(allocator, self.in_symtab);
109108
},
@@ -303,10 +302,10 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32)
303302
const code: ?[]const u8 = if (!sect.isZerofill()) try self.getSectionContents(sect) else null;
304303

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

311310
// Symbols within this section only.
312311
const filtered_syms = filterSymbolsByAddress(
@@ -549,10 +548,10 @@ pub fn parseDataInCode(self: Object) ?[]const macho.data_in_code_entry {
549548
.DATA_IN_CODE => {
550549
const dice = cmd.cast(macho.linkedit_data_command).?;
551550
const ndice = @divExact(dice.datasize, @sizeOf(macho.data_in_code_entry));
552-
return @alignCast(@alignOf(macho.data_in_code_entry), @ptrCast(
553-
[*]align(1) const macho.data_in_code_entry,
554-
self.contents.ptr + dice.dataoff,
555-
))[0..ndice];
551+
return @ptrCast(
552+
[*]const macho.data_in_code_entry,
553+
@alignCast(@alignOf(macho.data_in_code_entry), &self.contents[dice.dataoff]),
554+
)[0..ndice];
556555
},
557556
else => {},
558557
}

0 commit comments

Comments
 (0)