authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 13:46:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 13:46:54-07:00
log8405d6f7e2d837e52eaedeb651d596d94297de91
treeac0a71a748a5461eafe9c2c1818f097036a264d7
parent3697022a41ffa13a3971aeaf96b9c2b8de391ab1

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.

1 files changed, 46 insertions(+), 0 deletions(-)

src/link/MachO.zig+46
...@@ -1073,6 +1073,15 @@ fn freeTextBlock(self: *MachO, text_block: *TextBlock) void {...@@ -1073,6 +1073,15 @@ fn freeTextBlock(self: *MachO, text_block: *TextBlock) void {
1073 // TODO shrink the __text section size here1073 // TODO shrink the __text section size here
1074 self.last_text_block = text_block.prev;1074 self.last_text_block = text_block.prev;
1075 }1075 }
1076 if (self.d_sym) |*ds| {
1077 if (ds.dbg_info_decl_first == text_block) {
1078 ds.dbg_info_decl_first = text_block.dbg_info_next;
1079 }
1080 if (ds.dbg_info_decl_last == text_block) {
1081 // TODO shrink the .debug_info section size here
1082 ds.dbg_info_decl_last = text_block.dbg_info_prev;
1083 }
1084 }
10761085
1077 if (text_block.prev) |prev| {1086 if (text_block.prev) |prev| {
1078 prev.next = text_block.next;1087 prev.next = text_block.next;
...@@ -1091,6 +1100,20 @@ fn freeTextBlock(self: *MachO, text_block: *TextBlock) void {...@@ -1091,6 +1100,20 @@ fn freeTextBlock(self: *MachO, text_block: *TextBlock) void {
1091 } else {1100 } else {
1092 text_block.next = null;1101 text_block.next = null;
1093 }1102 }
1103
1104 if (text_block.dbg_info_prev) |prev| {
1105 prev.dbg_info_next = text_block.dbg_info_next;
1106
1107 // TODO the free list logic like we do for text blocks above
1108 } else {
1109 text_block.dbg_info_prev = null;
1110 }
1111
1112 if (text_block.dbg_info_next) |next| {
1113 next.dbg_info_prev = text_block.dbg_info_prev;
1114 } else {
1115 text_block.dbg_info_next = null;
1116 }
1094}1117}
10951118
1096fn shrinkTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64) void {1119fn shrinkTextBlock(self: *MachO, text_block: *TextBlock, new_block_size: u64) void {
...@@ -1477,6 +1500,29 @@ pub fn freeDecl(self: *MachO, decl: *Module.Decl) void {...@@ -1477,6 +1500,29 @@ pub fn freeDecl(self: *MachO, decl: *Module.Decl) void {
14771500
1478 decl.link.macho.local_sym_index = 0;1501 decl.link.macho.local_sym_index = 0;
1479 }1502 }
1503 if (self.d_sym) |*ds| {
1504 // TODO make this logic match freeTextBlock. Maybe abstract the logic
1505 // out since the same thing is desired for both.
1506 _ = ds.dbg_line_fn_free_list.remove(&decl.fn_link.macho);
1507 if (decl.fn_link.macho.prev) |prev| {
1508 ds.dbg_line_fn_free_list.put(self.base.allocator, prev, {}) catch {};
1509 prev.next = decl.fn_link.macho.next;
1510 if (decl.fn_link.macho.next) |next| {
1511 next.prev = prev;
1512 } else {
1513 ds.dbg_line_fn_last = prev;
1514 }
1515 } else if (decl.fn_link.macho.next) |next| {
1516 ds.dbg_line_fn_first = next;
1517 next.prev = null;
1518 }
1519 if (ds.dbg_line_fn_first == &decl.fn_link.macho) {
1520 ds.dbg_line_fn_first = decl.fn_link.macho.next;
1521 }
1522 if (ds.dbg_line_fn_last == &decl.fn_link.macho) {
1523 ds.dbg_line_fn_last = decl.fn_link.macho.prev;
1524 }
1525 }
1480}1526}
14811527
1482pub fn getDeclVAddr(self: *MachO, decl: *const Module.Decl) u64 {1528pub fn getDeclVAddr(self: *MachO, decl: *const Module.Decl) u64 {