Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Archive.zig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
objects: std.ArrayListUnmanaged(Object) = .{},
objects: std.ArrayListUnmanaged(Object) = .empty,

// Archive files start with the ARMAG identifying string. Then follows a
// `struct ar_hdr', and as many bytes of member file data as its `ar_size'
Expand Down
34 changes: 23 additions & 11 deletions src/Atom.zig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ n_sect: u32 = 0,
value: u64 = 0,

/// Name of this Atom.
name: MachO.String = .{},
name: MachO.String = .init,

/// Index of the output section.
out_n_sect: u8 = 0,
Expand Down Expand Up @@ -312,7 +312,7 @@ fn reportUndefSymbol(self: Atom, rel: Relocation, macho_file: *MachO) !bool {
const gpa = macho_file.allocator;
const gop = try macho_file.undefs.getOrPut(gpa, file.getGlobals()[@intFromEnum(rel.target.symbol)]); // TODO unsafe
if (!gop.found_existing) {
gop.value_ptr.* = .{ .atom_refs = .{} };
gop.value_ptr.* = .{ .atom_refs = .empty };
}
try gop.value_ptr.atom_refs.append(gpa, self.atom_index.toRef(self.file));
return true;
Expand Down Expand Up @@ -950,31 +950,43 @@ pub const UnwrappedRef = struct {

pub const Extra = struct {
/// Index of the range extension thunk of this atom.
thunk: u32 = 0,
thunk: u32,

/// Start index of relocations belonging to this atom.
rel_index: u32 = 0,
rel_index: u32,

/// Count of relocations belonging to this atom.
rel_count: u32 = 0,
rel_count: u32,

/// Start index of relocations being written out to file for this atom.
rel_out_index: u32 = 0,
rel_out_index: u32,

/// Count of relocations written out to file for this atom.
rel_out_count: u32 = 0,
rel_out_count: u32,

/// Start index of relocations belonging to this atom.
unwind_index: u32 = 0,
unwind_index: u32,

/// Count of relocations belonging to this atom.
unwind_count: u32 = 0,
unwind_count: u32,

/// Index into LiteralPool entry for this atom.
literal_pool_index: u32 = 0,
literal_pool_index: u32,

/// Index into the File's symbol table for local symbol representing this literal atom.
literal_symbol_index: u32 = 0,
literal_symbol_index: u32,

pub const init: Extra = .{
.thunk = 0,
.rel_index = 0,
.rel_count = 0,
.rel_out_index = 0,
.rel_out_count = 0,
.unwind_index = 0,
.unwind_count = 0,
.literal_pool_index = 0,
.literal_symbol_index = 0,
};
};

const aarch64 = @import("aarch64.zig");
Expand Down
2 changes: 1 addition & 1 deletion src/CodeSignature.zig
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const CodeDirectory = struct {
inner: macho.CodeDirectory,
ident: []const u8,
special_slots: [n_special_slots][hash_size]u8,
code_slots: std.ArrayListUnmanaged([hash_size]u8) = .{},
code_slots: std.ArrayListUnmanaged([hash_size]u8) = .empty,

const n_special_slots: usize = 7;

Expand Down
22 changes: 11 additions & 11 deletions src/Dylib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ index: File.Index,
file_handle: ?File.HandleIndex = null,
lib_stub: ?LibStub = null,

exports: std.MultiArrayList(Export) = .{},
strtab: std.ArrayListUnmanaged(u8) = .{},
exports: std.MultiArrayList(Export) = .empty,
strtab: std.ArrayListUnmanaged(u8) = .empty,
id: ?Id = null,
ordinal: u16 = 0,

symbols: std.ArrayListUnmanaged(Symbol) = .{},
symbols_extra: std.ArrayListUnmanaged(u32) = .{},
globals: std.ArrayListUnmanaged(MachO.SymbolResolver.Index) = .{},
dependents: std.ArrayListUnmanaged(Id) = .{},
rpaths: std.StringArrayHashMapUnmanaged(void) = .{},
symbols: std.ArrayListUnmanaged(Symbol) = .empty,
symbols_extra: std.ArrayListUnmanaged(u32) = .empty,
globals: std.ArrayListUnmanaged(MachO.SymbolResolver.Index) = .empty,
dependents: std.ArrayListUnmanaged(Id) = .empty,
rpaths: std.StringArrayHashMapUnmanaged(void) = .empty,
umbrella: File.Index,

needed: bool,
Expand All @@ -24,7 +24,7 @@ explicit: bool,
hoisted: bool = true,
referenced: bool = false,

output_symtab_ctx: MachO.SymtabCtx = .{},
output_symtab_ctx: MachO.SymtabCtx = .init,

pub fn deinit(self: *Dylib, allocator: Allocator) void {
if (self.lib_stub) |*ls| ls.deinit();
Expand Down Expand Up @@ -216,7 +216,7 @@ pub fn addExport(self: *Dylib, allocator: Allocator, name: []const u8, flags: Ex
const index = try self.addSymbol(allocator);
const symbol = &self.symbols.items[@intFromEnum(index)];
symbol.name = str;
symbol.extra = try self.addSymbolExtra(allocator, .{});
symbol.extra = try self.addSymbolExtra(allocator, .init);
symbol.flags.weak = flags.weak;
symbol.flags.tlv = flags.tlv;
symbol.visibility = .global;
Expand Down Expand Up @@ -616,7 +616,7 @@ fn initSymbols(self: *Dylib, macho_file: *MachO) !void {
const index = self.addSymbolAssumeCapacity();
const symbol = &self.symbols.items[@intFromEnum(index)];
symbol.name = noff;
symbol.extra = self.addSymbolExtraAssumeCapacity(.{});
symbol.extra = self.addSymbolExtraAssumeCapacity(.init);
symbol.flags.weak = flags.weak;
symbol.flags.tlv = flags.tlv;
symbol.visibility = .global;
Expand Down Expand Up @@ -842,7 +842,7 @@ pub const TargetMatcher = struct {
allocator: Allocator,
cpu_arch: std.Target.Cpu.Arch,
platform: macho.PLATFORM,
target_strings: std.ArrayListUnmanaged([]const u8) = .{},
target_strings: std.ArrayListUnmanaged([]const u8) = .empty,

pub fn init(allocator: Allocator, cpu_arch: std.Target.Cpu.Arch, platform: macho.PLATFORM) !TargetMatcher {
var self = TargetMatcher{
Expand Down
40 changes: 20 additions & 20 deletions src/InternalObject.zig
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
index: File.Index,

sections: std.MultiArrayList(Section) = .{},
atoms: std.ArrayListUnmanaged(Atom) = .{},
atoms_indexes: std.ArrayListUnmanaged(Atom.Index) = .{},
atoms_extra: std.ArrayListUnmanaged(u32) = .{},
symtab: std.ArrayListUnmanaged(macho.nlist_64) = .{},
strtab: std.ArrayListUnmanaged(u8) = .{},
symbols: std.ArrayListUnmanaged(Symbol) = .{},
symbols_extra: std.ArrayListUnmanaged(u32) = .{},
globals: std.ArrayListUnmanaged(MachO.SymbolResolver.Index) = .{},

objc_methnames: std.ArrayListUnmanaged(u8) = .{},
sections: std.MultiArrayList(Section) = .empty,
atoms: std.ArrayListUnmanaged(Atom) = .empty,
atoms_indexes: std.ArrayListUnmanaged(Atom.Index) = .empty,
atoms_extra: std.ArrayListUnmanaged(u32) = .empty,
symtab: std.ArrayListUnmanaged(macho.nlist_64) = .empty,
strtab: std.ArrayListUnmanaged(u8) = .empty,
symbols: std.ArrayListUnmanaged(Symbol) = .empty,
symbols_extra: std.ArrayListUnmanaged(u32) = .empty,
globals: std.ArrayListUnmanaged(MachO.SymbolResolver.Index) = .empty,

objc_methnames: std.ArrayListUnmanaged(u8) = .empty,
objc_selrefs: [@sizeOf(u64)]u8 = [_]u8{0} ** @sizeOf(u64),

force_undefined: std.ArrayListUnmanaged(Symbol.Index) = .{},
force_undefined: std.ArrayListUnmanaged(Symbol.Index) = .empty,
entry_index: ?Symbol.Index = null,
dyld_stub_binder_index: ?Symbol.Index = null,
dyld_private_index: ?Symbol.Index = null,
objc_msg_send_index: ?Symbol.Index = null,
mh_execute_header_index: ?Symbol.Index = null,
mh_dylib_header_index: ?Symbol.Index = null,
dso_handle_index: ?Symbol.Index = null,
boundary_symbols: std.ArrayListUnmanaged(Symbol.Index) = .{},
boundary_symbols: std.ArrayListUnmanaged(Symbol.Index) = .empty,

output_symtab_ctx: MachO.SymtabCtx = .{},
output_symtab_ctx: MachO.SymtabCtx = .init,

pub fn deinit(self: *InternalObject, allocator: Allocator) void {
for (self.sections.items(.relocs)) |*relocs| {
Expand Down Expand Up @@ -57,7 +57,7 @@ pub fn initSymbols(self: *InternalObject, macho_file: *MachO) !void {
const index = obj.addSymbolAssumeCapacity();
const symbol = &obj.symbols.items[@intFromEnum(index)];
symbol.name = name;
symbol.extra = obj.addSymbolExtraAssumeCapacity(.{});
symbol.extra = obj.addSymbolExtraAssumeCapacity(.init);
symbol.flags.dyn_ref = args.desc & macho.REFERENCED_DYNAMICALLY != 0;
symbol.visibility = if (args.type & macho.N_EXT != 0) blk: {
break :blk if (args.type & macho.N_PEXT != 0) .hidden else .global;
Expand Down Expand Up @@ -211,7 +211,7 @@ pub fn resolveBoundarySymbols(self: *InternalObject, macho_file: *MachO) !void {
.n_value = 0,
};
sym.nlist_idx = nlist_idx;
sym.extra = self.addSymbolExtraAssumeCapacity(.{});
sym.extra = self.addSymbolExtraAssumeCapacity(.init);

const idx = ref.getFile(macho_file).object.globals.items[@intFromEnum(ref.symbol)];
self.globals.addOneAssumeCapacity().* = idx;
Expand Down Expand Up @@ -266,7 +266,7 @@ fn addObjcMethnameSection(self: *InternalObject, methname: []const u8, macho_fil
const sym = &self.symbols.items[@intFromEnum(sym_index)];
sym.name = name_str;
sym.atom_ref = atom_index.toRef(self.index);
sym.extra = try self.addSymbolExtra(gpa, .{});
sym.extra = try self.addSymbolExtra(gpa, .init);
const nlist_idx: u32 = @intCast(self.symtab.items.len);
const nlist = try self.symtab.addOne(gpa);
nlist.* = .{
Expand Down Expand Up @@ -317,7 +317,7 @@ fn addObjcSelrefsSection(self: *InternalObject, methname_sym_index: Symbol.Index
const sym_index = try self.addSymbol(gpa);
const sym = &self.symbols.items[@intFromEnum(sym_index)];
sym.atom_ref = atom_index.toRef(self.index);
sym.extra = try self.addSymbolExtra(gpa, .{});
sym.extra = try self.addSymbolExtra(gpa, .init);
const nlist_idx: u32 = @intCast(self.symtab.items.len);
const nlist = try self.symtab.addOne(gpa);
nlist.* = .{
Expand Down Expand Up @@ -685,7 +685,7 @@ fn addAtom(self: *InternalObject, allocator: Allocator, size: u64, alignment: u3
.alignment = alignment,
.file = self.index,
.atom_index = atom_index,
.extra = try self.addAtomExtra(allocator, .{}),
.extra = try self.addAtomExtra(allocator, .init),
};
return atom_index;
}
Expand Down Expand Up @@ -884,7 +884,7 @@ fn formatSymtab(

const Section = struct {
header: macho.section_64,
relocs: std.ArrayListUnmanaged(Relocation) = .{},
relocs: std.ArrayListUnmanaged(Relocation) = .empty,
extra: Extra = .{},

const Extra = packed struct {
Expand Down
Loading