aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/relocatable.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2024-11-04 17:26:17 -0800
committerAndrew Kelley <andrew@ziglang.org>2025-01-15 15:11:35 -0800
commit795e7c64d5f67006246d172e5cd58233cb76f05e (patch)
tree7d376eeb11a443a0861a360c9447f28a58bb618e /src/link/MachO/relocatable.zig
parent77273103a8f9895ceab28287dffcf4d4c6fcb91b (diff)
downloadzig-795e7c64d5f67006246d172e5cd58233cb76f05e.tar.gz
zig-795e7c64d5f67006246d172e5cd58233cb76f05e.zip
wasm linker: aggressive DODification
The goals of this branch are to: * compile faster when using the wasm linker and backend * enable saving compiler state by directly copying in-memory linker state to disk. * more efficient compiler memory utilization * introduce integer type safety to wasm linker code * generate better WebAssembly code * fully participate in incremental compilation * do as much work as possible outside of flush(), while continuing to do linker garbage collection. * avoid unnecessary heap allocations * avoid unnecessary indirect function calls In order to accomplish this goals, this removes the ZigObject abstraction, as well as Symbol and Atom. These abstractions resulted in overly generic code, doing unnecessary work, and needless complications that simply go away by creating a better in-memory data model and emitting more things lazily. For example, this makes wasm codegen emit MIR which is then lowered to wasm code during linking, with optimal function indexes etc, or relocations are emitted if outputting an object. Previously, this would always emit relocations, which are fully unnecessary when emitting an executable, and required all function calls to use the maximum size LEB encoding. This branch introduces the concept of the "prelink" phase which occurs after all object files have been parsed, but before any Zcu updates are sent to the linker. This allows the linker to fully parse all objects into a compact memory model, which is guaranteed to be complete when Zcu code is generated. This commit is not a complete implementation of all these goals; it is not even passing semantic analysis.
Diffstat (limited to 'src/link/MachO/relocatable.zig')
-rw-r--r--src/link/MachO/relocatable.zig10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/link/MachO/relocatable.zig b/src/link/MachO/relocatable.zig
index 497969ab90..b8e05e333a 100644
--- a/src/link/MachO/relocatable.zig
+++ b/src/link/MachO/relocatable.zig
@@ -33,11 +33,11 @@ pub fn flushObject(macho_file: *MachO, comp: *Compilation, module_obj_path: ?Pat
diags.addParseError(link_input.path().?, "failed to read input file: {s}", .{@errorName(err)});
}
- if (diags.hasErrors()) return error.FlushFailure;
+ if (diags.hasErrors()) return error.LinkFailure;
try macho_file.parseInputFiles();
- if (diags.hasErrors()) return error.FlushFailure;
+ if (diags.hasErrors()) return error.LinkFailure;
try macho_file.resolveSymbols();
try macho_file.dedupLiterals();
@@ -93,11 +93,11 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?
diags.addParseError(link_input.path().?, "failed to read input file: {s}", .{@errorName(err)});
}
- if (diags.hasErrors()) return error.FlushFailure;
+ if (diags.hasErrors()) return error.LinkFailure;
try parseInputFilesAr(macho_file);
- if (diags.hasErrors()) return error.FlushFailure;
+ if (diags.hasErrors()) return error.LinkFailure;
// First, we flush relocatable object file generated with our backends.
if (macho_file.getZigObject()) |zo| {
@@ -218,7 +218,7 @@ pub fn flushStaticLib(macho_file: *MachO, comp: *Compilation, module_obj_path: ?
try macho_file.base.file.?.setEndPos(total_size);
try macho_file.base.file.?.pwriteAll(buffer.items, 0);
- if (diags.hasErrors()) return error.FlushFailure;
+ if (diags.hasErrors()) return error.LinkFailure;
}
fn parseInputFilesAr(macho_file: *MachO) !void {