diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2021-07-01 17:25:51 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2021-07-15 18:49:46 +0200 |
| commit | 2b3bda43e352152f0150bf2e795419cf1bcfcd90 (patch) | |
| tree | f6c550980ea30b8e3ded451b6145ebb203101b22 /src/link/MachO/Object.zig | |
| parent | 3622fe08dbdcaccb04204b48257e1d5fcbe0d164 (diff) | |
| download | zig-2b3bda43e352152f0150bf2e795419cf1bcfcd90.tar.gz zig-2b3bda43e352152f0150bf2e795419cf1bcfcd90.zip | |
zld: abstract Symbol creation logic
Diffstat (limited to 'src/link/MachO/Object.zig')
| -rw-r--r-- | src/link/MachO/Object.zig | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/src/link/MachO/Object.zig b/src/link/MachO/Object.zig index cb55dd1fd8..197c302316 100644 --- a/src/link/MachO/Object.zig +++ b/src/link/MachO/Object.zig @@ -9,12 +9,12 @@ const log = std.log.scoped(.object); const macho = std.macho; const mem = std.mem; const reloc = @import("reloc.zig"); +const parseName = @import("Zld.zig").parseName; const Allocator = mem.Allocator; const Arch = std.Target.Cpu.Arch; const Relocation = reloc.Relocation; const Symbol = @import("Symbol.zig"); -const parseName = @import("Zld.zig").parseName; usingnamespace @import("commands.zig"); @@ -437,47 +437,26 @@ pub fn parseSymbols(self: *Object) !void { if (Symbol.isWeakDef(sym) or Symbol.isPext(sym)) break :linkage .linkage_unit; break :linkage .global; }; - const regular = try self.allocator.create(Symbol.Regular); - errdefer self.allocator.destroy(regular); - regular.* = .{ - .base = .{ - .@"type" = .regular, - .name = name, - }, + break :symbol try Symbol.Regular.new(self.allocator, name, .{ .linkage = linkage, .address = sym.n_value, .section = sym.n_sect - 1, .weak_ref = Symbol.isWeakRef(sym), .file = self, - }; - break :symbol ®ular.base; + }); } if (sym.n_value != 0) { - const tentative = try self.allocator.create(Symbol.Tentative); - errdefer self.allocator.destroy(tentative); - tentative.* = .{ - .base = .{ - .@"type" = .tentative, - .name = name, - }, + break :symbol try Symbol.Tentative.new(self.allocator, name, .{ .size = sym.n_value, .alignment = (sym.n_desc >> 8) & 0x0f, .file = self, - }; - break :symbol &tentative.base; + }); } - const undef = try self.allocator.create(Symbol.Unresolved); - errdefer self.allocator.destroy(undef); - undef.* = .{ - .base = .{ - .@"type" = .unresolved, - .name = name, - }, + break :symbol try Symbol.Unresolved.new(self.allocator, name, .{ .file = self, - }; - break :symbol &undef.base; + }); }; try self.symbols.append(self.allocator, symbol); |
