diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-02-08 13:12:06 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-02-08 13:12:06 +0100 |
| commit | 102846315c1be4518ce7783717dc1ceb133b66cf (patch) | |
| tree | 51d6fdf2d20240e3114e33ae672d4743c178dc6e /src | |
| parent | ce207caa24dc3a283288beb7ee5fd4a07c2c8691 (diff) | |
| download | zig-102846315c1be4518ce7783717dc1ceb133b66cf.tar.gz zig-102846315c1be4518ce7783717dc1ceb133b66cf.zip | |
macho: couple small fixes
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/MachO.zig | 23 | ||||
| -rw-r--r-- | src/link/MachO/ZigObject.zig | 15 | ||||
| -rw-r--r-- | src/link/MachO/relocatable.zig | 4 |
3 files changed, 29 insertions, 13 deletions
diff --git a/src/link/MachO.zig b/src/link/MachO.zig index aac0536816..d018cc01a2 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -3205,7 +3205,7 @@ fn detectAllocCollision(self: *MachO, start: u64, size: u64) ?u64 { for (self.sections.items(.header)) |header| { if (header.isZerofill()) continue; const increased_size = padToIdeal(header.size); - const test_end = header.offset + increased_size; + const test_end = header.offset +| increased_size; if (end > header.offset and start < test_end) { return test_end; } @@ -3233,7 +3233,7 @@ fn detectAllocCollisionVirtual(self: *MachO, start: u64, size: u64) ?u64 { for (self.sections.items(.header)) |header| { const increased_size = padToIdeal(header.size); - const test_end = header.addr + increased_size; + const test_end = header.addr +| increased_size; if (end > header.addr and start < test_end) { return test_end; } @@ -3250,7 +3250,7 @@ fn detectAllocCollisionVirtual(self: *MachO, start: u64, size: u64) ?u64 { return null; } -fn allocatedSize(self: *MachO, start: u64) u64 { +pub fn allocatedSize(self: *MachO, start: u64) u64 { if (start == 0) return 0; var min_pos: u64 = std.math.maxInt(u64); for (self.sections.items(.header)) |header| { @@ -3264,12 +3264,19 @@ fn allocatedSize(self: *MachO, start: u64) u64 { return min_pos - start; } -fn allocatedSizeVirtual(self: *MachO, start: u64) u64 { +pub fn allocatedSizeVirtual(self: *MachO, start: u64) u64 { if (start == 0) return 0; var min_pos: u64 = std.math.maxInt(u64); - for (self.segments.items) |seg| { - if (seg.vmaddr <= start) continue; - if (seg.vmaddr < min_pos) min_pos = seg.vmaddr; + if (self.base.isRelocatable()) { + for (self.sections.items(.header)) |header| { + if (header.addr <= start) continue; + if (header.addr < min_pos) min_pos = header.addr; + } + } else { + for (self.segments.items) |seg| { + if (seg.vmaddr <= start) continue; + if (seg.vmaddr < min_pos) min_pos = seg.vmaddr; + } } return min_pos - start; } @@ -3482,7 +3489,7 @@ fn initMetadata(self: *MachO, options: InitMetadataOptions) !void { } } - if (self.base.isRelocatable()) { + if (self.base.isRelocatable() and options.zo.dwarf != null) { { self.debug_str_sect_index = try self.addSection("__DWARF", "__debug_str", .{ .flags = macho.S_ATTR_DEBUG, diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index 061f268892..3a28e824d5 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -52,11 +52,11 @@ dynamic_relocs: MachO.DynamicRelocs = .{}, output_symtab_ctx: MachO.SymtabCtx = .{}, output_ar_state: Archive.ArState = .{}, -debug_strtab_dirty: bool = true, -debug_abbrev_dirty: bool = true, -debug_aranges_dirty: bool = true, -debug_info_header_dirty: bool = true, -debug_line_header_dirty: bool = true, +debug_strtab_dirty: bool = false, +debug_abbrev_dirty: bool = false, +debug_aranges_dirty: bool = false, +debug_info_header_dirty: bool = false, +debug_line_header_dirty: bool = false, pub fn init(self: *ZigObject, macho_file: *MachO) !void { const comp = macho_file.base.comp; @@ -70,6 +70,11 @@ pub fn init(self: *ZigObject, macho_file: *MachO) !void { .dwarf => |v| { assert(v == .@"32"); self.dwarf = Dwarf.init(&macho_file.base, .dwarf32); + self.debug_strtab_dirty = true; + self.debug_abbrev_dirty = true; + self.debug_aranges_dirty = true; + self.debug_info_header_dirty = true; + self.debug_line_header_dirty = true; }, .code_view => unreachable, } diff --git a/src/link/MachO/relocatable.zig b/src/link/MachO/relocatable.zig index 8f5bf97696..b5241c498e 100644 --- a/src/link/MachO/relocatable.zig +++ b/src/link/MachO/relocatable.zig @@ -403,6 +403,7 @@ fn calcSectionSizes(macho_file: *MachO) !void { if (!atom.flags.alive) continue; const header = &macho_file.sections.items(.header)[atom.out_n_sect]; if (!macho_file.isZigSection(atom.out_n_sect)) continue; + if (!macho_file.isDebugSection(atom.out_n_sect)) continue; header.nreloc += atom.calcNumRelocs(macho_file); } } @@ -540,6 +541,7 @@ fn writeAtoms(macho_file: *MachO) !void { if (atoms.items.len == 0) continue; if (header.isZerofill()) continue; if (macho_file.isZigSection(@intCast(i))) continue; + if (macho_file.isDebugSection(@intCast(i))) continue; const size = math.cast(usize, header.size) orelse return error.Overflow; const code = try gpa.alloc(u8, size); @@ -581,6 +583,7 @@ fn writeAtoms(macho_file: *MachO) !void { for (macho_file.sections.items(.header), 0..) |header, n_sect| { if (header.isZerofill()) continue; if (!macho_file.isZigSection(@intCast(n_sect))) continue; + if (!macho_file.isDebugSection(@intCast(n_sect))) continue; const gop = try relocs.getOrPut(@intCast(n_sect)); if (gop.found_existing) continue; gop.value_ptr.* = try std.ArrayList(macho.relocation_info).initCapacity(gpa, header.nreloc); @@ -592,6 +595,7 @@ fn writeAtoms(macho_file: *MachO) !void { const header = macho_file.sections.items(.header)[atom.out_n_sect]; if (header.isZerofill()) continue; if (!macho_file.isZigSection(atom.out_n_sect)) continue; + if (!macho_file.isDebugSection(atom.out_n_sect)) continue; if (atom.getRelocs(macho_file).len == 0) continue; const atom_size = math.cast(usize, atom.size) orelse return error.Overflow; const code = try gpa.alloc(u8, atom_size); |
