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.
This commit is contained in:
Andrew Kelley 2021-05-17 13:46:54 -07:00
parent 3697022a41
commit 8405d6f7e2

View File

@ -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 {