diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-10-24 16:48:15 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-10-24 23:30:57 -0700 |
| commit | b3cd38ea4a7520fabbb05d3d2e74351c7c8effdb (patch) | |
| tree | 51a821b640352c1967490e96165e2d5abbd94c2b /src/link/MachO | |
| parent | 4f04759c874d5fd41c7cadeb974b4459559bc2a7 (diff) | |
| download | zig-b3cd38ea4a7520fabbb05d3d2e74351c7c8effdb.tar.gz zig-b3cd38ea4a7520fabbb05d3d2e74351c7c8effdb.zip | |
link: add an explicit error set for flush() and flushModule()
This makes it easier to understand how control flow should happen in
various cases; already just by doing this it is revealed that
UndefinedSymbol and UndefinedSymbolReference should be merged, and that
MissingMainEntrypoint should be removed in favor of the ErrorFlags
mechanism thath we already have for missing the main entrypoint.
The main motivation for this change, however, is preventing a compile
error when there is conditional compilation inside linker
implementations, causing the flush() error set to depend on compilation
options. With this change, the error set is fixed, and, notably, the
`-Donly-c` flag no longer has compilation errors due to this error set.
Diffstat (limited to 'src/link/MachO')
| -rw-r--r-- | src/link/MachO/dead_strip.zig | 24 | ||||
| -rw-r--r-- | src/link/MachO/zld.zig | 2 |
2 files changed, 13 insertions, 13 deletions
diff --git a/src/link/MachO/dead_strip.zig b/src/link/MachO/dead_strip.zig index 6090162ce8..c3af7a19d8 100644 --- a/src/link/MachO/dead_strip.zig +++ b/src/link/MachO/dead_strip.zig @@ -17,7 +17,7 @@ const N_DEAD = @import("zld.zig").N_DEAD; const AtomTable = std.AutoHashMap(AtomIndex, void); -pub fn gcAtoms(zld: *Zld, reverse_lookups: [][]u32) !void { +pub fn gcAtoms(zld: *Zld, reverse_lookups: [][]u32) Allocator.Error!void { const gpa = zld.gpa; var arena = std.heap.ArenaAllocator.init(gpa); @@ -30,8 +30,8 @@ pub fn gcAtoms(zld: *Zld, reverse_lookups: [][]u32) !void { try alive.ensureTotalCapacity(@intCast(u32, zld.atoms.items.len)); try collectRoots(zld, &roots); - try mark(zld, roots, &alive, reverse_lookups); - try prune(zld, alive); + mark(zld, roots, &alive, reverse_lookups); + prune(zld, alive); } fn collectRoots(zld: *Zld, roots: *AtomTable) !void { @@ -133,7 +133,7 @@ fn markLive( atom_index: AtomIndex, alive: *AtomTable, reverse_lookups: [][]u32, -) anyerror!void { +) void { if (alive.contains(atom_index)) return; const atom = zld.getAtom(atom_index); @@ -171,7 +171,7 @@ fn markLive( const other_atom = zld.getAtom(other_atom_index); const other_sym = zld.getSymbol(other_atom.getSymbolWithLoc()); if (other_sym.n_sect == sect_id) { - try markLive(zld, other_atom_index, alive, reverse_lookups); + markLive(zld, other_atom_index, alive, reverse_lookups); } } continue; @@ -194,11 +194,11 @@ fn markLive( zld.getAtom(target_atom_index).file, }); - try markLive(zld, target_atom_index, alive, reverse_lookups); + markLive(zld, target_atom_index, alive, reverse_lookups); } } -fn refersLive(zld: *Zld, atom_index: AtomIndex, alive: AtomTable, reverse_lookups: [][]u32) !bool { +fn refersLive(zld: *Zld, atom_index: AtomIndex, alive: AtomTable, reverse_lookups: [][]u32) bool { const atom = zld.getAtom(atom_index); const sym_loc = atom.getSymbolWithLoc(); @@ -240,10 +240,10 @@ fn refersLive(zld: *Zld, atom_index: AtomIndex, alive: AtomTable, reverse_lookup return false; } -fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable, reverse_lookups: [][]u32) !void { +fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable, reverse_lookups: [][]u32) void { var it = roots.keyIterator(); while (it.next()) |root| { - try markLive(zld, root.*, alive, reverse_lookups); + markLive(zld, root.*, alive, reverse_lookups); } var loop: bool = true; @@ -265,8 +265,8 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable, reverse_lookups: [][]u32 const source_sect = object.getSourceSection(sect_id); if (source_sect.isDontDeadStripIfReferencesLive()) { - if (try refersLive(zld, atom_index, alive.*, reverse_lookups)) { - try markLive(zld, atom_index, alive, reverse_lookups); + if (refersLive(zld, atom_index, alive.*, reverse_lookups)) { + markLive(zld, atom_index, alive, reverse_lookups); loop = true; } } @@ -275,7 +275,7 @@ fn mark(zld: *Zld, roots: AtomTable, alive: *AtomTable, reverse_lookups: [][]u32 } } -fn prune(zld: *Zld, alive: AtomTable) !void { +fn prune(zld: *Zld, alive: AtomTable) void { log.debug("pruning dead atoms", .{}); for (zld.objects.items) |*object| { var i: usize = 0; diff --git a/src/link/MachO/zld.zig b/src/link/MachO/zld.zig index 8d599e0185..20917a80c5 100644 --- a/src/link/MachO/zld.zig +++ b/src/link/MachO/zld.zig @@ -3735,7 +3735,7 @@ const SymbolResolver = struct { unresolved: std.AutoArrayHashMap(u32, void), }; -pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) !void { +pub fn linkWithZld(macho_file: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void { const tracy = trace(@src()); defer tracy.end(); |
