authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2023-07-16 21:10:49-04:00
committergravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2023-08-02 17:39:52-04:00
log4d711e8edd1234e727ba7e801b71090dc885249e
tree3c687750c2908c7655160e2daa9d9eb1f46edc57
parentb9aa1dcaf1a905682ee4da6b9c37626ed2a552a6

Plan 9 linker: don't try to calculate the vaddr before we know it

Previously, this worked on small codebases, but it is not correct. Unconditionally emitting a reloc fixes it (and it might be more performant).

1 files changed, 1 insertions(+), 20 deletions(-)

src/link/Plan9.zig+1-20
...@@ -1407,26 +1407,7 @@ pub fn getDeclVAddr(...@@ -1407,26 +1407,7 @@ pub fn getDeclVAddr(
1407 // TODO handle other extern variables and functions1407 // TODO handle other extern variables and functions
1408 return undefined;1408 return undefined;
1409 }1409 }
1410 // we might already know the vaddr1410 // otherwise, we just add a relocation
1411 if (decl.ty.zigTypeTag(mod) == .Fn) {
1412 var start = self.bases.text;
1413 var it_file = self.fn_decl_table.iterator();
1414 while (it_file.next()) |fentry| {
1415 var symidx_and_submap = fentry.value_ptr;
1416 var submap_it = symidx_and_submap.functions.iterator();
1417 while (submap_it.next()) |entry| {
1418 if (entry.key_ptr.* == decl_index) return start;
1419 start += entry.value_ptr.code.len;
1420 }
1421 }
1422 } else {
1423 var start = self.bases.data + self.got_len * if (!self.sixtyfour_bit) @as(u32, 4) else 8;
1424 var it = self.data_decl_table.iterator();
1425 while (it.next()) |kv| {
1426 if (decl_index == kv.key_ptr.*) return start;
1427 start += kv.value_ptr.len;
1428 }
1429 }
1430 const atom_index = try self.seeDecl(decl_index);1411 const atom_index = try self.seeDecl(decl_index);
1431 // the parent_atom_index in this case is just the decl_index of the parent1412 // the parent_atom_index in this case is just the decl_index of the parent
1432 try self.addReloc(reloc_info.parent_atom_index, .{1413 try self.addReloc(reloc_info.parent_atom_index, .{