elf: init objects after parsing them

This commit is contained in:
Jakub Konka 2023-11-05 12:37:15 +01:00
parent 8d7ec05070
commit 5c48236103
3 changed files with 14 additions and 15 deletions

View File

@ -1286,8 +1286,6 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
try positionals.append(.{ .path = ssp.full_object_path });
}
if (self.isStaticLib()) return self.flushStaticLib(comp, positionals.items);
for (positionals.items) |obj| {
var parse_ctx: ParseErrorCtx = .{ .detected_cpu_arch = undefined };
self.parsePositional(obj.path, obj.must_link, &parse_ctx) catch |err|
@ -1393,6 +1391,16 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
try self.handleAndReportParseError(obj.path, err, &parse_ctx);
}
if (self.isStaticLib()) return self.flushStaticLib(comp);
// Init all objects
for (self.objects.items) |index| {
try self.file(index).?.object.init(self);
}
for (self.shared_objects.items) |index| {
try self.file(index).?.shared_object.init(self);
}
// Dedup shared objects
{
var seen_dsos = std.StringHashMap(void).init(gpa);
@ -1522,18 +1530,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
}
}
pub fn flushStaticLib(
self: *Elf,
comp: *Compilation,
positionals: []const Compilation.LinkObject,
) link.File.FlushError!void {
pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void {
_ = comp;
if (positionals.len > 0) {
var err = try self.addErrorWithNotes(1);
try err.addMsg(self, "fatal linker error: too many input positionals", .{});
try err.addNote(self, "TODO implement linking objects into an static library", .{});
return;
}
const gpa = self.base.allocator;
// First, we flush relocatable object file generated with our backends.

View File

@ -96,7 +96,9 @@ pub fn parse(self: *Object, elf_file: *Elf) !void {
sym.st_name + strtab_bias;
}
}
}
pub fn init(self: *Object, elf_file: *Elf) !void {
try self.initAtoms(elf_file);
try self.initSymtab(elf_file);

View File

@ -72,7 +72,6 @@ pub fn parse(self: *SharedObject, elf_file: *Elf) !void {
}
try self.parseVersions(elf_file);
try self.initSymtab(elf_file);
}
fn parseVersions(self: *SharedObject, elf_file: *Elf) !void {
@ -120,7 +119,7 @@ fn parseVersions(self: *SharedObject, elf_file: *Elf) !void {
}
}
fn initSymtab(self: *SharedObject, elf_file: *Elf) !void {
pub fn init(self: *SharedObject, elf_file: *Elf) !void {
const gpa = elf_file.base.allocator;
const symtab = self.getSymtabRaw();
const strtab = self.getStrtabRaw();