aboutsummaryrefslogtreecommitdiff
path: root/src/link/Wasm.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-01-02 20:57:04 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-01-03 14:49:35 -0700
commitd94303be2bcee33e7efba22a186fd06eaa809707 (patch)
tree883b8f12094809995e885658652e9c43334def23 /src/link/Wasm.zig
parent663ffa5a7a1d53d1adf9c1ea6991aad8bf82aadc (diff)
downloadzig-d94303be2bcee33e7efba22a186fd06eaa809707.tar.gz
zig-d94303be2bcee33e7efba22a186fd06eaa809707.zip
stage2: introduce renameTmpIntoCache into the linker API
Doc comments reproduced here: This function is called by the frontend before flush(). It communicates that `options.bin_file.emit` directory needs to be renamed from `[zig-cache]/tmp/[random]` to `[zig-cache]/o/[digest]`. The frontend would like to simply perform a file system rename, however, some linker backends care about the file paths of the objects they are linking. So this function call tells linker backends to rename the paths of object files to observe the new directory path. Linker backends which do not have this requirement can fall back to the simple implementation at the bottom of this function. This function is only called when CacheMode is `whole`. This solves stack trace regressions on Windows and macOS because the linker backends do not observe object file paths until flush().
Diffstat (limited to 'src/link/Wasm.zig')
-rw-r--r--src/link/Wasm.zig22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig
index 5f8f48d1b1..220ab2f53c 100644
--- a/src/link/Wasm.zig
+++ b/src/link/Wasm.zig
@@ -1050,6 +1050,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
const arena = arena_allocator.allocator();
const directory = self.base.options.emit.?.directory; // Just an alias to make it shorter to type.
+ const full_out_path = try directory.join(arena, &[_][]const u8{self.base.options.emit.?.sub_path});
// If there is no Zig code to compile, then we should skip flushing the output file because it
// will not be part of the linker line anyway.
@@ -1061,15 +1062,22 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
.target = self.base.options.target,
.output_mode = .Obj,
});
- const o_directory = module.zig_cache_artifact_directory;
- const full_obj_path = try o_directory.join(arena, &[_][]const u8{obj_basename});
- break :blk full_obj_path;
+ switch (self.base.options.cache_mode) {
+ .incremental => break :blk try module.zig_cache_artifact_directory.join(
+ arena,
+ &[_][]const u8{obj_basename},
+ ),
+ .whole => break :blk try fs.path.join(arena, &.{
+ fs.path.dirname(full_out_path).?, obj_basename,
+ }),
+ }
}
try self.flushModule(comp);
- const obj_basename = self.base.intermediary_basename.?;
- const full_obj_path = try directory.join(arena, &[_][]const u8{obj_basename});
- break :blk full_obj_path;
+
+ break :blk try fs.path.join(arena, &.{
+ fs.path.dirname(full_out_path).?, self.base.intermediary_basename.?,
+ });
} else null;
const is_obj = self.base.options.output_mode == .Obj;
@@ -1143,8 +1151,6 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void {
};
}
- const full_out_path = try directory.join(arena, &[_][]const u8{self.base.options.emit.?.sub_path});
-
if (self.base.options.output_mode == .Obj) {
// LLD's WASM driver does not support the equivalent of `-r` so we do a simple file copy
// here. TODO: think carefully about how we can avoid this redundant operation when doing