Skip to content

Commit f2dcfe0

Browse files
committed
link.File.Wasm: parse inputs in compilation pipeline
Primarily, this moves linker input parsing from flush() into the linker task queue, which is executed simultaneously with the frontend. I also made it avoid redundantly opening the same archive file N times for each object file inside. Furthermore, hard code fixed buffer stream rather than using a generic stream type. Finally, I fixed the error handling of the Wasm.Archive.parse function. Please pay attention to this pattern of returning a struct rather than accepting a mutable struct as an argument. This ensures function-level atomicity and makes resource management straightforward. Deletes the file and path fields from Archive and Object. Removed a well-meaning but ultimately misguided suggestion about how to think about ZigObject since thinking about it that way has led to problematic anti-DOD patterns.
1 parent f5ade5e commit f2dcfe0

File tree

6 files changed

+735
-840
lines changed

6 files changed

+735
-840
lines changed

src/link.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ pub const File = struct {
10851085
const use_lld = build_options.have_llvm and base.comp.config.use_lld;
10861086
if (use_lld) return;
10871087
switch (base.tag) {
1088-
inline .elf => |tag| {
1088+
inline .elf, .wasm => |tag| {
10891089
dev.check(tag.devFeature());
10901090
return @as(*tag.Type(), @fieldParentPtr("base", base)).loadInput(input);
10911091
},

src/link/Elf.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,8 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod
823823
const sub_prog_node = prog_node.start("ELF Flush", 0);
824824
defer sub_prog_node.end();
825825

826-
const directory = self.base.emit.root_dir; // Just an alias to make it shorter to type.
827826
const module_obj_path: ?Path = if (self.base.zcu_object_sub_path) |path| .{
828-
.root_dir = directory,
827+
.root_dir = self.base.emit.root_dir,
829828
.sub_path = if (fs.path.dirname(self.base.emit.sub_path)) |dirname|
830829
try fs.path.join(arena, &.{ dirname, path })
831830
else
@@ -1104,7 +1103,7 @@ fn dumpArgvInit(self: *Elf, arena: Allocator) !void {
11041103
pub fn openParseObjectReportingFailure(self: *Elf, path: Path) void {
11051104
const diags = &self.base.comp.link_diags;
11061105
const obj = link.openObject(path, false, false) catch |err| {
1107-
switch (diags.failParse(path, "failed to open object {}: {s}", .{ path, @errorName(err) })) {
1106+
switch (diags.failParse(path, "failed to open object: {s}", .{@errorName(err)})) {
11081107
error.LinkFailure => return,
11091108
}
11101109
};

0 commit comments

Comments
 (0)