authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-12 18:07:10+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-12 18:07:10+02:00
log652ebf3b6a62007d37fb7fd4def393f11bb6159f
treea0202d6cae5600d701bfbcbd960924716a062618
parent9db472cff6573fd1d0f50c8ea1b5ecb536aeff1e

elf: allocate objects, currently atom-by-atom


1 files changed, 17 insertions(+), 3 deletions(-)

src/link/Elf.zig+17-3
...@@ -1053,7 +1053,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1053,7 +1053,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1053 try self.scanRelocs();1053 try self.scanRelocs();
10541054
1055 // Allocate atoms parsed from input object files1055 // Allocate atoms parsed from input object files
1056 self.allocateObjects();1056 try self.allocateObjects();
1057 self.allocateLinkerDefinedSymbols();1057 self.allocateLinkerDefinedSymbols();
10581058
1059 // Beyond this point, everything has been allocated a virtual address and we can resolve1059 // Beyond this point, everything has been allocated a virtual address and we can resolve
...@@ -1405,8 +1405,22 @@ fn scanRelocs(self: *Elf) !void {...@@ -1405,8 +1405,22 @@ fn scanRelocs(self: *Elf) !void {
1405 }1405 }
1406}1406}
14071407
1408fn allocateObjects(self: *Elf) void {1408fn allocateObjects(self: *Elf) !void {
1409 _ = self;1409 for (self.objects.items) |index| {
1410 const object = self.file(index).?.object;
1411 for (object.atoms.items) |atom_index| {
1412 const atom_ptr = self.atom(atom_index) orelse continue;
1413 if (!atom_ptr.alive) continue;
1414 try atom_ptr.allocate(self);
1415 }
1416
1417 for (object.globals()) |global_index| {
1418 const global = self.symbol(global_index);
1419 if (global.file_index == index) {
1420 global.value = global.atom(self).?.value;
1421 }
1422 }
1423 }
1410}1424}
14111425
1412fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !void {1426fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !void {