diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-09-06 18:30:40 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-09-06 18:30:40 +0200 |
| commit | 6836cc473c3e75a71c0e6c0123c8afb23a79596d (patch) | |
| tree | 805129caa39f1e6513b170728fbf837eced998a6 /src | |
| parent | 81e5320973e8cffd585f240b20321e6afc15e8f9 (diff) | |
| download | zig-6836cc473c3e75a71c0e6c0123c8afb23a79596d.tar.gz zig-6836cc473c3e75a71c0e6c0123c8afb23a79596d.zip | |
macho: make sure that parsed bss atoms are zero-filled
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/MachO.zig | 12 | ||||
| -rw-r--r-- | src/link/MachO/Object.zig | 25 |
2 files changed, 28 insertions, 9 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig index ec5ce6aedd..8f89133378 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -1672,7 +1672,7 @@ pub fn allocateAtom(self: *MachO, atom: *TextBlock, match: MatchingSection) !u64 break :blk new_start_vaddr; } else sect.addr; - log.warn("allocating atom for symbol {s} at address 0x{x}", .{ self.getString(sym.n_strx), vaddr }); + log.debug("allocating atom for symbol {s} at address 0x{x}", .{ self.getString(sym.n_strx), vaddr }); const expand_section = atom_placement == null or atom_placement.?.next == null; if (expand_section) { @@ -3803,13 +3803,13 @@ fn growSection(self: *MachO, match: MatchingSection, new_size: u32) !void { if (last_sect_off + offset_amt > seg_off) { // Need to grow segment first. - log.warn(" (need to grow segment first)", .{}); + log.debug(" (need to grow segment first)", .{}); const spill_size = (last_sect_off + offset_amt) - seg_off; const seg_offset_amt = mem.alignForwardGeneric(u64, spill_size, self.page_size); seg.inner.filesize += seg_offset_amt; seg.inner.vmsize += seg_offset_amt; - log.warn(" (new {s} segment file offsets from 0x{x} to 0x{x} (in memory 0x{x} to 0x{x}))", .{ + log.debug(" (new {s} segment file offsets from 0x{x} to 0x{x} (in memory 0x{x} to 0x{x}))", .{ seg.inner.segname, seg.inner.fileoff, seg.inner.fileoff + seg.inner.filesize, @@ -3836,7 +3836,7 @@ fn growSection(self: *MachO, match: MatchingSection, new_size: u32) !void { next_seg.inner.fileoff += seg_offset_amt; next_seg.inner.vmaddr += seg_offset_amt; - log.warn(" (new {s} segment file offsets from 0x{x} to 0x{x} (in memory 0x{x} to 0x{x}))", .{ + log.debug(" (new {s} segment file offsets from 0x{x} to 0x{x} (in memory 0x{x} to 0x{x}))", .{ next_seg.inner.segname, next_seg.inner.fileoff, next_seg.inner.fileoff + next_seg.inner.filesize, @@ -3848,7 +3848,7 @@ fn growSection(self: *MachO, match: MatchingSection, new_size: u32) !void { moved_sect.offset += @intCast(u32, seg_offset_amt); moved_sect.addr += seg_offset_amt; - log.warn(" (new {s},{s} file offsets from 0x{x} to 0x{x} (in memory 0x{x} to 0x{x}))", .{ + log.debug(" (new {s},{s} file offsets from 0x{x} to 0x{x} (in memory 0x{x} to 0x{x}))", .{ commands.segmentName(moved_sect.*), commands.sectionName(moved_sect.*), moved_sect.offset, @@ -3884,7 +3884,7 @@ fn growSection(self: *MachO, match: MatchingSection, new_size: u32) !void { moved_sect.offset += @intCast(u32, offset_amt); moved_sect.addr += offset_amt; - log.warn(" (new {s},{s} file offsets from 0x{x} to 0x{x} (in memory 0x{x} to 0x{x}))", .{ + log.debug(" (new {s},{s} file offsets from 0x{x} to 0x{x} (in memory 0x{x} to 0x{x}))", .{ commands.segmentName(moved_sect.*), commands.sectionName(moved_sect.*), moved_sect.offset, diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index a3f0c56065..c72aa66b84 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -408,7 +408,14 @@ const TextBlockParser = struct { const block = try context.macho_file.createEmptyAtom(senior_nlist.index, size, actual_align); block.stab = stab; - mem.copy(u8, block.code.items, code); + + const is_zerofill = blk: { + const section_type = commands.sectionType(self.section); + break :blk section_type == macho.S_ZEROFILL or section_type == macho.S_THREAD_LOCAL_ZEROFILL; + }; + if (!is_zerofill) { + mem.copy(u8, block.code.items, code); + } try block.aliases.ensureTotalCapacity(context.allocator, aliases.items.len); for (aliases.items) |alias| { @@ -567,7 +574,13 @@ pub fn parseTextBlocks( const block_size = block_code.len; const block = try macho_file.createEmptyAtom(block_local_sym_index, block_size, sect.@"align"); - mem.copy(u8, block.code.items, block_code); + const is_zerofill = blk: { + const section_type = commands.sectionType(sect); + break :blk section_type == macho.S_ZEROFILL or section_type == macho.S_THREAD_LOCAL_ZEROFILL; + }; + if (!is_zerofill) { + mem.copy(u8, block.code.items, block_code); + } try block.parseRelocs(relocs, .{ .base_addr = 0, @@ -667,7 +680,13 @@ pub fn parseTextBlocks( }; const block = try macho_file.createEmptyAtom(block_local_sym_index, sect.size, sect.@"align"); - mem.copy(u8, block.code.items, code); + const is_zerofill = blk: { + const section_type = commands.sectionType(sect); + break :blk section_type == macho.S_ZEROFILL or section_type == macho.S_THREAD_LOCAL_ZEROFILL; + }; + if (!is_zerofill) { + mem.copy(u8, block.code.items, code); + } try block.parseRelocs(relocs, .{ .base_addr = 0, |
