aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/Object.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2022-07-12 23:03:15 +0200
committerJakub Konka <kubkon@jakubkonka.com>2022-07-22 16:58:20 +0200
commitd80fcc8a0b5594a6eb0fb409f4e5e5f949eec2fe (patch)
tree16dea5f36353ee793855006437134316969495e5 /src/link/MachO/Object.zig
parenteeb6d8f0457b42cef560c1e4efeca69c0fe276fe (diff)
downloadzig-d80fcc8a0b5594a6eb0fb409f4e5e5f949eec2fe.tar.gz
zig-d80fcc8a0b5594a6eb0fb409f4e5e5f949eec2fe.zip
macho: rework symbol handling for incremental stage2 builds
Diffstat (limited to 'src/link/MachO/Object.zig')
-rw-r--r--src/link/MachO/Object.zig30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig
index 7170e8efdb..91e2169b7d 100644
--- a/src/link/MachO/Object.zig
+++ b/src/link/MachO/Object.zig
@@ -270,7 +270,7 @@ const SymbolAtIndex = struct {
fn getSymbolName(self: SymbolAtIndex, ctx: Context) []const u8 {
const sym = self.getSymbol(ctx);
- if (sym.n_strx == 0) return "";
+ assert(sym.n_strx < ctx.strtab.len);
return mem.sliceTo(@ptrCast([*:0]const u8, ctx.strtab.ptr + sym.n_strx), 0);
}
@@ -359,15 +359,17 @@ fn filterDice(
return dices[start..end];
}
-/// Splits object into atoms assuming whole cache mode aka traditional linking mode.
-pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !void {
+/// Splits object into atoms assuming one-shot linking mode.
+pub fn splitIntoAtomsOneShot(self: *Object, macho_file: *MachO, object_id: u32) !void {
+ assert(macho_file.mode == .one_shot);
+
const tracy = trace(@src());
defer tracy.end();
const gpa = macho_file.base.allocator;
const seg = self.load_commands.items[self.segment_cmd_index.?].segment;
- log.debug("splitting object({d}, {s}) into atoms: whole cache mode", .{ object_id, self.name });
+ log.debug("splitting object({d}, {s}) into atoms: one-shot mode", .{ object_id, self.name });
// You would expect that the symbol table is at least pre-sorted based on symbol's type:
// local < extern defined < undefined. Unfortunately, this is not guaranteed! For instance,
@@ -416,11 +418,11 @@ pub fn splitIntoAtomsWhole(self: *Object, macho_file: *MachO, object_id: u32) !v
log.debug(" unhandled section", .{});
continue;
};
- const target_sect = macho_file.getSection(match);
+
log.debug(" output sect({d}, '{s},{s}')", .{
macho_file.getSectionOrdinal(match),
- target_sect.segName(),
- target_sect.sectName(),
+ macho_file.getSection(match).segName(),
+ macho_file.getSection(match).sectName(),
});
const is_zerofill = blk: {
@@ -585,10 +587,19 @@ fn createAtomFromSubsection(
sect: macho.section_64,
) !*Atom {
const gpa = macho_file.base.allocator;
- const sym = &self.symtab.items[sym_index];
+ const sym = self.symtab.items[sym_index];
const atom = try MachO.createEmptyAtom(gpa, sym_index, size, alignment);
atom.file = object_id;
- sym.n_sect = macho_file.getSectionOrdinal(match);
+ self.symtab.items[sym_index].n_sect = macho_file.getSectionOrdinal(match);
+
+ log.debug("creating ATOM(%{d}, '{s}') in sect({d}, '{s},{s}') in object({d})", .{
+ sym_index,
+ self.getString(sym.n_strx),
+ macho_file.getSectionOrdinal(match),
+ macho_file.getSection(match).segName(),
+ macho_file.getSection(match).sectName(),
+ object_id,
+ });
try self.atom_by_index_table.putNoClobber(gpa, sym_index, atom);
try self.managed_atoms.append(gpa, atom);
@@ -669,7 +680,6 @@ fn createAtomFromSubsection(
// if (zld.globals.contains(zld.getString(sym.strx))) break :blk .global;
break :blk .static;
} else null;
-
atom.contained.appendAssumeCapacity(.{
.sym_index = inner_sym_index.index,
.offset = inner_sym.n_value - sym.n_value,