authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-04-03 06:02:38-04:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-04-03 18:02:53+02:00
log562170681a3d0c8502892f8975f369c4b269fe1a
treef4515c71cbd4d8d204fc8b957f0fda024f443fe2
parentf0d13489f819ecd1c0d1c23914127c225f507241

link: cleanup lazy symbols

We now only update one lazy symbol in flushModule. Updating the rest from updateDecl is TBD.

5 files changed, 158 insertions(+), 163 deletions(-)

src/Module.zig+1-1
......@@ -555,7 +555,7 @@ pub const Decl = struct {
555555 _,
556556
557557 pub fn init(oi: ?Index) OptionalIndex {
558 return oi orelse .none;
558 return @intToEnum(OptionalIndex, @enumToInt(oi orelse return .none));
559559 }
560560
561561 pub fn unwrap(oi: OptionalIndex) ?Index {
src/link.zig+12-14
......@@ -1106,23 +1106,21 @@ pub const File = struct {
11061106 };
11071107
11081108 pub const LazySymbol = struct {
1109 kind: enum { code, const_data },
1110 ty: Type,
1109 pub const Kind = enum { code, const_data };
11111110
1112 pub const Context = struct {
1113 mod: *Module,
1111 kind: Kind,
1112 ty: Type,
11141113
1115 pub fn hash(ctx: @This(), sym: LazySymbol) u32 {
1116 var hasher = std.hash.Wyhash.init(0);
1117 std.hash.autoHash(&hasher, sym.kind);
1118 sym.ty.hashWithHasher(&hasher, ctx.mod);
1119 return @truncate(u32, hasher.final());
1120 }
1114 pub fn initDecl(kind: Kind, decl: Module.Decl.OptionalIndex, mod: *Module) LazySymbol {
1115 return .{ .kind = kind, .ty = if (decl.unwrap()) |decl_index|
1116 mod.declPtr(decl_index).val.castTag(.ty).?.data
1117 else
1118 Type.anyerror };
1119 }
11211120
1122 pub fn eql(ctx: @This(), lhs: LazySymbol, rhs: LazySymbol, _: usize) bool {
1123 return lhs.kind == rhs.kind and lhs.ty.eql(rhs.ty, ctx.mod);
1124 }
1125 };
1121 pub fn getDecl(self: LazySymbol) Module.Decl.OptionalIndex {
1122 return Module.Decl.OptionalIndex.init(self.ty.getOwnerDeclOrNull());
1123 }
11261124 };
11271125
11281126 pub const C = @import("link/C.zig");
src/link/Coff.zig+48-51
......@@ -145,16 +145,11 @@ const Section = struct {
145145 free_list: std.ArrayListUnmanaged(Atom.Index) = .{},
146146};
147147
148const LazySymbolTable = std.ArrayHashMapUnmanaged(
149 link.File.LazySymbol,
150 LazySymbolMetadata,
151 link.File.LazySymbol.Context,
152 true,
153);
148const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
154149
155150const LazySymbolMetadata = struct {
156 atom: Atom.Index,
157 section: u16,
151 text_atom: ?Atom.Index = null,
152 rdata_atom: ?Atom.Index = null,
158153 alignment: u32,
159154};
160155
......@@ -1176,10 +1171,28 @@ pub fn updateDecl(self: *Coff, module: *Module, decl_index: Module.Decl.Index) !
11761171 return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index));
11771172}
11781173
1179fn updateLazySymbol(
1174fn updateLazySymbol(self: *Coff, decl: Module.Decl.OptionalIndex, metadata: LazySymbolMetadata) !void {
1175 const mod = self.base.options.module.?;
1176 if (metadata.text_atom) |atom| try self.updateLazySymbolAtom(
1177 link.File.LazySymbol.initDecl(.code, decl, mod),
1178 atom,
1179 self.text_section_index.?,
1180 metadata.alignment,
1181 );
1182 if (metadata.rdata_atom) |atom| try self.updateLazySymbolAtom(
1183 link.File.LazySymbol.initDecl(.const_data, decl, mod),
1184 atom,
1185 self.rdata_section_index.?,
1186 metadata.alignment,
1187 );
1188}
1189
1190fn updateLazySymbolAtom(
11801191 self: *Coff,
1181 lazy_sym: link.File.LazySymbol,
1182 lazy_metadata: LazySymbolMetadata,
1192 sym: link.File.LazySymbol,
1193 atom_index: Atom.Index,
1194 section_index: u16,
1195 required_alignment: u32,
11831196) !void {
11841197 const gpa = self.base.allocator;
11851198 const mod = self.base.options.module.?;
......@@ -1188,16 +1201,15 @@ fn updateLazySymbol(
11881201 defer code_buffer.deinit();
11891202
11901203 const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{
1191 @tagName(lazy_sym.kind),
1192 lazy_sym.ty.fmt(mod),
1204 @tagName(sym.kind),
1205 sym.ty.fmt(mod),
11931206 });
11941207 defer gpa.free(name);
11951208
1196 const atom_index = lazy_metadata.atom;
11971209 const atom = self.getAtomPtr(atom_index);
11981210 const local_sym_index = atom.getSymbolIndex().?;
11991211
1200 const src = if (lazy_sym.ty.getOwnerDeclOrNull()) |owner_decl|
1212 const src = if (sym.ty.getOwnerDeclOrNull()) |owner_decl|
12011213 mod.declPtr(owner_decl).srcLoc()
12021214 else
12031215 Module.SrcLoc{
......@@ -1205,14 +1217,9 @@ fn updateLazySymbol(
12051217 .parent_decl_node = undefined,
12061218 .lazy = .unneeded,
12071219 };
1208 const res = try codegen.generateLazySymbol(
1209 &self.base,
1210 src,
1211 lazy_sym,
1212 &code_buffer,
1213 .none,
1214 .{ .parent_atom_index = local_sym_index },
1215 );
1220 const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{
1221 .parent_atom_index = local_sym_index,
1222 });
12161223 const code = switch (res) {
12171224 .ok => code_buffer.items,
12181225 .fail => |em| {
......@@ -1221,11 +1228,10 @@ fn updateLazySymbol(
12211228 },
12221229 };
12231230
1224 const required_alignment = lazy_metadata.alignment;
12251231 const code_len = @intCast(u32, code.len);
12261232 const symbol = atom.getSymbolPtr(self);
12271233 try self.setSymbolName(symbol, name);
1228 symbol.section_number = @intToEnum(coff.SectionNumber, lazy_metadata.section + 1);
1234 symbol.section_number = @intToEnum(coff.SectionNumber, section_index + 1);
12291235 symbol.type = .{ .complex_type = .NULL, .base_type = .NULL };
12301236
12311237 const vaddr = try self.allocateAtom(atom_index, code_len, required_alignment);
......@@ -1250,24 +1256,18 @@ fn updateLazySymbol(
12501256
12511257pub fn getOrCreateAtomForLazySymbol(
12521258 self: *Coff,
1253 lazy_sym: link.File.LazySymbol,
1259 sym: link.File.LazySymbol,
12541260 alignment: u32,
12551261) !Atom.Index {
1256 const gop = try self.lazy_syms.getOrPutContext(self.base.allocator, lazy_sym, .{
1257 .mod = self.base.options.module.?,
1258 });
1262 const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl());
12591263 errdefer _ = self.lazy_syms.pop();
1260 if (!gop.found_existing) {
1261 gop.value_ptr.* = .{
1262 .atom = try self.createAtom(),
1263 .section = switch (lazy_sym.kind) {
1264 .code => self.text_section_index.?,
1265 .const_data => self.rdata_section_index.?,
1266 },
1267 .alignment = alignment,
1268 };
1269 }
1270 return gop.value_ptr.atom;
1264 if (!gop.found_existing) gop.value_ptr.* = .{ .alignment = alignment };
1265 const atom = switch (sym.kind) {
1266 .code => &gop.value_ptr.text_atom,
1267 .const_data => &gop.value_ptr.rdata_atom,
1268 };
1269 if (atom.* == null) atom.* = try self.createAtom();
1270 return atom.*.?;
12711271}
12721272
12731273pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: Module.Decl.Index) !Atom.Index {
......@@ -1600,17 +1600,13 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
16001600 sub_prog_node.activate();
16011601 defer sub_prog_node.end();
16021602
1603 {
1604 var lazy_it = self.lazy_syms.iterator();
1605 while (lazy_it.next()) |lazy_entry| {
1606 self.updateLazySymbol(
1607 lazy_entry.key_ptr.*,
1608 lazy_entry.value_ptr.*,
1609 ) catch |err| switch (err) {
1610 error.CodegenFail => return error.FlushFailure,
1611 else => |e| return e,
1612 };
1613 }
1603 // Most lazy symbols can be updated when the corresponding decl is,
1604 // so we only have to worry about the one without an associated decl.
1605 if (self.lazy_syms.get(.none)) |metadata| {
1606 self.updateLazySymbol(.none, metadata) catch |err| switch (err) {
1607 error.CodegenFail => return error.FlushFailure,
1608 else => |e| return e,
1609 };
16141610 }
16151611
16161612 const gpa = self.base.allocator;
......@@ -2489,6 +2485,7 @@ const Module = @import("../Module.zig");
24892485const Object = @import("Coff/Object.zig");
24902486const Relocation = @import("Coff/Relocation.zig");
24912487const StringTable = @import("strtab.zig").StringTable;
2488const Type = @import("../type.zig").Type;
24922489const TypedValue = @import("../TypedValue.zig");
24932490
24942491pub const base_tag: link.File.Tag = .coff;
src/link/Elf.zig+48-44
......@@ -64,8 +64,8 @@ const Section = struct {
6464};
6565
6666const LazySymbolMetadata = struct {
67 atom: Atom.Index,
68 shdr: u16,
67 text_atom: ?Atom.Index = null,
68 rodata_atom: ?Atom.Index = null,
6969 alignment: u32,
7070};
7171
......@@ -208,7 +208,7 @@ relocs: RelocTable = .{},
208208
209209const RelocTable = std.AutoHashMapUnmanaged(Atom.Index, std.ArrayListUnmanaged(Atom.Reloc));
210210const UnnamedConstTable = std.AutoHashMapUnmanaged(Module.Decl.Index, std.ArrayListUnmanaged(Atom.Index));
211const LazySymbolTable = std.ArrayHashMapUnmanaged(File.LazySymbol, LazySymbolMetadata, File.LazySymbol.Context, true);
211const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
212212
213213/// When allocating, the ideal_capacity is calculated by
214214/// actual_capacity + (actual_capacity / ideal_factor)
......@@ -1065,17 +1065,13 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
10651065 sub_prog_node.activate();
10661066 defer sub_prog_node.end();
10671067
1068 {
1069 var lazy_it = self.lazy_syms.iterator();
1070 while (lazy_it.next()) |lazy_entry| {
1071 self.updateLazySymbol(
1072 lazy_entry.key_ptr.*,
1073 lazy_entry.value_ptr.*,
1074 ) catch |err| switch (err) {
1075 error.CodegenFail => return error.FlushFailure,
1076 else => |e| return e,
1077 };
1078 }
1068 // Most lazy symbols can be updated when the corresponding decl is,
1069 // so we only have to worry about the one without an associated decl.
1070 if (self.lazy_syms.get(.none)) |metadata| {
1071 self.updateLazySymbol(.none, metadata) catch |err| switch (err) {
1072 error.CodegenFail => return error.FlushFailure,
1073 else => |e| return e,
1074 };
10791075 }
10801076
10811077 // TODO This linker code currently assumes there is only 1 compilation unit and it
......@@ -2424,22 +2420,16 @@ pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void {
24242420 }
24252421}
24262422
2427pub fn getOrCreateAtomForLazySymbol(self: *Elf, lazy_sym: File.LazySymbol, alignment: u32) !Atom.Index {
2428 const gop = try self.lazy_syms.getOrPutContext(self.base.allocator, lazy_sym, .{
2429 .mod = self.base.options.module.?,
2430 });
2423pub fn getOrCreateAtomForLazySymbol(self: *Elf, sym: File.LazySymbol, alignment: u32) !Atom.Index {
2424 const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl());
24312425 errdefer _ = self.lazy_syms.pop();
2432 if (!gop.found_existing) {
2433 gop.value_ptr.* = .{
2434 .atom = try self.createAtom(),
2435 .shdr = switch (lazy_sym.kind) {
2436 .code => self.text_section_index.?,
2437 .const_data => self.rodata_section_index.?,
2438 },
2439 .alignment = alignment,
2440 };
2441 }
2442 return gop.value_ptr.atom;
2426 if (!gop.found_existing) gop.value_ptr.* = .{ .alignment = alignment };
2427 const atom = switch (sym.kind) {
2428 .code => &gop.value_ptr.text_atom,
2429 .const_data => &gop.value_ptr.rodata_atom,
2430 };
2431 if (atom.* == null) atom.* = try self.createAtom();
2432 return atom.*.?;
24432433}
24442434
24452435pub fn getOrCreateAtomForDecl(self: *Elf, decl_index: Module.Decl.Index) !Atom.Index {
......@@ -2708,7 +2698,29 @@ pub fn updateDecl(self: *Elf, module: *Module, decl_index: Module.Decl.Index) !v
27082698 return self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index));
27092699}
27102700
2711fn updateLazySymbol(self: *Elf, lazy_sym: File.LazySymbol, lazy_metadata: LazySymbolMetadata) !void {
2701fn updateLazySymbol(self: *Elf, decl: Module.Decl.OptionalIndex, metadata: LazySymbolMetadata) !void {
2702 const mod = self.base.options.module.?;
2703 if (metadata.text_atom) |atom| try self.updateLazySymbolAtom(
2704 File.LazySymbol.initDecl(.code, decl, mod),
2705 atom,
2706 self.text_section_index.?,
2707 metadata.alignment,
2708 );
2709 if (metadata.rodata_atom) |atom| try self.updateLazySymbolAtom(
2710 File.LazySymbol.initDecl(.const_data, decl, mod),
2711 atom,
2712 self.rodata_section_index.?,
2713 metadata.alignment,
2714 );
2715}
2716
2717fn updateLazySymbolAtom(
2718 self: *Elf,
2719 sym: File.LazySymbol,
2720 atom_index: Atom.Index,
2721 shdr_index: u16,
2722 required_alignment: u32,
2723) !void {
27122724 const gpa = self.base.allocator;
27132725 const mod = self.base.options.module.?;
27142726
......@@ -2717,19 +2729,18 @@ fn updateLazySymbol(self: *Elf, lazy_sym: File.LazySymbol, lazy_metadata: LazySy
27172729
27182730 const name_str_index = blk: {
27192731 const name = try std.fmt.allocPrint(gpa, "__lazy_{s}_{}", .{
2720 @tagName(lazy_sym.kind),
2721 lazy_sym.ty.fmt(mod),
2732 @tagName(sym.kind),
2733 sym.ty.fmt(mod),
27222734 });
27232735 defer gpa.free(name);
27242736 break :blk try self.shstrtab.insert(gpa, name);
27252737 };
27262738 const name = self.shstrtab.get(name_str_index).?;
27272739
2728 const atom_index = lazy_metadata.atom;
27292740 const atom = self.getAtom(atom_index);
27302741 const local_sym_index = atom.getSymbolIndex().?;
27312742
2732 const src = if (lazy_sym.ty.getOwnerDeclOrNull()) |owner_decl|
2743 const src = if (sym.ty.getOwnerDeclOrNull()) |owner_decl|
27332744 mod.declPtr(owner_decl).srcLoc()
27342745 else
27352746 Module.SrcLoc{
......@@ -2737,14 +2748,9 @@ fn updateLazySymbol(self: *Elf, lazy_sym: File.LazySymbol, lazy_metadata: LazySy
27372748 .parent_decl_node = undefined,
27382749 .lazy = .unneeded,
27392750 };
2740 const res = try codegen.generateLazySymbol(
2741 &self.base,
2742 src,
2743 lazy_sym,
2744 &code_buffer,
2745 .none,
2746 .{ .parent_atom_index = local_sym_index },
2747 );
2751 const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{
2752 .parent_atom_index = local_sym_index,
2753 });
27482754 const code = switch (res) {
27492755 .ok => code_buffer.items,
27502756 .fail => |em| {
......@@ -2753,7 +2759,6 @@ fn updateLazySymbol(self: *Elf, lazy_sym: File.LazySymbol, lazy_metadata: LazySy
27532759 },
27542760 };
27552761
2756 const shdr_index = lazy_metadata.shdr;
27572762 const phdr_index = self.sections.items(.phdr_index)[shdr_index];
27582763 const local_sym = atom.getSymbolPtr(self);
27592764 local_sym.* = .{
......@@ -2764,7 +2769,6 @@ fn updateLazySymbol(self: *Elf, lazy_sym: File.LazySymbol, lazy_metadata: LazySy
27642769 .st_value = 0,
27652770 .st_size = 0,
27662771 };
2767 const required_alignment = lazy_metadata.alignment;
27682772 const vaddr = try self.allocateAtom(atom_index, code.len, required_alignment);
27692773 errdefer self.freeAtom(atom_index);
27702774 log.debug("allocated text block for {s} at 0x{x}", .{ name, vaddr });
src/link/MachO.zig+49-53
......@@ -232,16 +232,11 @@ const is_hot_update_compatible = switch (builtin.target.os.tag) {
232232 else => false,
233233};
234234
235const LazySymbolTable = std.ArrayHashMapUnmanaged(
236 link.File.LazySymbol,
237 LazySymbolMetadata,
238 link.File.LazySymbol.Context,
239 true,
240);
235const LazySymbolTable = std.AutoArrayHashMapUnmanaged(Module.Decl.OptionalIndex, LazySymbolMetadata);
241236
242237const LazySymbolMetadata = struct {
243 atom: Atom.Index,
244 section: u8,
238 text_atom: ?Atom.Index = null,
239 data_const_atom: ?Atom.Index = null,
245240 alignment: u32,
246241};
247242
......@@ -513,17 +508,13 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No
513508 sub_prog_node.activate();
514509 defer sub_prog_node.end();
515510
516 {
517 var lazy_it = self.lazy_syms.iterator();
518 while (lazy_it.next()) |lazy_entry| {
519 self.updateLazySymbol(
520 lazy_entry.key_ptr.*,
521 lazy_entry.value_ptr.*,
522 ) catch |err| switch (err) {
523 error.CodegenFail => return error.FlushFailure,
524 else => |e| return e,
525 };
526 }
511 // Most lazy symbols can be updated when the corresponding decl is,
512 // so we only have to worry about the one without an associated decl.
513 if (self.lazy_syms.get(.none)) |metadata| {
514 self.updateLazySymbol(.none, metadata) catch |err| switch (err) {
515 error.CodegenFail => return error.FlushFailure,
516 else => |e| return e,
517 };
527518 }
528519
529520 const module = self.base.options.module orelse return error.LinkingWithoutZigSourceUnimplemented;
......@@ -2309,7 +2300,29 @@ pub fn updateDecl(self: *MachO, module: *Module, decl_index: Module.Decl.Index)
23092300 try self.updateDeclExports(module, decl_index, module.getDeclExports(decl_index));
23102301}
23112302
2312fn updateLazySymbol(self: *MachO, lazy_sym: File.LazySymbol, lazy_metadata: LazySymbolMetadata) !void {
2303fn updateLazySymbol(self: *MachO, decl: Module.Decl.OptionalIndex, metadata: LazySymbolMetadata) !void {
2304 const mod = self.base.options.module.?;
2305 if (metadata.text_atom) |atom| try self.updateLazySymbolAtom(
2306 File.LazySymbol.initDecl(.code, decl, mod),
2307 atom,
2308 self.text_section_index.?,
2309 metadata.alignment,
2310 );
2311 if (metadata.data_const_atom) |atom| try self.updateLazySymbolAtom(
2312 File.LazySymbol.initDecl(.const_data, decl, mod),
2313 atom,
2314 self.data_const_section_index.?,
2315 metadata.alignment,
2316 );
2317}
2318
2319fn updateLazySymbolAtom(
2320 self: *MachO,
2321 sym: File.LazySymbol,
2322 atom_index: Atom.Index,
2323 section_index: u8,
2324 required_alignment: u32,
2325) !void {
23132326 const gpa = self.base.allocator;
23142327 const mod = self.base.options.module.?;
23152328
......@@ -2318,19 +2331,18 @@ fn updateLazySymbol(self: *MachO, lazy_sym: File.LazySymbol, lazy_metadata: Lazy
23182331
23192332 const name_str_index = blk: {
23202333 const name = try std.fmt.allocPrint(gpa, "___lazy_{s}_{}", .{
2321 @tagName(lazy_sym.kind),
2322 lazy_sym.ty.fmt(mod),
2334 @tagName(sym.kind),
2335 sym.ty.fmt(mod),
23232336 });
23242337 defer gpa.free(name);
23252338 break :blk try self.strtab.insert(gpa, name);
23262339 };
23272340 const name = self.strtab.get(name_str_index).?;
23282341
2329 const atom_index = lazy_metadata.atom;
23302342 const atom = self.getAtomPtr(atom_index);
23312343 const local_sym_index = atom.getSymbolIndex().?;
23322344
2333 const src = if (lazy_sym.ty.getOwnerDeclOrNull()) |owner_decl|
2345 const src = if (sym.ty.getOwnerDeclOrNull()) |owner_decl|
23342346 mod.declPtr(owner_decl).srcLoc()
23352347 else
23362348 Module.SrcLoc{
......@@ -2338,14 +2350,9 @@ fn updateLazySymbol(self: *MachO, lazy_sym: File.LazySymbol, lazy_metadata: Lazy
23382350 .parent_decl_node = undefined,
23392351 .lazy = .unneeded,
23402352 };
2341 const res = try codegen.generateLazySymbol(
2342 &self.base,
2343 src,
2344 lazy_sym,
2345 &code_buffer,
2346 .none,
2347 .{ .parent_atom_index = local_sym_index },
2348 );
2353 const res = try codegen.generateLazySymbol(&self.base, src, sym, &code_buffer, .none, .{
2354 .parent_atom_index = local_sym_index,
2355 });
23492356 const code = switch (res) {
23502357 .ok => code_buffer.items,
23512358 .fail => |em| {
......@@ -2354,11 +2361,10 @@ fn updateLazySymbol(self: *MachO, lazy_sym: File.LazySymbol, lazy_metadata: Lazy
23542361 },
23552362 };
23562363
2357 const required_alignment = lazy_metadata.alignment;
23582364 const symbol = atom.getSymbolPtr(self);
23592365 symbol.n_strx = name_str_index;
23602366 symbol.n_type = macho.N_SECT;
2361 symbol.n_sect = lazy_metadata.section + 1;
2367 symbol.n_sect = section_index + 1;
23622368 symbol.n_desc = 0;
23632369
23642370 const vaddr = try self.allocateAtom(atom_index, code.len, required_alignment);
......@@ -2381,26 +2387,16 @@ fn updateLazySymbol(self: *MachO, lazy_sym: File.LazySymbol, lazy_metadata: Lazy
23812387 try self.writeAtom(atom_index, code);
23822388}
23832389
2384pub fn getOrCreateAtomForLazySymbol(
2385 self: *MachO,
2386 lazy_sym: File.LazySymbol,
2387 alignment: u32,
2388) !Atom.Index {
2389 const gop = try self.lazy_syms.getOrPutContext(self.base.allocator, lazy_sym, .{
2390 .mod = self.base.options.module.?,
2391 });
2390pub fn getOrCreateAtomForLazySymbol(self: *MachO, sym: File.LazySymbol, alignment: u32) !Atom.Index {
2391 const gop = try self.lazy_syms.getOrPut(self.base.allocator, sym.getDecl());
23922392 errdefer _ = self.lazy_syms.pop();
2393 if (!gop.found_existing) {
2394 gop.value_ptr.* = .{
2395 .atom = try self.createAtom(),
2396 .section = switch (lazy_sym.kind) {
2397 .code => self.text_section_index.?,
2398 .const_data => self.data_const_section_index.?,
2399 },
2400 .alignment = alignment,
2401 };
2402 }
2403 return gop.value_ptr.atom;
2393 if (!gop.found_existing) gop.value_ptr.* = .{ .alignment = alignment };
2394 const atom = switch (sym.kind) {
2395 .code => &gop.value_ptr.text_atom,
2396 .const_data => &gop.value_ptr.data_const_atom,
2397 };
2398 if (atom.* == null) atom.* = try self.createAtom();
2399 return atom.*.?;
24042400}
24052401
24062402pub fn getOrCreateAtomForDecl(self: *MachO, decl_index: Module.Decl.Index) !Atom.Index {