macho: don't prealloc sections when stage1

This commit is contained in:
Jakub Konka
2021-12-04 13:53:57 +01:00
parent 9e03cf9489
commit c86f2402d0
3 changed files with 464 additions and 192 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -344,7 +344,8 @@ pub fn parseRelocs(self: *Atom, relocs: []macho.relocation_info, context: RelocC
const local_sym_index = context.object.sections_as_symbols.get(sect_id) orelse blk: {
const seg = context.object.load_commands.items[context.object.segment_cmd_index.?].Segment;
const sect = seg.sections.items[sect_id];
const match = (try context.macho_file.getMatchingSection(sect)) orelse unreachable;
const match = (try context.macho_file.getMatchingSection(sect)) orelse
unreachable;
const local_sym_index = @intCast(u32, context.macho_file.locals.items.len);
try context.macho_file.locals.append(context.allocator, .{
.n_strx = 0,

View File

@@ -474,7 +474,9 @@ pub fn parseIntoAtoms(self: *Object, allocator: Allocator, macho_file: *MachO) !
try self.sections_as_symbols.putNoClobber(allocator, sect_id, atom_local_sym_index);
break :blk atom_local_sym_index;
};
const atom = try macho_file.createEmptyAtom(atom_local_sym_index, sect.size, sect.@"align");
const alignment = try math.powi(u32, 2, sect.@"align");
const aligned_size = mem.alignForwardGeneric(u64, sect.size, alignment);
const atom = try macho_file.createEmptyAtom(atom_local_sym_index, aligned_size, sect.@"align");
const is_zerofill = blk: {
const section_type = commands.sectionType(sect);