zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 8405d6f7e2d837e52eaedeb651d596d94297de91 (tree)
parent 3697022a41ffa13a3971aeaf96b9c2b8de391ab1
Author: Andrew Kelley <andrew@ziglang.org>
Date:   Mon, 17 May 2021 13:46:54 -0700

link/MachO: bring in some of the Elf logic

There was missing incremental compilation logic in the MachO linker
code, causing test failures. With this logic ported over from the
corresponding ELF logic, tests pass again.

Diffstat:
Msrc/link/MachO.zig | 46++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+), 0 deletions(-)

diff --git a/src/link/MachO.zig b/src/link/MachO.zig @@ -1073,6 +1073,15 @@ fn freeTextBlock(self: *MachO, text_block: *TextBlock) void { // TODO shrink the __text section size here self.last_text_block = text_block.prev; } + if (self.d_sym) |*ds| { + if (ds.dbg_info_decl_first == text_block) { + ds.dbg_info_decl_first = text_block.dbg_info_next; + } + if (ds.dbg_info_decl_last == text_block) { + // TODO shrink the .debug_info section size here + ds.dbg_info_decl_last = text_block.dbg_info_prev; + } + } if (text_block.prev) |prev| { prev.next = text_block.next; @@ -1091,6 +1100,20 @@ fn freeTextBlock(self: *MachO, text_block: *TextBlock) void { } else { text_block.next = null; } + + if (text_block.dbg_info_prev) |prev| { + prev.dbg_info_next = text_block.dbg_info_next; + + // TODO the free list logic like we do for text blocks above + } else { + text_block.dbg_info_prev = null; + } + + if (text_block.dbg_info_next) |next| { + next.dbg_info_prev = text_block.dbg_info_prev; + } else { + text_block.dbg_info_next = null; + } } fn shrinkTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64) void { @@ -1477,6 +1500,29 @@ pub fn freeDecl(self: *MachO, decl: *Module.Decl) void { decl.link.macho.local_sym_index = 0; } + if (self.d_sym) |*ds| { + // TODO make this logic match freeTextBlock. Maybe abstract the logic + // out since the same thing is desired for both. + _ = ds.dbg_line_fn_free_list.remove(&decl.fn_link.macho); + if (decl.fn_link.macho.prev) |prev| { + ds.dbg_line_fn_free_list.put(self.base.allocator, prev, {}) catch {}; + prev.next = decl.fn_link.macho.next; + if (decl.fn_link.macho.next) |next| { + next.prev = prev; + } else { + ds.dbg_line_fn_last = prev; + } + } else if (decl.fn_link.macho.next) |next| { + ds.dbg_line_fn_first = next; + next.prev = null; + } + if (ds.dbg_line_fn_first == &decl.fn_link.macho) { + ds.dbg_line_fn_first = decl.fn_link.macho.next; + } + if (ds.dbg_line_fn_last == &decl.fn_link.macho) { + ds.dbg_line_fn_last = decl.fn_link.macho.prev; + } + } } pub fn getDeclVAddr(self: *MachO, decl: *const Module.Decl) u64 {