@@ -99,10 +99,11 @@ pub fn parse(self: *Object, allocator: Allocator, cpu_arch: std.Target.Cpu.Arch)
99
99
},
100
100
.SYMTAB = > {
101
101
const symtab = cmd .cast (macho .symtab_command ).? ;
102
- self .in_symtab = @ptrCast (
103
- [* ]const macho .nlist_64 ,
104
- @alignCast (@alignOf (macho .nlist_64 ), & self .contents [symtab .symoff ]),
105
- )[0.. symtab .nsyms ];
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 ];
106
107
self .in_strtab = self .contents [symtab .stroff .. ][0.. symtab .strsize ];
107
108
try self .symtab .appendSlice (allocator , self .in_symtab );
108
109
},
@@ -302,10 +303,10 @@ pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32)
302
303
const code : ? []const u8 = if (! sect .isZerofill ()) try self .getSectionContents (sect ) else null ;
303
304
304
305
// Read section's list of relocations
305
- const relocs = @ptrCast (
306
- [* ]const macho .relocation_info ,
307
- @alignCast ( @alignOf ( macho . relocation_info ), & self .contents [ sect .reloff ]) ,
308
- )[0.. sect .nreloc ];
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 ];
309
310
310
311
// Symbols within this section only.
311
312
const filtered_syms = filterSymbolsByAddress (
@@ -548,10 +549,10 @@ pub fn parseDataInCode(self: Object) ?[]const macho.data_in_code_entry {
548
549
.DATA_IN_CODE = > {
549
550
const dice = cmd .cast (macho .linkedit_data_command ).? ;
550
551
const ndice = @divExact (dice .datasize , @sizeOf (macho .data_in_code_entry ));
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 ];
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 ];
555
556
},
556
557
else = > {},
557
558
}
0 commit comments