authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-07 16:09:31-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-07 19:53:07-04:00
log5637ede041a9b8b0a050343be5392f97994f6777
treed6118812b7ba7207513ddbc2b6b86eaa843e5cdc
parent804b044235954830e66a27b2365e1b26db51478a

Dwarf2: use indexed strings

This saves ~75MB on a `zig build -Dnew-linker` compiler binary.

2 files changed, 492 insertions(+), 329 deletions(-)

src/link/Dwarf2.zig+292-230
......@@ -199,8 +199,8 @@ pub const Line = struct {
199199
200200pub const Str = struct {
201201 ni: link.MappedFile.Node.Index.Optional,
202 offset: usize,
203 map: std.HashMapUnmanaged(usize, void, Context, std.hash_map.default_max_load_percentage),
202 end: usize,
203 map: std.array_hash_map.Custom(usize, void, Context, true),
204204
205205 fn get(
206206 s: *Str,
......@@ -217,21 +217,21 @@ pub const Str = struct {
217217 .{ .slice = slice },
218218 );
219219 if (!gop.found_existing) {
220 gop.key_ptr.* = s.offset;
221 try ni.ensureMinimumSize(gpa, mf, s.offset + str.len + 1);
220 gop.key_ptr.* = s.end;
221 try ni.ensureMinimumSize(gpa, mf, s.end + str.len + 1);
222222 const slice_mut = ni.slice(mf);
223 @memcpy(slice_mut[s.offset..][0..str.len], str);
224 s.offset += str.len;
225 slice_mut[s.offset] = 0;
226 s.offset += 1;
223 @memcpy(slice_mut[s.end..][0..str.len], str);
224 s.end += str.len;
225 slice_mut[s.end] = 0;
226 s.end += 1;
227227 }
228228 return gop.key_ptr.*;
229229 }
230230
231231 const Context = struct {
232232 slice: []const u8,
233 pub fn hash(context: Context, offset: usize) u64 {
234 return std.hash.Wyhash.hash(0, std.mem.sliceTo(context.slice[offset..], 0));
233 pub fn hash(context: Context, offset: usize) u32 {
234 return @truncate(std.hash.Wyhash.hash(0, std.mem.sliceTo(context.slice[offset..], 0)));
235235 }
236236 pub fn eql(_: Context, lhs_offset: usize, rhs_offset: usize) bool {
237237 return lhs_offset == rhs_offset;
......@@ -240,10 +240,10 @@ pub const Str = struct {
240240
241241 const Adapter = struct {
242242 slice: []const u8,
243 pub fn hash(_: Adapter, key: []const u8) u64 {
244 return std.hash.Wyhash.hash(0, key);
243 pub fn hash(_: Adapter, key: []const u8) u32 {
244 return @truncate(std.hash.Wyhash.hash(0, key));
245245 }
246 pub fn eql(adapter: Adapter, key: []const u8, rhs_offset: usize) bool {
246 pub fn eql(adapter: Adapter, key: []const u8, rhs_offset: usize, _: usize) bool {
247247 return std.mem.startsWith(u8, adapter.slice[rhs_offset..], key) and
248248 adapter.slice[rhs_offset + key.len] == 0;
249249 }
......@@ -251,17 +251,47 @@ pub const Str = struct {
251251};
252252
253253pub const Rnglists = struct {
254 fn offsetsTableOffset(dwarf: *Dwarf) usize {
254 fn tableOffset(dwarf: *Dwarf) usize {
255255 return dwarf.unitLengthSize() + 2 + 1 + 1 + 4;
256256 }
257
258 pub fn size(dwarf: *Dwarf, ui: Unit.Index) usize {
259 return ui.get(dwarf).debug_rnglists_end + 1;
260 }
257261};
258262
259263pub const StrOffsets = struct {
260264 ni: link.MappedFile.Node.Index.Optional,
261 offset: usize,
265 pending_index: usize,
266 map: std.array_hash_map.Auto(usize, void),
267
268 fn get(
269 so: *StrOffsets,
270 dwarf: *Dwarf,
271 s: *Str,
272 mf: *link.MappedFile,
273 str: []const u8,
274 ) link.Error!usize {
275 const comp = dwarf.lf.comp;
276 try so.map.ensureUnusedCapacity(comp.gpa, 1);
277 return so.map.getOrPutAssumeCapacity(s.get(comp.gpa, mf, str) catch |err| switch (err) {
278 else => |e| return e,
279 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
280 mf.io_err.?,
281 }),
282 }).index;
283 }
284
285 fn tableOffset(dwarf: *Dwarf) usize {
286 return dwarf.unitLengthSize() + 2 + 2;
287 }
288
289 pub fn size(so: *StrOffsets, dwarf: *Dwarf) usize {
290 return tableOffset(dwarf) + dwarf.secOffsetSize() * so.pending_index;
291 }
262292};
263293
264pub const SharedSection = enum { debug_abbrev, debug_line_str, debug_str, debug_str_offsets };
294pub const SharedSection = enum { debug_abbrev, debug_line_str, debug_str };
265295
266296pub const Loc = union(enum) {
267297 empty,
......@@ -695,8 +725,8 @@ pub const WipFunc = struct {
695725 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
696726 try di_w.writeUleb128(decl.src_column + 1);
697727 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
698 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
699 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
728 try dwarf.strx(di_nw, nav.name.toSlice(ip));
729 try dwarf.strx(di_nw, switch (decl.linkage) {
700730 .normal => nav.fqn,
701731 .@"extern", .@"export" => nav.name,
702732 }.toSlice(ip));
......@@ -813,7 +843,7 @@ pub const WipFunc = struct {
813843 .arg => if (opt_name) |_| .arg else .unnamed_arg,
814844 .local_var => if (opt_name) |_| .local_var else unreachable,
815845 });
816 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);
846 if (opt_name) |name| try dwarf.strx(di_nw, name);
817847 try dwarf.refType(debug.pt, di_nw, ty);
818848 try dwarf.exprLoc(di_nw, loc);
819849 debug.empty = false;
......@@ -865,7 +895,7 @@ pub const WipFunc = struct {
865895 .fully_comptime => .local_const_fully_comptime,
866896 } else unreachable,
867897 });
868 if (opt_name) |name| try dwarf.strp(&dwarf.debug_str, di_nw, name);
898 if (opt_name) |name| try dwarf.strx(di_nw, name);
869899 try dwarf.refType(pt, di_nw, ty);
870900 if (ty_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, val);
871901 if (ty_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, val);
......@@ -1297,18 +1327,19 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
12971327 },
12981328 .debug_line_str = .{
12991329 .ni = .none,
1300 .offset = 0,
1330 .end = 0,
13011331 .map = .empty,
13021332 },
13031333 .debug_rnglists = .{},
13041334 .debug_str = .{
13051335 .ni = .none,
1306 .offset = 0,
1336 .end = 0,
13071337 .map = .empty,
13081338 },
13091339 .debug_str_offsets = .{
13101340 .ni = .none,
1311 .offset = 0,
1341 .pending_index = 0,
1342 .map = .empty,
13121343 },
13131344 };
13141345}
......@@ -1324,6 +1355,7 @@ pub fn deinit(dwarf: *Dwarf) void {
13241355 dwarf.decls.deinit(gpa);
13251356 dwarf.debug_line_str.map.deinit(gpa);
13261357 dwarf.debug_str.map.deinit(gpa);
1358 dwarf.debug_str_offsets.map.deinit(gpa);
13271359 dwarf.* = undefined;
13281360}
13291361
......@@ -1499,7 +1531,7 @@ fn getConstDeclInst(dwarf: *Dwarf, val: InternPool.Index) ?InternPool.TrackedIns
14991531 }).srcInst(ip),
15001532 }
15011533}
1502fn getConstDecl(
1534pub fn getConstDecl(
15031535 dwarf: *Dwarf,
15041536 pt: Zcu.PerThread,
15051537 instance_const: InternPool.Index,
......@@ -1509,7 +1541,7 @@ fn getConstDecl(
15091541 return Const.get(cpi, dwarf).debug_info_ni.unwrap().?;
15101542 }, .{ .@"const" = instance_const });
15111543}
1512fn getGlobalDecl(
1544pub fn getGlobalDecl(
15131545 dwarf: *Dwarf,
15141546 pt: Zcu.PerThread,
15151547 instance_global: InternPool.Nav.Index,
......@@ -1567,7 +1599,7 @@ pub fn unitLengthSize(dwarf: *Dwarf) usize {
15671599 .@"64" => 4 + 8,
15681600 };
15691601}
1570pub fn genUnitLength(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {
1602fn genUnitLength(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {
15711603 switch (dwarf.format) {
15721604 .@"32" => try w.writeInt(u32, undefined, dwarf.endian),
15731605 .@"64" => {
......@@ -1700,22 +1732,23 @@ pub fn genDebugInfoHeader(
17001732 const compile_unit_offset = dih_w.end;
17011733 try dwarf.abbrevCode(dih_nw, .compile_unit);
17021734 try dih_w.writeByte(DW.LANG.Zig);
1703 try dwarf.strp(&dwarf.debug_str, dih_nw, "zig " ++ @import("build_options").version);
1704 const root_dir_path = try mod.root.toAbsolute(&comp.dirs, comp.gpa);
1705 defer comp.gpa.free(root_dir_path);
1706 try dwarf.strp(&dwarf.debug_line_str, dih_nw, root_dir_path);
1707 try dwarf.strp(&dwarf.debug_line_str, dih_nw, mod.root_src_path);
17081735 try dwarf.secOffset(
17091736 dih_nw,
17101737 dwarf.getUnit(zcu.root_mod).get(dwarf).debug_info_header_ni.unwrap().?,
17111738 compile_unit_offset,
17121739 );
17131740 try dwarf.secOffset(dih_nw, unit.debug_line_header_ni.unwrap().?, 0);
1714 try dwarf.secOffset(dih_nw, unit.debug_rnglists_ni.unwrap().?, Rnglists.offsetsTableOffset(dwarf));
1741 try dwarf.secOffset(dih_nw, unit.debug_rnglists_ni.unwrap().?, Rnglists.tableOffset(dwarf));
1742 try dwarf.secOffset(dih_nw, dwarf.debug_str_offsets.ni.unwrap().?, StrOffsets.tableOffset(dwarf));
1743 try dwarf.strx1(dih_nw, "zig " ++ @import("build_options").version);
1744 const root_dir_path = try mod.root.toAbsolute(&comp.dirs, comp.gpa);
1745 defer comp.gpa.free(root_dir_path);
1746 try dwarf.strp(&dwarf.debug_line_str, dih_nw, root_dir_path);
1747 try dwarf.strp(&dwarf.debug_line_str, dih_nw, mod.root_src_path);
17151748 try dih_w.writeUleb128(0);
17161749 const module_offset = dih_w.end;
17171750 try dwarf.abbrevCode(dih_nw, .module);
1718 try dwarf.strp(&dwarf.debug_str, dih_nw, mod.fully_qualified_name);
1751 try dwarf.strx(dih_nw, mod.fully_qualified_name);
17191752 try dih_w.writeUleb128(0);
17201753 try dwarf.genModuleDependency(
17211754 dih_nw,
......@@ -1741,7 +1774,7 @@ fn genModuleDependency(
17411774 const dep_unit = dwarf.getUnit(dep).get(dwarf);
17421775 if (!dep_unit.alive) return;
17431776 try dwarf.abbrevCode(di_nw, .module_dependency);
1744 try dwarf.strp(&dwarf.debug_str, di_nw, name);
1777 try dwarf.strx(di_nw, name);
17451778 try dwarf.secOffset(di_nw, dep_unit.debug_info_header_ni.unwrap().?, module_offset);
17461779}
17471780
......@@ -1858,11 +1891,7 @@ pub fn genDebugLineHeader(
18581891 }
18591892 try dlh_w.writeInt(i64, @truncate(zf.stat.mtime.nanoseconds), dwarf.endian);
18601893 try dlh_w.writeInt(u64, zf.stat.size, dwarf.endian);
1861 try dwarf.strp(
1862 &dwarf.debug_line_str,
1863 dlh_nw,
1864 if (zf.is_builtin) zf.source.? else "",
1865 );
1894 try dwarf.strp(&dwarf.debug_line_str, dlh_nw, if (zf.is_builtin) zf.source.? else "");
18661895 }
18671896 switch (dwarf.format) {
18681897 .@"32" => std.mem.writeInt(
......@@ -1924,7 +1953,7 @@ pub fn genDebugRnglistsHeader(
19241953 try drh_w.writeByte(@backingInt(dwarf.address_size));
19251954 try drh_w.writeByte(0);
19261955 try drh_w.writeInt(u32, 1, dwarf.endian);
1927 assert(drh_w.end == Rnglists.offsetsTableOffset(dwarf));
1956 assert(drh_w.end == Rnglists.tableOffset(dwarf));
19281957 switch (dwarf.format) {
19291958 .@"32" => try drh_w.writeInt(u32, 4, dwarf.endian),
19301959 .@"64" => try drh_w.writeInt(u64, 8, dwarf.endian),
......@@ -1933,7 +1962,7 @@ pub fn genDebugRnglistsHeader(
19331962 try drh_w.writeByte(DW.RLE.end_of_list);
19341963}
19351964
1936pub fn genDebugRnglists(
1965pub fn genDebugRnglistsRange(
19371966 dwarf: *Dwarf,
19381967 unit: *Unit,
19391968 dr_nw: *link.MappedFile.Node.Writer,
......@@ -1949,6 +1978,24 @@ pub fn genDebugRnglists(
19491978 try dr_w.writeByte(DW.RLE.end_of_list);
19501979}
19511980
1981pub fn genDebugStrOffsetsHeader(dwarf: *Dwarf, dsoh_w: *std.Io.Writer) std.Io.Writer.Error!void {
1982 try dwarf.genUnitLength(dsoh_w);
1983 try dsoh_w.writeInt(u16, 5, dwarf.endian);
1984 try dsoh_w.writeInt(u16, 0, dwarf.endian);
1985 assert(dsoh_w.end == StrOffsets.tableOffset(dwarf));
1986}
1987
1988pub fn genPendingDebugStrOffsets(dwarf: *Dwarf, dso_nw: *link.MappedFile.Node.Writer) link.Error!void {
1989 dso_nw.interface.end = dwarf.debug_str_offsets.size(dwarf);
1990 for (dwarf.debug_str_offsets.map.keys()[dwarf.debug_str_offsets.pending_index..]) |offset| {
1991 dwarf.secOffset(dso_nw, dwarf.debug_str.ni.unwrap().?, offset) catch |err| switch (err) {
1992 else => |e| return e,
1993 error.WriteFailed => return dwarf.reportWriteError(dso_nw),
1994 };
1995 dwarf.debug_str_offsets.pending_index += 1;
1996 }
1997}
1998
19521999pub fn updateExtern(
19532000 dwarf: *Dwarf,
19542001 pt: Zcu.PerThread,
......@@ -2012,17 +2059,17 @@ fn updateExternInner(
20122059 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
20132060 try di_w.writeUleb128(decl.src_column + 1);
20142061 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2015 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2062 try dwarf.strx(di_nw, nav.name.toSlice(ip));
20162063 } else {
20172064 try dwarf.abbrevCode(di_nw, .decl_var);
20182065 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
20192066 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
20202067 try di_w.writeUleb128(decl.src_column + 1);
20212068 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2022 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2069 try dwarf.strx(di_nw, nav.name.toSlice(ip));
20232070 },
20242071 }
2025 try dwarf.strp(&dwarf.debug_str, di_nw, nav_extern.name.toSlice(ip));
2072 try dwarf.strx(di_nw, nav_extern.name.toSlice(ip));
20262073 if (maybe_func_type) |func_type| {
20272074 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
20282075 try dwarf.addrSym(di_nw, si, 0);
......@@ -2115,9 +2162,9 @@ fn updateGlobalInner(
21152162 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
21162163 try di_w.writeUleb128(decl.src_column + 1);
21172164 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2118 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2165 try dwarf.strx(di_nw, nav.name.toSlice(ip));
21192166 }
2120 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
2167 try dwarf.strx(di_nw, switch (decl.linkage) {
21212168 .normal => nav.fqn,
21222169 .@"extern" => unreachable,
21232170 .@"export" => nav.name,
......@@ -2286,12 +2333,12 @@ fn genComptimeGlobalInner(
22862333 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
22872334 try di_w.writeUleb128(decl.src_column + 1);
22882335 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2289 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
2336 try dwarf.strx(di_nw, nav.name.toSlice(ip));
22902337 }
22912338 switch (nav_ty.toIntern()) {
22922339 .type_type => try dwarf.refConst(pt, di_nw, nav_val),
22932340 else => {
2294 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
2341 try dwarf.strx(di_nw, switch (decl.linkage) {
22952342 .normal => nav.fqn,
22962343 .@"extern", .@"export" => nav.name,
22972344 }.toSlice(ip));
......@@ -2389,7 +2436,7 @@ fn updateConstInner(
23892436 const ty: Type = .fromInterned(val);
23902437 try dwarf.abbrevCode(di_nw, .numeric_type);
23912438 var name_buf: [std.fmt.count("i{d}", .{std.math.maxInt(u16)})]u8 = undefined;
2392 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&name_buf, "{f}", .{
2439 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
23932440 ty.fmt(pt),
23942441 }) catch unreachable);
23952442 try di_w.writeByte(switch (int_type.signedness) {
......@@ -2408,7 +2455,7 @@ fn updateConstInner(
24082455 .none => .ptr_type,
24092456 else => .ptr_sentinel_type,
24102457 });
2411 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2458 try dwarf.strx(di_nw, name);
24122459 switch (ptr_type.sentinel) {
24132460 .none => {},
24142461 else => |sentinel| try dwarf.blockConst(pt, di_nw, .fromInterned(sentinel)),
......@@ -2440,16 +2487,16 @@ fn updateConstInner(
24402487 const name = try zcu.gpa.print("{f}", .{ty.fmt(pt)});
24412488 defer zcu.gpa.free(name);
24422489 try dwarf.abbrevCode(di_nw, .generated_struct_type);
2443 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2490 try dwarf.strx(di_nw, name);
24442491 try di_w.writeUleb128(ty.abiSize(zcu));
24452492 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
24462493 try dwarf.abbrevCode(di_nw, .generated_field);
2447 try dwarf.strp(&dwarf.debug_str, di_nw, "ptr");
2494 try dwarf.strx(di_nw, "ptr");
24482495 const ptr_field_ty = ty.slicePtrFieldType(zcu);
24492496 try dwarf.refType(pt, di_nw, ptr_field_ty);
24502497 try di_w.writeUleb128(0);
24512498 try dwarf.abbrevCode(di_nw, .generated_field);
2452 try dwarf.strp(&dwarf.debug_str, di_nw, "len");
2499 try dwarf.strx(di_nw, "len");
24532500 const len_field_ty: Type = .usize;
24542501 try dwarf.refType(pt, di_nw, len_field_ty);
24552502 try di_w.writeUleb128(len_field_ty.abiAlignment(zcu).forward(ptr_field_ty.abiSize(zcu)));
......@@ -2463,7 +2510,7 @@ fn updateConstInner(
24632510 di_nw,
24642511 if (array_type.sentinel == .none) .array_type else .array_sentinel_type,
24652512 );
2466 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2513 try dwarf.strx(di_nw, name);
24672514 if (array_type.sentinel != .none)
24682515 try dwarf.blockConst(pt, di_nw, .fromInterned(array_type.sentinel));
24692516 try dwarf.refType(pt, di_nw, .fromInterned(array_type.child));
......@@ -2476,7 +2523,7 @@ fn updateConstInner(
24762523 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
24772524 defer zcu.gpa.free(name);
24782525 try dwarf.abbrevCode(di_nw, .vector_type);
2479 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2526 try dwarf.strx(di_nw, name);
24802527 try dwarf.refType(pt, di_nw, .fromInterned(vector_type.child));
24812528 try dwarf.abbrevCode(di_nw, .array_len);
24822529 try dwarf.refType(pt, di_nw, .usize);
......@@ -2490,13 +2537,13 @@ fn updateConstInner(
24902537 const name = try zcu.gpa.print("{f}", .{opt_ty.fmt(pt)});
24912538 defer zcu.gpa.free(name);
24922539 try dwarf.abbrevCode(di_nw, .generated_union_type);
2493 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2540 try dwarf.strx(di_nw, name);
24942541 try di_w.writeUleb128(opt_ty.abiSize(zcu));
24952542 try di_w.writeUleb128(opt_ty.abiAlignment(zcu).toByteUnits().?);
24962543 switch (opt_repr) {
24972544 .opv_null => {
24982545 try dwarf.abbrevCode(di_nw, .generated_field);
2499 try dwarf.strp(&dwarf.debug_str, di_nw, "null");
2546 try dwarf.strx(di_nw, "null");
25002547 try dwarf.refType(pt, di_nw, .null);
25012548 try di_w.writeUleb128(0);
25022549 },
......@@ -2507,7 +2554,7 @@ fn updateConstInner(
25072554 {
25082555 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
25092556 try dwarf.abbrevCode(di_nw, .generated_field);
2510 try dwarf.strp(&dwarf.debug_str, di_nw, "has_value");
2557 try dwarf.strx(di_nw, "has_value");
25112558 switch (opt_repr) {
25122559 .opv_null => unreachable,
25132560 .unpacked => {
......@@ -2535,7 +2582,7 @@ fn updateConstInner(
25352582 try di_w.writeByte(0);
25362583 {
25372584 try dwarf.abbrevCode(di_nw, .generated_field);
2538 try dwarf.strp(&dwarf.debug_str, di_nw, "null");
2585 try dwarf.strx(di_nw, "null");
25392586 try dwarf.refType(pt, di_nw, .null);
25402587 try di_w.writeUleb128(0);
25412588 }
......@@ -2544,7 +2591,7 @@ fn updateConstInner(
25442591 try dwarf.abbrevCode(di_nw, .tagged_union_default_field);
25452592 {
25462593 try dwarf.abbrevCode(di_nw, .generated_field);
2547 try dwarf.strp(&dwarf.debug_str, di_nw, "?");
2594 try dwarf.strx(di_nw, "?");
25482595 try dwarf.refType(pt, di_nw, opt_child_ty);
25492596 try di_w.writeUleb128(0);
25502597 }
......@@ -2571,7 +2618,7 @@ fn updateConstInner(
25712618 defer zcu.gpa.free(name);
25722619
25732620 try dwarf.abbrevCode(di_nw, .generated_union_type);
2574 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2621 try dwarf.strx(di_nw, name);
25752622 if (error_union_type.error_set_type != .generic_poison_type and
25762623 error_union_type.payload_type != .generic_poison_type)
25772624 {
......@@ -2588,7 +2635,7 @@ fn updateConstInner(
25882635 {
25892636 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
25902637 try dwarf.abbrevCode(di_nw, .generated_field);
2591 try dwarf.strp(&dwarf.debug_str, di_nw, "is_error");
2638 try dwarf.strx(di_nw, "is_error");
25922639 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
25932640 try di_w.writeUleb128(eu_error_set_offset);
25942641
......@@ -2597,7 +2644,7 @@ fn updateConstInner(
25972644 try di_w.writeUleb128(0);
25982645 {
25992646 try dwarf.abbrevCode(di_nw, .generated_field);
2600 try dwarf.strp(&dwarf.debug_str, di_nw, "value");
2647 try dwarf.strx(di_nw, "value");
26012648 try dwarf.refType(pt, di_nw, eu_payload_ty);
26022649 try di_w.writeUleb128(eu_payload_offset);
26032650 }
......@@ -2606,7 +2653,7 @@ fn updateConstInner(
26062653 try dwarf.abbrevCode(di_nw, .tagged_union_default_field);
26072654 {
26082655 try dwarf.abbrevCode(di_nw, .generated_field);
2609 try dwarf.strp(&dwarf.debug_str, di_nw, "error");
2656 try dwarf.strx(di_nw, "error");
26102657 try dwarf.refType(pt, di_nw, eu_error_set_ty);
26112658 try di_w.writeUleb128(eu_error_set_offset);
26122659 }
......@@ -2638,7 +2685,7 @@ fn updateConstInner(
26382685 => {
26392686 const ty: Type = .fromInterned(val);
26402687 try dwarf.abbrevCode(di_nw, .numeric_type);
2641 try dwarf.strp(&dwarf.debug_str, di_nw, @tagName(simple_type));
2688 try dwarf.strx(di_nw, @tagName(simple_type));
26422689 try di_w.writeByte(if (val == .bool_type)
26432690 DW.ATE.boolean
26442691 else if (ty.isRuntimeFloat())
......@@ -2655,7 +2702,7 @@ fn updateConstInner(
26552702 },
26562703 .generic_poison => {
26572704 try dwarf.abbrevCode(di_nw, .void_type);
2658 try dwarf.strp(&dwarf.debug_str, di_nw, "anytype");
2705 try dwarf.strx(di_nw, "anytype");
26592706 },
26602707 .anyopaque,
26612708 .void,
......@@ -2670,7 +2717,7 @@ fn updateConstInner(
26702717 const ty: Type = .fromInterned(val);
26712718 try dwarf.abbrevCode(di_nw, .void_type);
26722719 var name_buf: ["@TypeOf(undefined)".len]u8 = undefined;
2673 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&name_buf, "{f}", .{
2720 try dwarf.strx(di_nw, std.mem.print(&name_buf, "{f}", .{
26742721 ty.fmt(pt),
26752722 }) catch unreachable);
26762723 },
......@@ -2680,13 +2727,13 @@ fn updateConstInner(
26802727 .generated_enum_type
26812728 else
26822729 .generated_empty_enum_type);
2683 try dwarf.strp(&dwarf.debug_str, di_nw, "anyerror");
2730 try dwarf.strx(di_nw, "anyerror");
26842731 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
26852732 for (global_error_set_names, 1..) |name, value| {
26862733 try dwarf.abbrevCode(di_nw, .enum_field);
26872734 try di_w.writeUleb128(DW.FORM.udata);
26882735 try di_w.writeUleb128(value);
2689 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
2736 try dwarf.strx(di_nw, name.toSlice(ip));
26902737 }
26912738 if (global_error_set_names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
26922739 },
......@@ -2698,11 +2745,11 @@ fn updateConstInner(
26982745 defer zcu.gpa.free(name);
26992746 if (tuple_type.types.len == 0) {
27002747 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
2701 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2748 try dwarf.strx(di_nw, name);
27022749 try di_w.writeByte(@intFromBool(false));
27032750 } else {
27042751 try dwarf.abbrevCode(di_nw, .generated_struct_type);
2705 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2752 try dwarf.strx(di_nw, name);
27062753 try di_w.writeUleb128(ty.abiSize(zcu));
27072754 try di_w.writeUleb128(ty.abiAlignment(zcu).toByteUnits().?);
27082755 var field_byte_offset: u64 = 0;
......@@ -2723,7 +2770,7 @@ fn updateConstInner(
27232770 },
27242771 });
27252772 var field_name_buf: [std.fmt.count("{d}", .{std.math.maxInt(u32)})]u8 = undefined;
2726 try dwarf.strp(&dwarf.debug_str, di_nw, std.mem.print(&field_name_buf, "{d}", .{
2773 try dwarf.strx(di_nw, std.mem.print(&field_name_buf, "{d}", .{
27272774 field_index,
27282775 }) catch unreachable);
27292776 try dwarf.refType(pt, di_nw, field_ty);
......@@ -2755,7 +2802,7 @@ fn updateConstInner(
27552802 .@"extern", .@"packed" => unreachable,
27562803 });
27572804 try di_w.writeUleb128(@backingInt(fi));
2758 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));
2805 try dwarf.strx(di_nw, loaded_struct.name.toSlice(ip));
27592806 } else if (loaded_struct.captures.len > 0 or loaded_struct.is_reified) {
27602807 try dwarf.abbrevCode(di_nw, if (loaded_struct.captures.len > 0 or
27612808 loaded_struct.field_types.len > 0) switch (loaded_struct.layout) {
......@@ -2788,7 +2835,7 @@ fn updateConstInner(
27882835 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
27892836 try di_w.writeUleb128(decl.src_column + 1);
27902837 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2791 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2838 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
27922839 } else {
27932840 const decl = zf.zir.?.getStructDecl(src_inst.inst);
27942841 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
......@@ -2806,7 +2853,7 @@ fn updateConstInner(
28062853 try dwarf.secOffset(di_nw, parent_ni, 0);
28072854 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
28082855 try di_w.writeUleb128(decl.src_column + 1);
2809 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));
2856 try dwarf.strx(di_nw, loaded_struct.name.toSlice(ip));
28102857 }
28112858 switch (loaded_struct.layout) {
28122859 .auto, .@"extern" => {
......@@ -2846,8 +2893,7 @@ fn updateConstInner(
28462893 .partially_comptime => .field_default_partially_comptime,
28472894 .fully_comptime => .field_default_fully_comptime,
28482895 });
2849 try dwarf.strp(
2850 &dwarf.debug_str,
2896 try dwarf.strx(
28512897 di_nw,
28522898 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),
28532899 );
......@@ -2871,8 +2917,7 @@ fn updateConstInner(
28712917 var field_bit_offset: u16 = 0;
28722918 for (0..loaded_struct.field_types.len) |field_index| {
28732919 try dwarf.abbrevCode(di_nw, .packed_field);
2874 try dwarf.strp(
2875 &dwarf.debug_str,
2920 try dwarf.strx(
28762921 di_nw,
28772922 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),
28782923 );
......@@ -2924,7 +2969,7 @@ fn updateConstInner(
29242969 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
29252970 try di_w.writeUleb128(decl.src_column + 1);
29262971 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
2927 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
2972 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
29282973 } else {
29292974 const decl = zf.zir.?.getUnionDecl(loaded_union.zir_index.resolve(ip).?);
29302975 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
......@@ -2942,7 +2987,7 @@ fn updateConstInner(
29422987 try dwarf.secOffset(di_nw, parent_ni, 0);
29432988 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
29442989 try di_w.writeUleb128(decl.src_column + 1);
2945 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_union.name.toSlice(ip));
2990 try dwarf.strx(di_nw, loaded_union.name.toSlice(ip));
29462991 }
29472992 switch (loaded_union.layout) {
29482993 .auto, .@"extern" => {
......@@ -2957,7 +3002,7 @@ fn updateConstInner(
29573002 {
29583003 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
29593004 try dwarf.abbrevCode(di_nw, .generated_field);
2960 try dwarf.strp(&dwarf.debug_str, di_nw, "tag");
3005 try dwarf.strx(di_nw, "tag");
29613006 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.enum_tag_type));
29623007 try di_w.writeUleb128(union_layout.tagOffset());
29633008
......@@ -2966,8 +3011,7 @@ fn updateConstInner(
29663011 try dwarf.enumConstValue(di_w, loaded_tag, field_index);
29673012 {
29683013 try dwarf.abbrevCode(di_nw, .field);
2969 try dwarf.strp(
2970 &dwarf.debug_str,
3014 try dwarf.strx(
29713015 di_nw,
29723016 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
29733017 );
......@@ -2989,8 +3033,7 @@ fn updateConstInner(
29893033 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
29903034 } else for (0..loaded_union.field_types.len) |field_index| {
29913035 try dwarf.abbrevCode(di_nw, .field);
2992 try dwarf.strp(
2993 &dwarf.debug_str,
3036 try dwarf.strx(
29943037 di_nw,
29953038 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
29963039 );
......@@ -3011,8 +3054,7 @@ fn updateConstInner(
30113054 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.packed_backing_int_type));
30123055 for (0..loaded_union.field_types.len) |field_index| {
30133056 try dwarf.abbrevCode(di_nw, .packed_field);
3014 try dwarf.strp(
3015 &dwarf.debug_str,
3057 try dwarf.strx(
30163058 di_nw,
30173059 loaded_tag.field_names.get(ip)[field_index].toSlice(ip),
30183060 );
......@@ -3057,7 +3099,7 @@ fn updateConstInner(
30573099 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
30583100 try di_w.writeUleb128(decl.src_column + 1);
30593101 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3060 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
3102 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
30613103 } else {
30623104 const decl = zir.getEnumDecl(loaded_enum.zir_index.unwrap().?.resolve(ip).?);
30633105 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
......@@ -3070,7 +3112,7 @@ fn updateConstInner(
30703112 try dwarf.secOffset(di_nw, parent_ni, 0);
30713113 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
30723114 try di_w.writeUleb128(decl.src_column + 1);
3073 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));
3115 try dwarf.strx(di_nw, loaded_enum.name.toSlice(ip));
30743116 }
30753117 },
30763118 else => {
......@@ -3078,7 +3120,7 @@ fn updateConstInner(
30783120 .generated_enum_type
30793121 else
30803122 .generated_empty_enum_type);
3081 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.fqn.toSlice(ip));
3123 try dwarf.strx(di_nw, loaded_enum.fqn.toSlice(ip));
30823124 },
30833125 }
30843126 try dwarf.refType(pt, di_nw, .fromInterned(loaded_enum.int_tag_type));
......@@ -3086,11 +3128,7 @@ fn updateConstInner(
30863128 for (0..loaded_enum.field_names.len) |field_index| {
30873129 try dwarf.abbrevCode(di_nw, .enum_field);
30883130 try dwarf.enumConstValue(di_w, loaded_enum, field_index);
3089 try dwarf.strp(
3090 &dwarf.debug_str,
3091 di_nw,
3092 loaded_enum.field_names.get(ip)[field_index].toSlice(ip),
3093 );
3131 try dwarf.strx(di_nw, loaded_enum.field_names.get(ip)[field_index].toSlice(ip));
30943132 }
30953133 if (loaded_enum.captures.len > 0 or loaded_enum.field_names.len > 0)
30963134 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
......@@ -3103,7 +3141,7 @@ fn updateConstInner(
31033141 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
31043142 defer zcu.gpa.free(name);
31053143 try dwarf.abbrevCode(di_nw, if (is_empty) .empty_func_type else .func_type);
3106 try dwarf.strp(&dwarf.debug_str, di_nw, name);
3144 try dwarf.strx(di_nw, name);
31073145 const cc: DW.CC = cc: {
31083146 if (zcu.getTarget().cCallingConvention()) |cc| {
31093147 if (@as(std.lang.CallingConvention.Tag, cc) == func_type.cc) {
......@@ -3191,14 +3229,14 @@ fn updateConstInner(
31913229 di_nw,
31923230 if (error_set_type.names.len > 0) .generated_enum_type else .generated_empty_enum_type,
31933231 );
3194 try dwarf.strp(&dwarf.debug_str, di_nw, name);
3232 try dwarf.strx(di_nw, name);
31953233 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
31963234 for (0..error_set_type.names.len) |field_index| {
31973235 const field_name = error_set_type.names.get(ip)[field_index];
31983236 try dwarf.abbrevCode(di_nw, .enum_field);
31993237 try di_w.writeUleb128(DW.FORM.udata);
32003238 try di_w.writeUleb128(ip.getErrorValueIfExists(field_name).?);
3201 try dwarf.strp(&dwarf.debug_str, di_nw, field_name.toSlice(ip));
3239 try dwarf.strx(di_nw, field_name.toSlice(ip));
32023240 }
32033241 if (error_set_type.names.len > 0) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
32043242 },
......@@ -3206,7 +3244,7 @@ fn updateConstInner(
32063244 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
32073245 defer zcu.gpa.free(name);
32083246 try dwarf.abbrevCode(di_nw, .inferred_error_set_type);
3209 try dwarf.strp(&dwarf.debug_str, di_nw, name);
3247 try dwarf.strx(di_nw, name);
32103248 try dwarf.refType(pt, di_nw, switch (ies: {
32113249 const fi = dwarf.getFuncIfExists(ip.indexToKey(func).func.owner_nav) orelse
32123250 break :ies .none;
......@@ -3248,7 +3286,7 @@ fn updateConstInner(
32483286 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
32493287 try di_w.writeUleb128(decl.src_column + 1);
32503288 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3251 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
3289 try dwarf.strx(di_nw, nav.name.toSlice(ip));
32523290 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
32533291 for (
32543292 zir.getParamBody(func.zir_body_inst.resolve(ip).?)[0..func_type.param_types.len],
......@@ -3258,7 +3296,7 @@ fn updateConstInner(
32583296 .empty => try dwarf.abbrevCode(di_nw, .unnamed_param),
32593297 else => |param_name| {
32603298 try dwarf.abbrevCode(di_nw, .param);
3261 try dwarf.strp(&dwarf.debug_str, di_nw, zir.nullTerminatedString(param_name));
3299 try dwarf.strx(di_nw, zir.nullTerminatedString(param_name));
32623300 },
32633301 }
32643302 try dwarf.refType(pt, di_nw, .fromInterned(param_ty));
......@@ -3313,7 +3351,7 @@ fn updateConstInner(
33133351 }
33143352 {
33153353 try dwarf.abbrevCode(di_nw, .comptime_value_field_runtime);
3316 try dwarf.strp(&dwarf.debug_str, di_nw, "is_error");
3354 try dwarf.strx(di_nw, "is_error");
33173355 try di_w.writeUleb128(err_bytes.len);
33183356 try di_w.writeAll(err_bytes);
33193357 }
......@@ -3328,7 +3366,7 @@ fn updateConstInner(
33283366 .comptime_value_field_runtime
33293367 else
33303368 break :payload_field);
3331 try dwarf.strp(&dwarf.debug_str, di_nw, "value");
3369 try dwarf.strx(di_nw, "value");
33323370 if (payload_class.comptimeOnly())
33333371 try dwarf.refConst(pt, di_nw, .fromInterned(payload_val))
33343372 else if (payload_class.hasRuntimeBits())
......@@ -3339,7 +3377,7 @@ fn updateConstInner(
33393377 }
33403378 {
33413379 try dwarf.abbrevCode(di_nw, .comptime_value_field_runtime);
3342 try dwarf.strp(&dwarf.debug_str, di_nw, "error");
3380 try dwarf.strx(di_nw, "error");
33433381 try di_w.writeUleb128(err_bytes.len);
33443382 try di_w.writeAll(err_bytes);
33453383 }
......@@ -3348,8 +3386,8 @@ fn updateConstInner(
33483386 .enum_literal => |enum_literal| {
33493387 try dwarf.abbrevCode(di_nw, .comptime_value);
33503388 try dwarf.refType(pt, di_nw, .enum_literal);
3351 try di_w.writeUleb128(DW.FORM.strp);
3352 try dwarf.strp(&dwarf.debug_str, di_nw, enum_literal.toSlice(ip));
3389 try di_w.writeUleb128(DW.FORM.strx);
3390 try dwarf.strx(di_nw, enum_literal.toSlice(ip));
33533391 },
33543392 .enum_tag => |enum_tag| {
33553393 var big_int_space: Value.BigIntSpace = undefined;
......@@ -3493,11 +3531,11 @@ fn updateConstInner(
34933531 },
34943532 .field => |field| {
34953533 try dwarf.abbrevCode(di_nw, .access);
3496 try dwarf.strp(&dwarf.debug_str, di_nw, field.toSlice(ip));
3534 try dwarf.strx(di_nw, field.toSlice(ip));
34973535 },
34983536 .synthetic_field => |field| {
34993537 try dwarf.abbrevCode(di_nw, .access);
3500 try dwarf.strp(&dwarf.debug_str, di_nw, field);
3538 try dwarf.strx(di_nw, field);
35013539 },
35023540 .tuple_index => |index| {
35033541 try dwarf.abbrevCode(di_nw, .access);
......@@ -3505,7 +3543,7 @@ fn updateConstInner(
35053543 undefined;
35063544 const field_name = std.mem.print(&field_name_buf, "{d}", .{index}) catch
35073545 unreachable;
3508 try dwarf.strp(&dwarf.debug_str, di_nw, field_name);
3546 try dwarf.strx(di_nw, field_name);
35093547 },
35103548 };
35113549 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
......@@ -3516,12 +3554,12 @@ fn updateConstInner(
35163554 try dwarf.refType(pt, di_nw, .fromInterned(slice.ty));
35173555 {
35183556 try dwarf.abbrevCode(di_nw, .comptime_value_field_comptime);
3519 try dwarf.strp(&dwarf.debug_str, di_nw, "ptr");
3557 try dwarf.strx(di_nw, "ptr");
35203558 try dwarf.refConst(pt, di_nw, .fromInterned(slice.ptr));
35213559 }
35223560 {
35233561 try dwarf.abbrevCode(di_nw, .comptime_value_field_runtime);
3524 try dwarf.strp(&dwarf.debug_str, di_nw, "len");
3562 try dwarf.strx(di_nw, "len");
35253563 try dwarf.blockConst(pt, di_nw, .fromInterned(slice.len));
35263564 }
35273565 try di_w.writeUleb128(@backingInt(AbbrevCode.null));
......@@ -3532,7 +3570,7 @@ fn updateConstInner(
35323570 try dwarf.refType(pt, di_nw, .fromInterned(opt.ty));
35333571 {
35343572 try dwarf.abbrevCode(di_nw, .comptime_value_field_runtime);
3535 try dwarf.strp(&dwarf.debug_str, di_nw, "has_value");
3573 try dwarf.strx(di_nw, "has_value");
35363574 switch (optRepr(opt_child_ty, zcu)) {
35373575 .opv_null => try di_w.writeUleb128(0),
35383576 .unpacked => try dwarf.blockConst(pt, di_nw, .makeBool(opt.val != .none)),
......@@ -3547,7 +3585,7 @@ fn updateConstInner(
35473585 .comptime_value_field_runtime
35483586 else
35493587 break :child_field);
3550 try dwarf.strp(&dwarf.debug_str, di_nw, "?");
3588 try dwarf.strx(di_nw, "?");
35513589 if (opt_child_class.comptimeOnly())
35523590 try dwarf.refConst(pt, di_nw, .fromInterned(opt.val))
35533591 else if (opt_child_class.hasRuntimeBits())
......@@ -3575,8 +3613,7 @@ fn updateConstInner(
35753613 .comptime_value_field_runtime
35763614 else
35773615 continue);
3578 try dwarf.strp(
3579 &dwarf.debug_str,
3616 try dwarf.strx(
35803617 di_nw,
35813618 loaded_struct.field_names.get(ip)[field_index].toSlice(ip),
35823619 );
......@@ -3608,7 +3645,7 @@ fn updateConstInner(
36083645 undefined;
36093646 const field_name = std.mem.print(&field_name_buf, "{d}", .{field_index}) catch
36103647 unreachable;
3611 try dwarf.strp(&dwarf.debug_str, di_nw, field_name);
3648 try dwarf.strx(di_nw, field_name);
36123649 }
36133650 const field_value: Value = .fromInterned(switch (aggregate.storage) {
36143651 .bytes => unreachable,
......@@ -3665,7 +3702,7 @@ fn updateConstInner(
36653702 .comptime_value_field_runtime
36663703 else
36673704 .access);
3668 try dwarf.strp(&dwarf.debug_str, di_nw, field_name.toSlice(ip));
3705 try dwarf.strx(di_nw, field_name.toSlice(ip));
36693706 if (field_class.comptimeOnly())
36703707 try dwarf.refConst(pt, di_nw, .fromInterned(un.val))
36713708 else if (field_class.hasRuntimeBits())
......@@ -3727,7 +3764,7 @@ fn updateConstIncompleteInner(
37273764 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, src_inst.file);
37283765 try dwarf.abbrevCode(di_nw, .empty_file);
37293766 try di_w.writeUleb128(@backingInt(fi));
3730 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_struct.name.toSlice(ip));
3767 try dwarf.strx(di_nw, loaded_struct.name.toSlice(ip));
37313768 try di_w.writeByte(@intFromBool(true));
37323769 break :done;
37333770 },
......@@ -3798,7 +3835,7 @@ fn updateConstIncompleteInner(
37983835 const loaded_enum = ip.loadEnumType(val);
37993836 const zir_index = loaded_enum.zir_index.unwrap() orelse {
38003837 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
3801 try dwarf.strp(&dwarf.debug_str, di_nw, loaded_enum.name.toSlice(ip));
3838 try dwarf.strx(di_nw, loaded_enum.name.toSlice(ip));
38023839 try di_w.writeByte(@intFromBool(true));
38033840 break :done;
38043841 };
......@@ -3858,7 +3895,7 @@ fn updateConstIncompleteInner(
38583895 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
38593896 defer zcu.gpa.free(name);
38603897 try dwarf.abbrevCode(di_nw, .generated_empty_struct_type);
3861 try dwarf.strp(&dwarf.debug_str, di_nw, name);
3898 try dwarf.strx(di_nw, name);
38623899 try di_w.writeByte(@intFromBool(true));
38633900 },
38643901 else => |ty| {
......@@ -3899,7 +3936,7 @@ fn updateConstIncompleteInner(
38993936 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
39003937 try di_w.writeUleb128(decl.src_column + 1);
39013938 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
3902 try dwarf.strp(&dwarf.debug_str, di_nw, name_nav.name.toSlice(ip));
3939 try dwarf.strx(di_nw, name_nav.name.toSlice(ip));
39033940 } else {
39043941 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
39053942 ip.namespacePtr(namespace).parent.unwrap().?,
......@@ -3916,7 +3953,7 @@ fn updateConstIncompleteInner(
39163953 try dwarf.secOffset(di_nw, parent_ni, 0);
39173954 try di_w.writeInt(u32, src_line + 1, dwarf.endian);
39183955 try di_w.writeUleb128(src_column + 1);
3919 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
3956 try dwarf.strx(di_nw, name.toSlice(ip));
39203957 }
39213958 try dwarf.genCaptures(pt, di_nw, captures);
39223959 if (captures.len > 0) try di_w.writeByte(@backingInt(AbbrevCode.null));
......@@ -4169,7 +4206,7 @@ fn genDeclInner(
41694206 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
41704207 try di_w.writeUleb128(decl.src_column + 1);
41714208 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
4172 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
4209 try dwarf.strx(di_nw, name.toSlice(ip));
41734210 } else {
41744211 const parent_ni = try dwarf.getConstDecl(pt, ip.namespacePtr(
41754212 ip.namespacePtr(namespace).parent.unwrap().?,
......@@ -4186,21 +4223,20 @@ fn genDeclInner(
41864223 try dwarf.secOffset(di_nw, parent_ni, 0);
41874224 try di_w.writeInt(u32, src_line + 1, dwarf.endian);
41884225 try di_w.writeUleb128(src_column + 1);
4189 try dwarf.strp(&dwarf.debug_str, di_nw, name.toSlice(ip));
4226 try dwarf.strx(di_nw, name.toSlice(ip));
41904227 }
41914228 for (capture_names, captures.get(ip)) |capture_name, capture| {
41924229 try dwarf.abbrevCode(di_nw, .capture_specification);
41934230 switch (capture.unwrap()) {
4194 .@"comptime", .runtime, .nav_val => try dwarf.strp(
4195 &dwarf.debug_str,
4196 di_nw,
4197 zir.nullTerminatedString(capture_name),
4198 ),
4231 .@"comptime",
4232 .runtime,
4233 .nav_val,
4234 => try dwarf.strx(di_nw, zir.nullTerminatedString(capture_name)),
41994235 .nav_ref => {
42004236 const capture_name_slice =
42014237 try zcu.gpa.print("&{s}", .{zir.nullTerminatedString(capture_name)});
42024238 defer zcu.gpa.free(capture_name_slice);
4203 try dwarf.strp(&dwarf.debug_str, di_nw, capture_name_slice);
4239 try dwarf.strx(di_nw, capture_name_slice);
42044240 },
42054241 }
42064242 }
......@@ -4225,7 +4261,7 @@ fn genDeclInner(
42254261 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
42264262 try di_w.writeUleb128(decl.src_column + 1);
42274263 try di_w.writeByte(if (decl.is_pub) DW.ACCESS.public else DW.ACCESS.private);
4228 try dwarf.strp(&dwarf.debug_str, di_nw, nav.name.toSlice(ip));
4264 try dwarf.strx(di_nw, nav.name.toSlice(ip));
42294265 },
42304266 }
42314267 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
......@@ -4310,7 +4346,7 @@ fn genDebugAbbrev(
43104346 dwarf.debug_abbrev.end = da_w.end;
43114347}
43124348
4313pub fn secOffsetSize(dwarf: *Dwarf) usize {
4349fn secOffsetSize(dwarf: *Dwarf) usize {
43144350 return switch (dwarf.format) {
43154351 .@"32" => 4,
43164352 .@"64" => 8,
......@@ -4487,6 +4523,30 @@ fn strp(dwarf: *Dwarf, s: *Str, nw: *link.MappedFile.Node.Writer, str: []const u
44874523 });
44884524}
44894525
4526fn strx(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4527 try nw.interface.writeUleb128(try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str));
4528}
4529fn strx1(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4530 try nw.interface.writeByte(@intCast(
4531 try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str),
4532 ));
4533}
4534fn strx2(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4535 try nw.interface.writeInt(u16, @intCast(
4536 try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str),
4537 ), dwarf.endian);
4538}
4539fn strx3(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4540 try nw.interface.writeInt(u24, @intCast(
4541 try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str),
4542 ), dwarf.endian);
4543}
4544fn strx4(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4545 try nw.interface.writeInt(u32, @intCast(
4546 try dwarf.debug_str_offsets.get(dwarf, &dwarf.debug_str, nw.mf, str),
4547 ), dwarf.endian);
4548}
4549
44904550fn reportWriteError(dwarf: *Dwarf, nw: *const link.MappedFile.Node.Writer) link.Error {
44914551 switch (nw.err.?) {
44924552 else => |e| return e,
......@@ -4621,9 +4681,6 @@ pub const AbbrevCode = enum {
46214681 decl_instance_func_generic,
46224682 // the rest are unrestricted other than empty variants must not be longer
46234683 // than the non-empty variant, and so should appear first
4624 compile_unit,
4625 module,
4626 module_dependency,
46274684 empty_file,
46284685 file,
46294686 access,
......@@ -4704,6 +4761,10 @@ pub const AbbrevCode = enum {
47044761 comptime_value_field_comptime,
47054762 comptime_value_elem_runtime,
47064763 comptime_value_elem_comptime,
4764 // low-frequency should appear last
4765 compile_unit,
4766 module,
4767 module_dependency,
47074768
47084769 const decl_size = uleb128Size(@backingInt(AbbrevCode.decl_func_generic));
47094770 comptime {
......@@ -4721,13 +4782,13 @@ pub const AbbrevCode = enum {
47214782 .{ .decl_line, .data4 },
47224783 .{ .decl_column, .udata },
47234784 .{ .accessibility, .data1 },
4724 .{ .name, .strp },
4785 .{ .name, .strx },
47254786 };
47264787 const type_decl_attrs = &[_]Attr{
47274788 .{ .ZIG_parent, .ref_addr },
47284789 .{ .decl_line, .data4 },
47294790 .{ .decl_column, .udata },
4730 .{ .name, .strp },
4791 .{ .name, .strx },
47314792 };
47324793 const decl_specification_attrs = decl_attrs ++ &[_]Attr{
47334794 .{ .declaration, .flag_present },
......@@ -4959,7 +5020,7 @@ pub const AbbrevCode = enum {
49595020 .decl_const = .{
49605021 .tag = .constant,
49615022 .attrs = decl_attrs ++ .{
4962 .{ .linkage_name, .strp },
5023 .{ .linkage_name, .strx },
49635024 .{ .type, .ref_addr },
49645025 .{ .alignment, .udata },
49655026 .{ .external, .flag },
......@@ -4968,7 +5029,7 @@ pub const AbbrevCode = enum {
49685029 .decl_const_fully_runtime = .{
49695030 .tag = .constant,
49705031 .attrs = decl_attrs ++ .{
4971 .{ .linkage_name, .strp },
5032 .{ .linkage_name, .strx },
49725033 .{ .type, .ref_addr },
49735034 .{ .alignment, .udata },
49745035 .{ .external, .flag },
......@@ -4978,7 +5039,7 @@ pub const AbbrevCode = enum {
49785039 .decl_const_partially_comptime = .{
49795040 .tag = .constant,
49805041 .attrs = decl_attrs ++ .{
4981 .{ .linkage_name, .strp },
5042 .{ .linkage_name, .strx },
49825043 .{ .type, .ref_addr },
49835044 .{ .alignment, .udata },
49845045 .{ .external, .flag },
......@@ -4989,7 +5050,7 @@ pub const AbbrevCode = enum {
49895050 .decl_const_fully_comptime = .{
49905051 .tag = .constant,
49915052 .attrs = decl_attrs ++ .{
4992 .{ .linkage_name, .strp },
5053 .{ .linkage_name, .strx },
49935054 .{ .type, .ref_addr },
49945055 .{ .alignment, .udata },
49955056 .{ .external, .flag },
......@@ -4999,7 +5060,7 @@ pub const AbbrevCode = enum {
49995060 .decl_var = .{
50005061 .tag = .variable,
50015062 .attrs = decl_attrs ++ .{
5002 .{ .linkage_name, .strp },
5063 .{ .linkage_name, .strx },
50035064 .{ .type, .ref_addr },
50045065 .{ .location, .exprloc },
50055066 .{ .alignment, .udata },
......@@ -5009,7 +5070,7 @@ pub const AbbrevCode = enum {
50095070 .decl_empty_func = .{
50105071 .tag = .subprogram,
50115072 .attrs = decl_attrs ++ .{
5012 .{ .linkage_name, .strp },
5073 .{ .linkage_name, .strx },
50135074 .{ .type, .ref_addr },
50145075 .{ .low_pc, .addr },
50155076 .{ .high_pc, .data4 },
......@@ -5022,7 +5083,7 @@ pub const AbbrevCode = enum {
50225083 .tag = .subprogram,
50235084 .children = true,
50245085 .attrs = decl_attrs ++ .{
5025 .{ .linkage_name, .strp },
5086 .{ .linkage_name, .strx },
50265087 .{ .type, .ref_addr },
50275088 .{ .low_pc, .addr },
50285089 .{ .high_pc, .data4 },
......@@ -5047,7 +5108,7 @@ pub const AbbrevCode = enum {
50475108 .decl_extern_empty_func = .{
50485109 .tag = .subprogram,
50495110 .attrs = decl_attrs ++ .{
5050 .{ .linkage_name, .strp },
5111 .{ .linkage_name, .strx },
50515112 .{ .type, .ref_addr },
50525113 .{ .low_pc, .addr },
50535114 .{ .external, .flag_present },
......@@ -5058,7 +5119,7 @@ pub const AbbrevCode = enum {
50585119 .tag = .subprogram,
50595120 .children = true,
50605121 .attrs = decl_attrs ++ .{
5061 .{ .linkage_name, .strp },
5122 .{ .linkage_name, .strx },
50625123 .{ .type, .ref_addr },
50635124 .{ .low_pc, .addr },
50645125 .{ .external, .flag_present },
......@@ -5240,7 +5301,7 @@ pub const AbbrevCode = enum {
52405301 .decl_instance_const = .{
52415302 .tag = .constant,
52425303 .attrs = decl_instance_attrs ++ .{
5243 .{ .linkage_name, .strp },
5304 .{ .linkage_name, .strx },
52445305 .{ .type, .ref_addr },
52455306 .{ .alignment, .udata },
52465307 .{ .external, .flag },
......@@ -5249,7 +5310,7 @@ pub const AbbrevCode = enum {
52495310 .decl_instance_const_fully_runtime = .{
52505311 .tag = .constant,
52515312 .attrs = decl_instance_attrs ++ .{
5252 .{ .linkage_name, .strp },
5313 .{ .linkage_name, .strx },
52535314 .{ .type, .ref_addr },
52545315 .{ .alignment, .udata },
52555316 .{ .external, .flag },
......@@ -5259,7 +5320,7 @@ pub const AbbrevCode = enum {
52595320 .decl_instance_const_partially_comptime = .{
52605321 .tag = .constant,
52615322 .attrs = decl_instance_attrs ++ .{
5262 .{ .linkage_name, .strp },
5323 .{ .linkage_name, .strx },
52635324 .{ .type, .ref_addr },
52645325 .{ .alignment, .udata },
52655326 .{ .external, .flag },
......@@ -5270,7 +5331,7 @@ pub const AbbrevCode = enum {
52705331 .decl_instance_const_fully_comptime = .{
52715332 .tag = .constant,
52725333 .attrs = decl_instance_attrs ++ .{
5273 .{ .linkage_name, .strp },
5334 .{ .linkage_name, .strx },
52745335 .{ .type, .ref_addr },
52755336 .{ .alignment, .udata },
52765337 .{ .external, .flag },
......@@ -5280,7 +5341,7 @@ pub const AbbrevCode = enum {
52805341 .decl_instance_var = .{
52815342 .tag = .variable,
52825343 .attrs = decl_instance_attrs ++ .{
5283 .{ .linkage_name, .strp },
5344 .{ .linkage_name, .strx },
52845345 .{ .type, .ref_addr },
52855346 .{ .location, .exprloc },
52865347 .{ .alignment, .udata },
......@@ -5290,7 +5351,7 @@ pub const AbbrevCode = enum {
52905351 .decl_instance_empty_func = .{
52915352 .tag = .subprogram,
52925353 .attrs = decl_instance_attrs ++ .{
5293 .{ .linkage_name, .strp },
5354 .{ .linkage_name, .strx },
52945355 .{ .type, .ref_addr },
52955356 .{ .low_pc, .addr },
52965357 .{ .high_pc, .data4 },
......@@ -5303,7 +5364,7 @@ pub const AbbrevCode = enum {
53035364 .tag = .subprogram,
53045365 .children = true,
53055366 .attrs = decl_instance_attrs ++ .{
5306 .{ .linkage_name, .strp },
5367 .{ .linkage_name, .strx },
53075368 .{ .type, .ref_addr },
53085369 .{ .low_pc, .addr },
53095370 .{ .high_pc, .data4 },
......@@ -5325,41 +5386,11 @@ pub const AbbrevCode = enum {
53255386 .{ .type, .ref_addr },
53265387 },
53275388 },
5328 .compile_unit = .{
5329 .tag = .compile_unit,
5330 .children = true,
5331 .attrs = &.{
5332 .{ .language, .data1 },
5333 .{ .producer, .strp },
5334 .{ .comp_dir, .line_strp },
5335 .{ .name, .line_strp },
5336 .{ .base_types, .ref_addr },
5337 .{ .stmt_list, .sec_offset },
5338 .{ .rnglists_base, .sec_offset },
5339 .{ .ranges, .rnglistx },
5340 .{ .use_UTF8, .flag_present },
5341 },
5342 },
5343 .module = .{
5344 .tag = .module,
5345 .children = true,
5346 .attrs = &.{
5347 .{ .name, .strp },
5348 .{ .ranges, .rnglistx },
5349 },
5350 },
5351 .module_dependency = .{
5352 .tag = .imported_module,
5353 .attrs = &.{
5354 .{ .name, .strp },
5355 .{ .import, .ref_addr },
5356 },
5357 },
53585389 .empty_file = .{
53595390 .tag = .structure_type,
53605391 .attrs = &.{
53615392 .{ .decl_file, .udata },
5362 .{ .name, .strp },
5393 .{ .name, .strx },
53635394 .{ .declaration, .flag },
53645395 },
53655396 },
......@@ -5368,7 +5399,7 @@ pub const AbbrevCode = enum {
53685399 .children = true,
53695400 .attrs = &.{
53705401 .{ .decl_file, .udata },
5371 .{ .name, .strp },
5402 .{ .name, .strx },
53725403 .{ .byte_size, .udata },
53735404 .{ .alignment, .udata },
53745405 },
......@@ -5376,20 +5407,20 @@ pub const AbbrevCode = enum {
53765407 .access = .{
53775408 .tag = .member,
53785409 .attrs = &.{
5379 .{ .name, .strp },
5410 .{ .name, .strx },
53805411 },
53815412 },
53825413 .enum_field = .{
53835414 .tag = .enumerator,
53845415 .attrs = &.{
53855416 .{ .const_value, .indirect },
5386 .{ .name, .strp },
5417 .{ .name, .strx },
53875418 },
53885419 },
53895420 .generated_field = .{
53905421 .tag = .member,
53915422 .attrs = &.{
5392 .{ .name, .strp },
5423 .{ .name, .strx },
53935424 .{ .type, .ref_addr },
53945425 .{ .data_member_location, .udata },
53955426 .{ .artificial, .flag_present },
......@@ -5398,7 +5429,7 @@ pub const AbbrevCode = enum {
53985429 .field = .{
53995430 .tag = .member,
54005431 .attrs = &.{
5401 .{ .name, .strp },
5432 .{ .name, .strx },
54025433 .{ .type, .ref_addr },
54035434 .{ .data_member_location, .udata },
54045435 .{ .alignment, .udata },
......@@ -5407,7 +5438,7 @@ pub const AbbrevCode = enum {
54075438 .field_default_fully_runtime = .{
54085439 .tag = .member,
54095440 .attrs = &.{
5410 .{ .name, .strp },
5441 .{ .name, .strx },
54115442 .{ .type, .ref_addr },
54125443 .{ .data_member_location, .udata },
54135444 .{ .alignment, .udata },
......@@ -5417,7 +5448,7 @@ pub const AbbrevCode = enum {
54175448 .field_default_partially_comptime = .{
54185449 .tag = .member,
54195450 .attrs = &.{
5420 .{ .name, .strp },
5451 .{ .name, .strx },
54215452 .{ .type, .ref_addr },
54225453 .{ .data_member_location, .udata },
54235454 .{ .alignment, .udata },
......@@ -5428,7 +5459,7 @@ pub const AbbrevCode = enum {
54285459 .field_default_fully_comptime = .{
54295460 .tag = .member,
54305461 .attrs = &.{
5431 .{ .name, .strp },
5462 .{ .name, .strx },
54325463 .{ .type, .ref_addr },
54335464 .{ .data_member_location, .udata },
54345465 .{ .alignment, .udata },
......@@ -5439,7 +5470,7 @@ pub const AbbrevCode = enum {
54395470 .tag = .member,
54405471 .attrs = &.{
54415472 .{ .const_expr, .flag_present },
5442 .{ .name, .strp },
5473 .{ .name, .strx },
54435474 .{ .type, .ref_addr },
54445475 },
54455476 },
......@@ -5447,7 +5478,7 @@ pub const AbbrevCode = enum {
54475478 .tag = .member,
54485479 .attrs = &.{
54495480 .{ .const_expr, .flag_present },
5450 .{ .name, .strp },
5481 .{ .name, .strx },
54515482 .{ .type, .ref_addr },
54525483 .{ .const_value, .block },
54535484 },
......@@ -5456,7 +5487,7 @@ pub const AbbrevCode = enum {
54565487 .tag = .member,
54575488 .attrs = &.{
54585489 .{ .const_expr, .flag_present },
5459 .{ .name, .strp },
5490 .{ .name, .strx },
54605491 .{ .type, .ref_addr },
54615492 .{ .const_value, .block },
54625493 .{ .ZIG_comptime_value, .ref_addr },
......@@ -5466,7 +5497,7 @@ pub const AbbrevCode = enum {
54665497 .tag = .member,
54675498 .attrs = &.{
54685499 .{ .const_expr, .flag_present },
5469 .{ .name, .strp },
5500 .{ .name, .strx },
54705501 .{ .type, .ref_addr },
54715502 .{ .ZIG_comptime_value, .ref_addr },
54725503 },
......@@ -5474,7 +5505,7 @@ pub const AbbrevCode = enum {
54745505 .packed_field = .{
54755506 .tag = .member,
54765507 .attrs = &.{
5477 .{ .name, .strp },
5508 .{ .name, .strx },
54785509 .{ .type, .ref_addr },
54795510 .{ .data_bit_offset, .udata },
54805511 },
......@@ -5500,13 +5531,13 @@ pub const AbbrevCode = enum {
55005531 .void_type = .{
55015532 .tag = .unspecified_type,
55025533 .attrs = &.{
5503 .{ .name, .strp },
5534 .{ .name, .strx },
55045535 },
55055536 },
55065537 .numeric_type = .{
55075538 .tag = .base_type,
55085539 .attrs = &.{
5509 .{ .name, .strp },
5540 .{ .name, .strx },
55105541 .{ .encoding, .data1 },
55115542 .{ .bit_size, .udata },
55125543 .{ .byte_size, .udata },
......@@ -5516,14 +5547,14 @@ pub const AbbrevCode = enum {
55165547 .inferred_error_set_type = .{
55175548 .tag = .typedef,
55185549 .attrs = &.{
5519 .{ .name, .strp },
5550 .{ .name, .strx },
55205551 .{ .type, .ref_addr },
55215552 },
55225553 },
55235554 .ptr_type = .{
55245555 .tag = .pointer_type,
55255556 .attrs = &.{
5526 .{ .name, .strp },
5557 .{ .name, .strx },
55275558 .{ .address_class, .data1 },
55285559 .{ .type, .ref_addr },
55295560 },
......@@ -5531,7 +5562,7 @@ pub const AbbrevCode = enum {
55315562 .ptr_sentinel_type = .{
55325563 .tag = .pointer_type,
55335564 .attrs = &.{
5534 .{ .name, .strp },
5565 .{ .name, .strx },
55355566 .{ .ZIG_sentinel, .block },
55365567 .{ .address_class, .data1 },
55375568 .{ .type, .ref_addr },
......@@ -5560,7 +5591,7 @@ pub const AbbrevCode = enum {
55605591 .tag = .array_type,
55615592 .children = true,
55625593 .attrs = &.{
5563 .{ .name, .strp },
5594 .{ .name, .strx },
55645595 .{ .type, .ref_addr },
55655596 },
55665597 },
......@@ -5568,7 +5599,7 @@ pub const AbbrevCode = enum {
55685599 .tag = .array_type,
55695600 .children = true,
55705601 .attrs = &.{
5571 .{ .name, .strp },
5602 .{ .name, .strx },
55725603 .{ .ZIG_sentinel, .block },
55735604 .{ .type, .ref_addr },
55745605 },
......@@ -5577,7 +5608,7 @@ pub const AbbrevCode = enum {
55775608 .tag = .array_type,
55785609 .children = true,
55795610 .attrs = &.{
5580 .{ .name, .strp },
5611 .{ .name, .strx },
55815612 .{ .type, .ref_addr },
55825613 .{ .GNU_vector, .flag_present },
55835614 },
......@@ -5598,7 +5629,7 @@ pub const AbbrevCode = enum {
55985629 .empty_func_type = .{
55995630 .tag = .subroutine_type,
56005631 .attrs = &.{
5601 .{ .name, .strp },
5632 .{ .name, .strx },
56025633 .{ .calling_convention, .data1 },
56035634 .{ .type, .ref_addr },
56045635 },
......@@ -5607,7 +5638,7 @@ pub const AbbrevCode = enum {
56075638 .tag = .subroutine_type,
56085639 .children = true,
56095640 .attrs = &.{
5610 .{ .name, .strp },
5641 .{ .name, .strx },
56115642 .{ .calling_convention, .data1 },
56125643 .{ .type, .ref_addr },
56135644 },
......@@ -5615,7 +5646,7 @@ pub const AbbrevCode = enum {
56155646 .param = .{
56165647 .tag = .formal_parameter,
56175648 .attrs = &.{
5618 .{ .name, .strp },
5649 .{ .name, .strx },
56195650 .{ .type, .ref_addr },
56205651 },
56215652 },
......@@ -5631,7 +5662,7 @@ pub const AbbrevCode = enum {
56315662 .generated_empty_enum_type = .{
56325663 .tag = .enumeration_type,
56335664 .attrs = &.{
5634 .{ .name, .strp },
5665 .{ .name, .strx },
56355666 .{ .type, .ref_addr },
56365667 },
56375668 },
......@@ -5639,14 +5670,14 @@ pub const AbbrevCode = enum {
56395670 .tag = .enumeration_type,
56405671 .children = true,
56415672 .attrs = &.{
5642 .{ .name, .strp },
5673 .{ .name, .strx },
56435674 .{ .type, .ref_addr },
56445675 },
56455676 },
56465677 .generated_empty_struct_type = .{
56475678 .tag = .structure_type,
56485679 .attrs = &.{
5649 .{ .name, .strp },
5680 .{ .name, .strx },
56505681 .{ .declaration, .flag },
56515682 },
56525683 },
......@@ -5654,7 +5685,7 @@ pub const AbbrevCode = enum {
56545685 .tag = .structure_type,
56555686 .children = true,
56565687 .attrs = &.{
5657 .{ .name, .strp },
5688 .{ .name, .strx },
56585689 .{ .byte_size, .udata },
56595690 .{ .alignment, .udata },
56605691 },
......@@ -5663,7 +5694,7 @@ pub const AbbrevCode = enum {
56635694 .tag = .union_type,
56645695 .children = true,
56655696 .attrs = &.{
5666 .{ .name, .strp },
5697 .{ .name, .strx },
56675698 .{ .byte_size, .udata },
56685699 .{ .alignment, .udata },
56695700 },
......@@ -5671,7 +5702,7 @@ pub const AbbrevCode = enum {
56715702 .capture_specification = .{
56725703 .tag = .template_value_parameter,
56735704 .attrs = &.{
5674 .{ .name, .strp },
5705 .{ .name, .strx },
56755706 },
56765707 },
56775708 .comptime_capture = .{
......@@ -5718,7 +5749,7 @@ pub const AbbrevCode = enum {
57185749 .tag = .subprogram,
57195750 .attrs = &.{
57205751 .{ .ZIG_parent, .ref_addr },
5721 .{ .linkage_name, .strp },
5752 .{ .linkage_name, .strx },
57225753 .{ .type, .ref_addr },
57235754 .{ .low_pc, .addr },
57245755 .{ .external, .flag_present },
......@@ -5730,7 +5761,7 @@ pub const AbbrevCode = enum {
57305761 .children = true,
57315762 .attrs = &.{
57325763 .{ .ZIG_parent, .ref_addr },
5733 .{ .linkage_name, .strp },
5764 .{ .linkage_name, .strx },
57345765 .{ .type, .ref_addr },
57355766 .{ .low_pc, .addr },
57365767 .{ .external, .flag_present },
......@@ -5741,7 +5772,7 @@ pub const AbbrevCode = enum {
57415772 .tag = .variable,
57425773 .attrs = &.{
57435774 .{ .ZIG_parent, .ref_addr },
5744 .{ .linkage_name, .strp },
5775 .{ .linkage_name, .strx },
57455776 .{ .type, .ref_addr },
57465777 .{ .location, .exprloc },
57475778 .{ .alignment, .udata },
......@@ -5787,7 +5818,7 @@ pub const AbbrevCode = enum {
57875818 .arg = .{
57885819 .tag = .formal_parameter,
57895820 .attrs = &.{
5790 .{ .name, .strp },
5821 .{ .name, .strx },
57915822 .{ .type, .ref_addr },
57925823 .{ .location, .exprloc },
57935824 },
......@@ -5803,7 +5834,7 @@ pub const AbbrevCode = enum {
58035834 .tag = .formal_parameter,
58045835 .attrs = &.{
58055836 .{ .const_expr, .flag_present },
5806 .{ .name, .strp },
5837 .{ .name, .strx },
58075838 .{ .type, .ref_addr },
58085839 },
58095840 },
......@@ -5811,7 +5842,7 @@ pub const AbbrevCode = enum {
58115842 .tag = .formal_parameter,
58125843 .attrs = &.{
58135844 .{ .const_expr, .flag_present },
5814 .{ .name, .strp },
5845 .{ .name, .strx },
58155846 .{ .type, .ref_addr },
58165847 .{ .const_value, .block },
58175848 },
......@@ -5820,7 +5851,7 @@ pub const AbbrevCode = enum {
58205851 .tag = .formal_parameter,
58215852 .attrs = &.{
58225853 .{ .const_expr, .flag_present },
5823 .{ .name, .strp },
5854 .{ .name, .strx },
58245855 .{ .type, .ref_addr },
58255856 .{ .const_value, .block },
58265857 .{ .ZIG_comptime_value, .ref_addr },
......@@ -5830,7 +5861,7 @@ pub const AbbrevCode = enum {
58305861 .tag = .formal_parameter,
58315862 .attrs = &.{
58325863 .{ .const_expr, .flag_present },
5833 .{ .name, .strp },
5864 .{ .name, .strx },
58345865 .{ .type, .ref_addr },
58355866 .{ .ZIG_comptime_value, .ref_addr },
58365867 },
......@@ -5876,7 +5907,7 @@ pub const AbbrevCode = enum {
58765907 .local_var = .{
58775908 .tag = .variable,
58785909 .attrs = &.{
5879 .{ .name, .strp },
5910 .{ .name, .strx },
58805911 .{ .type, .ref_addr },
58815912 .{ .location, .exprloc },
58825913 },
......@@ -5884,14 +5915,14 @@ pub const AbbrevCode = enum {
58845915 .local_const = .{
58855916 .tag = .constant,
58865917 .attrs = &.{
5887 .{ .name, .strp },
5918 .{ .name, .strx },
58885919 .{ .type, .ref_addr },
58895920 },
58905921 },
58915922 .local_const_fully_runtime = .{
58925923 .tag = .constant,
58935924 .attrs = &.{
5894 .{ .name, .strp },
5925 .{ .name, .strx },
58955926 .{ .type, .ref_addr },
58965927 .{ .const_value, .block },
58975928 },
......@@ -5899,7 +5930,7 @@ pub const AbbrevCode = enum {
58995930 .local_const_partially_comptime = .{
59005931 .tag = .constant,
59015932 .attrs = &.{
5902 .{ .name, .strp },
5933 .{ .name, .strx },
59035934 .{ .type, .ref_addr },
59045935 .{ .const_value, .block },
59055936 .{ .ZIG_comptime_value, .ref_addr },
......@@ -5908,7 +5939,7 @@ pub const AbbrevCode = enum {
59085939 .local_const_fully_comptime = .{
59095940 .tag = .constant,
59105941 .attrs = &.{
5911 .{ .name, .strp },
5942 .{ .name, .strx },
59125943 .{ .type, .ref_addr },
59135944 .{ .ZIG_comptime_value, .ref_addr },
59145945 },
......@@ -5959,14 +5990,14 @@ pub const AbbrevCode = enum {
59595990 .comptime_value_field_runtime = .{
59605991 .tag = .member,
59615992 .attrs = &.{
5962 .{ .name, .strp },
5993 .{ .name, .strx },
59635994 .{ .const_value, .block },
59645995 },
59655996 },
59665997 .comptime_value_field_comptime = .{
59675998 .tag = .member,
59685999 .attrs = &.{
5969 .{ .name, .strp },
6000 .{ .name, .strx },
59706001 .{ .ZIG_comptime_value, .ref_addr },
59716002 },
59726003 },
......@@ -5982,6 +6013,37 @@ pub const AbbrevCode = enum {
59826013 .{ .ZIG_comptime_value, .ref_addr },
59836014 },
59846015 },
6016 .compile_unit = .{
6017 .tag = .compile_unit,
6018 .children = true,
6019 .attrs = &.{
6020 .{ .language, .data1 },
6021 .{ .base_types, .ref_addr },
6022 .{ .stmt_list, .sec_offset },
6023 .{ .rnglists_base, .sec_offset },
6024 .{ .str_offsets_base, .sec_offset },
6025 .{ .producer, .strx1 },
6026 .{ .comp_dir, .line_strp },
6027 .{ .name, .line_strp },
6028 .{ .ranges, .rnglistx },
6029 .{ .use_UTF8, .flag_present },
6030 },
6031 },
6032 .module = .{
6033 .tag = .module,
6034 .children = true,
6035 .attrs = &.{
6036 .{ .name, .strx },
6037 .{ .ranges, .rnglistx },
6038 },
6039 },
6040 .module_dependency = .{
6041 .tag = .imported_module,
6042 .attrs = &.{
6043 .{ .name, .strx },
6044 .{ .import, .ref_addr },
6045 },
6046 },
59856047 });
59866048};
59876049
src/link/Elf2.zig+200-99
......@@ -215,6 +215,7 @@ textrel_count: u32,
215215
216216dwarf: Dwarf,
217217dwarf_shared: std.enums.EnumArray(Dwarf.SharedSection, dwarf_relocs.Shared),
218dwarf_str_offsets: dwarf_relocs.StrOffsets,
218219dwarf_units: []dwarf_relocs.Unit,
219220dwarf_consts: std.array_hash_map.Auto(link.ConstPool.Index, dwarf_relocs.Const),
220221dwarf_globals: std.ArrayList(dwarf_relocs.Global),
......@@ -287,6 +288,7 @@ const Node = union(enum) {
287288
288289 debug_shared: Dwarf.SharedSection,
289290 eh_frame_footer,
291 debug_str_offsets,
290292 unit_padding,
291293 unit_frame: Dwarf.Unit.Index,
292294 unit_frame_cie: Dwarf.Unit.Index,
......@@ -880,6 +882,10 @@ const dwarf_relocs = struct {
880882 const Shared = struct {
881883 first_target_reloc: NodeReloc.Index,
882884 };
885 const StrOffsets = struct {
886 first_target_reloc: NodeReloc.Index,
887 node_relocs: std.ArrayList(NodeReloc.Index),
888 };
883889 const Unit = struct {
884890 frame_cie_first_target_reloc: NodeReloc.Index,
885891 debug_info_header_first_target_reloc: NodeReloc.Index,
......@@ -887,7 +893,7 @@ const dwarf_relocs = struct {
887893 debug_line_header_first_target_reloc: NodeReloc.Index,
888894 debug_line_header_first_node_reloc: NodeReloc.Index,
889895 debug_rnglists_first_target_reloc: NodeReloc.Index,
890 debug_rnglists_symbol_relocs: std.array_hash_map.Auto(SymbolReloc.Index, void),
896 debug_rnglists_symbol_relocs: std.ArrayList(SymbolReloc.Index),
891897 };
892898 const Const = struct {
893899 debug_info_first_target_reloc: NodeReloc.Index,
......@@ -3347,6 +3353,7 @@ pub fn symbolForAtom(elf: *Elf, atom: link.File.AtomId) link.File.SymbolId {
33473353 .copied_global,
33483354 .debug_shared,
33493355 .eh_frame_footer,
3356 .debug_str_offsets,
33503357 .unit_padding,
33513358 .unit_frame,
33523359 .unit_frame_cie,
......@@ -3866,6 +3873,10 @@ fn create(
38663873 .dwarf_shared = comptime .initFill(.{
38673874 .first_target_reloc = .none,
38683875 }),
3876 .dwarf_str_offsets = .{
3877 .first_target_reloc = .none,
3878 .node_relocs = .empty,
3879 },
38693880 .dwarf_units = &.{},
38703881 .dwarf_consts = .empty,
38713882 .dwarf_globals = .empty,
......@@ -3921,6 +3932,7 @@ pub fn deinit(elf: *Elf) void {
39213932 elf.changed_symtab_index.deinit(gpa);
39223933
39233934 elf.dwarf.deinit();
3935 elf.dwarf_str_offsets.node_relocs.deinit(gpa);
39243936 for (elf.dwarf_units) |*dwarf_unit| dwarf_unit.debug_rnglists_symbol_relocs.deinit(gpa);
39253937 gpa.free(elf.dwarf_units);
39263938 elf.dwarf_consts.deinit(gpa);
......@@ -5132,6 +5144,8 @@ fn initHeaders(
51325144 });
51335145 elf.shndx.debug_str_offsets = try elf.addSection(elf.ni.elf, .{
51345146 .name = ".debug_str_offsets",
5147 .addralign = addr_align,
5148 .node_align = elf.mf.flags.block_size,
51355149 });
51365150 },
51375151 .code_view => unreachable,
......@@ -5227,6 +5241,7 @@ fn getNodeShndx(elf: *const Elf, ni: MappedFile.Node.Index) Section.Index {
52275241 .lazy_const_data,
52285242 .debug_shared,
52295243 .eh_frame_footer,
5244 .debug_str_offsets,
52305245 .unit_padding,
52315246 .unit_frame,
52325247 .unit_debug_info,
......@@ -5274,6 +5289,7 @@ fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {
52745289 => |i| Symbol.Id.local(i.symbol(elf)).value(elf),
52755290 .debug_shared,
52765291 .eh_frame_footer,
5292 .debug_str_offsets,
52775293 .unit_padding,
52785294 .unit_frame,
52795295 .unit_frame_cie,
......@@ -5313,7 +5329,7 @@ fn computeNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 {
53135329 .lazy_code,
53145330 .lazy_const_data,
53155331 => |i| Symbol.Id.local(i.symbol(elf)).value(elf),
5316 .debug_shared, .eh_frame_footer, .unit_padding => unreachable,
5332 .debug_shared, .eh_frame_footer, .debug_str_offsets, .unit_padding => unreachable,
53175333 .unit_frame, .unit_debug_info, .unit_debug_line => {
53185334 const section_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);
53195335 break :parent_vaddr elf.getNodeShndx(parent_ni).vaddr(elf) + section_offset;
......@@ -5350,7 +5366,7 @@ fn computeNodeSectionOffset(elf: *Elf, ni: MappedFile.Node.Index) u64 {
53505366 .section, .section_manual_size => 0,
53515367 .input_section, .copied_global => unreachable,
53525368 .nav, .uav, .lazy_code, .lazy_const_data => unreachable,
5353 .debug_shared, .eh_frame_footer, .unit_padding => unreachable,
5369 .debug_shared, .eh_frame_footer, .debug_str_offsets, .unit_padding => unreachable,
53545370 .unit_frame, .unit_debug_info, .unit_debug_line => {
53555371 const parent_section_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf);
53565372 break :parent_section_offset parent_section_offset;
......@@ -5400,6 +5416,7 @@ pub fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {
54005416 .copied_global,
54015417 .debug_shared,
54025418 .eh_frame_footer,
5419 .debug_str_offsets,
54035420 .unit_padding,
54045421 .unit_frame,
54055422 .unit_frame_cie,
......@@ -7163,8 +7180,8 @@ fn updateInitFiniArraySectionSize(
71637180}
71647181
71657182pub fn prelink(elf: *Elf, prog_node: std.Progress.Node) link.Error!void {
7166 const sub_prog_node = prog_node.start("ELF Prelink", 0);
7167 defer sub_prog_node.end();
7183 const prelink_prog_node = prog_node.start("ELF Prelink", 0);
7184 defer prelink_prog_node.end();
71687185
71697186 const diags = &elf.base.comp.link_diags;
71707187 elf.prelinkInner() catch |err| switch (err) {
......@@ -7198,45 +7215,14 @@ fn prelinkInner(elf: *Elf) Error!void {
71987215 };
71997216 elf.input_pending_index += 1;
72007217
7201 try elf.nodes.ensureUnusedCapacity(gpa, 4 + 5);
7202
7203 switch (elf.shndx.debug_abbrev) {
7204 .UNDEF => {},
7205 else => |debug_abbrev_shndx| elf.dwarf.debug_abbrev.ni = .wrap(elf.addNodeAssumeCapacity(
7206 try debug_abbrev_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7207 .{ .debug_shared = .debug_abbrev },
7208 )),
7209 }
7210 switch (elf.shndx.debug_line_str) {
7211 .UNDEF => {},
7212 else => |debug_line_str_shndx| elf.dwarf.debug_line_str.ni =
7213 .wrap(elf.addNodeAssumeCapacity(
7214 try debug_line_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7215 .{ .debug_shared = .debug_line_str },
7216 )),
7217 }
7218 switch (elf.shndx.debug_str) {
7219 .UNDEF => {},
7220 else => |debug_str_shndx| elf.dwarf.debug_str.ni = .wrap(elf.addNodeAssumeCapacity(
7221 try debug_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7222 .{ .debug_shared = .debug_str },
7223 )),
7224 }
7225 switch (elf.shndx.debug_str_offsets) {
7226 .UNDEF => {},
7227 else => |debug_str_offsets_shndx| elf.dwarf.debug_str_offsets.ni =
7228 .wrap(elf.addNodeAssumeCapacity(
7229 try debug_str_offsets_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7230 .{ .debug_shared = .debug_str_offsets },
7231 )),
7232 }
7233
7234 for ([5]Section.Index{
7218 try elf.nodes.ensureUnusedCapacity(gpa, 6 + 4);
7219 for ([6]Section.Index{
72357220 elf.shndx.eh_frame,
72367221 elf.shndx.debug_frame,
72377222 elf.shndx.debug_info,
72387223 elf.shndx.debug_line,
72397224 elf.shndx.debug_rnglists,
7225 elf.shndx.debug_str_offsets,
72407226 }) |debug_shndx| {
72417227 if (debug_shndx == .UNDEF) continue;
72427228 const debug_ni = debug_shndx.get(elf).ni;
......@@ -7272,6 +7258,53 @@ fn prelinkInner(elf: *Elf) Error!void {
72727258 error.WriteFailed => return debug_nw.err.?,
72737259 };
72747260 }
7261 switch (elf.shndx.debug_abbrev) {
7262 .UNDEF => {},
7263 else => |debug_abbrev_shndx| elf.dwarf.debug_abbrev.ni = .wrap(elf.addNodeAssumeCapacity(
7264 try debug_abbrev_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7265 .{ .debug_shared = .debug_abbrev },
7266 )),
7267 }
7268 switch (elf.shndx.debug_line_str) {
7269 .UNDEF => {},
7270 else => |debug_line_str_shndx| elf.dwarf.debug_line_str.ni =
7271 .wrap(elf.addNodeAssumeCapacity(
7272 try debug_line_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7273 .{ .debug_shared = .debug_line_str },
7274 )),
7275 }
7276 switch (elf.shndx.debug_str) {
7277 .UNDEF => {},
7278 else => |debug_str_shndx| elf.dwarf.debug_str.ni = .wrap(elf.addNodeAssumeCapacity(
7279 try debug_str_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{}),
7280 .{ .debug_shared = .debug_str },
7281 )),
7282 }
7283 switch (elf.shndx.debug_str_offsets) {
7284 .UNDEF => {},
7285 else => |debug_str_offsets_shndx| {
7286 const debug_str_offsets_ni = elf.addNodeAssumeCapacity(
7287 try debug_str_offsets_shndx.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{
7288 .alignment = switch (elf.dwarf.format) {
7289 .@"32" => .@"4",
7290 .@"64" => .@"8",
7291 },
7292 .next_moved = true,
7293 .enable_next_moved = true,
7294 }),
7295 .debug_str_offsets,
7296 );
7297 elf.dwarf.debug_str_offsets.ni = .wrap(debug_str_offsets_ni);
7298
7299 var dsoh_nw: link.MappedFile.Node.Writer = undefined;
7300 debug_str_offsets_ni.writer(gpa, &elf.mf, &dsoh_nw);
7301 defer dsoh_nw.deinit();
7302 elf.dwarf.genDebugStrOffsetsHeader(&dsoh_nw.interface) catch |err| switch (err) {
7303 else => |e| return e,
7304 error.WriteFailed => return dsoh_nw.err.?,
7305 };
7306 },
7307 }
72757308 }
72767309}
72777310
......@@ -7397,6 +7430,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void {
73977430 error.WriteFailed => return dih_nw.err.?,
73987431 };
73997432 }
7433 try elf.genPendingDebugStrings(gpa);
74007434}
74017435
74027436fn flushFiles(elf: *Elf) Error!void {
......@@ -8221,6 +8255,7 @@ fn addNodeRelocAssumeCapacity(
82218255 const first_target_reloc = switch (elf.getNode(target)) {
82228256 else => unreachable,
82238257 .debug_shared => |ss| &elf.dwarf_shared.getPtr(ss).first_target_reloc,
8258 .debug_str_offsets => &elf.dwarf_str_offsets.first_target_reloc,
82248259 .unit_frame_cie => |ui| &elf.dwarf_units[@backingInt(ui)].frame_cie_first_target_reloc,
82258260 .unit_debug_info_header => |ui| &elf.dwarf_units[@backingInt(ui)].debug_info_header_first_target_reloc,
82268261 .unit_debug_line_header => |ui| &elf.dwarf_units[@backingInt(ui)].debug_line_header_first_target_reloc,
......@@ -8327,6 +8362,7 @@ fn addGotRelocAssumeCapacity(
83278362 .copied_global,
83288363 .debug_shared,
83298364 .eh_frame_footer,
8365 .debug_str_offsets,
83308366 .unit_padding,
83318367 .unit_frame,
83328368 .unit_frame_cie,
......@@ -9049,10 +9085,12 @@ fn updateFuncInner(
90499085 const unit = debug.wip_func.unit.get(debug.wip_func.dwarf);
90509086 {
90519087 var dr_nw: MappedFile.Node.Writer = undefined;
9052 unit.debug_rnglists_ni.unwrap().?.writer(gpa, &elf.mf, &dr_nw);
9088 const debug_rnglists_ni = unit.debug_rnglists_ni.unwrap().?;
9089 try debug_rnglists_ni.moved(gpa, &elf.mf);
9090 debug_rnglists_ni.writer(gpa, &elf.mf, &dr_nw);
90539091 defer dr_nw.deinit();
9054 const first_symbol_reloc = elf.symbol_relocs.items.len;
9055 debug.wip_func.dwarf.genDebugRnglists(
9092 const first_symbol_ri = elf.symbol_relocs.items.len;
9093 debug.wip_func.dwarf.genDebugRnglistsRange(
90569094 unit,
90579095 &dr_nw,
90589096 debug.wip_func.func_si,
......@@ -9064,12 +9102,9 @@ fn updateFuncInner(
90649102 const symbol_relocs = &elf.dwarf_units[@backingInt(debug.wip_func.unit)]
90659103 .debug_rnglists_symbol_relocs;
90669104 try symbol_relocs.ensureUnusedCapacity(gpa, elf.symbol_relocs.items.len -
9067 first_symbol_reloc);
9068 for (first_symbol_reloc..elf.symbol_relocs.items.len) |symbol_ri|
9069 symbol_relocs.putAssumeCapacityNoClobber(
9070 @fromBackingInt(@intCast(symbol_ri)),
9071 {},
9072 );
9105 first_symbol_ri);
9106 for (first_symbol_ri..elf.symbol_relocs.items.len) |symbol_ri|
9107 symbol_relocs.appendAssumeCapacity(@fromBackingInt(@intCast(symbol_ri)));
90739108 }
90749109 debug.wip_func.finishDebugFrameFde(func_length);
90759110 if (func.analysisUnordered(ip).inferred_error_set) {
......@@ -9153,8 +9188,8 @@ fn flushInner(
91539188 const diags = &comp.link_diags;
91549189 _ = arena;
91559190
9156 const sub_prog_node = prog_node.start("ELF Flush", 0);
9157 defer sub_prog_node.end();
9191 const flush_prog_node = prog_node.start("ELF Flush", 0);
9192 defer flush_prog_node.end();
91589193
91599194 try elf.flushFiles();
91609195
......@@ -9172,8 +9207,11 @@ fn flushInner(
91729207
91739208 while (try elf.idle(tid)) {}
91749209
9210 assert(elf.input_pending_index == elf.inputs.items.len);
9211 assert(elf.input_section_pending_index == elf.input_sections.items.len);
91759212 assert(elf.pending_uavs.items.len == 0);
91769213 assert(elf.dwarf.const_pool.pending.items.len == 0);
9214 assert(elf.dwarf.debug_str_offsets.pending_index == elf.dwarf.debug_str_offsets.map.count());
91779215
91789216 // We've done the final `idle` loop, so everything is at its final place in the file. We have a
91799217 // few more things to check and write now that addresses and offsets are finalized.
......@@ -9237,22 +9275,24 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
92379275 assert(elf.dwarf.const_pool.pending.items.len == 0);
92389276
92399277 task: {
9240 if (elf.input_pending_index < elf.inputs.items.len) {
9278 if (elf.inputs.items.len - elf.input_pending_index > 0) {
92419279 const ii: Node.InputIndex = @fromBackingInt(elf.input_pending_index);
92429280 elf.input_pending_index += 1;
9243 const sub_prog_node = elf.idleProgNode(tid, elf.input_prog_node, elf.getNode(ii.node(elf)));
9244 defer sub_prog_node.end();
9281 const idle_prog_node =
9282 elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(ii.node(elf)));
9283 defer idle_prog_node.end();
92459284 elf.flushInput(ii) catch |err| switch (err) {
92469285 else => |e| return e,
92479286 error.MappedFileIo => return diags.fail("failed to write output file: {t}", .{elf.mf.io_err.?}),
92489287 };
92499288 break :task;
92509289 }
9251 if (elf.input_section_pending_index < elf.input_sections.items.len) {
9290 if (elf.input_sections.items.len - elf.input_section_pending_index > 0) {
92529291 const isi: InputSection.Index = @fromBackingInt(elf.input_section_pending_index);
92539292 elf.input_section_pending_index += 1;
9254 const sub_prog_node = elf.idleProgNode(tid, elf.input_prog_node, elf.getNode(isi.node(elf)));
9255 defer sub_prog_node.end();
9293 const idle_prog_node =
9294 elf.startIdleProgress(tid, elf.input_prog_node, elf.getNode(isi.node(elf)));
9295 defer idle_prog_node.end();
92569296 elf.flushInputSection(isi) catch |err| switch (err) {
92579297 else => |e| return e,
92589298 error.MappedFileIo => return diags.fail("failed to write output file: {t}", .{elf.mf.io_err.?}),
......@@ -9279,8 +9319,8 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
92799319 break :task;
92809320 }
92819321 if (elf.changed_symtab_index.pop()) |kv| {
9282 const sub_prog_node = elf.mf.update_prog_node.start(kv.key.slice(elf), 0);
9283 defer sub_prog_node.end();
9322 const idle_prog_node = elf.mf.update_prog_node.start(kv.key.slice(elf), 0);
9323 defer idle_prog_node.end();
92849324
92859325 const global_name = kv.key;
92869326 const global = elf.globalByName(global_name).?;
......@@ -9359,22 +9399,23 @@ pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool {
93599399 const clean_resized = ni.cleanResized(&elf.mf);
93609400 const clean_next_moved = ni.cleanNextMoved(&elf.mf);
93619401 if (!clean_moved and !clean_resized and !clean_next_moved) continue;
9362 const sub_prog_node = elf.idleProgNode(tid, elf.mf.update_prog_node, elf.getNode(ni));
9363 defer sub_prog_node.end();
9402 const idle_prog_node = elf.startIdleProgress(tid, elf.mf.update_prog_node, elf.getNode(ni));
9403 defer idle_prog_node.end();
93649404 if (clean_moved) try elf.flushMoved(ni);
93659405 if (clean_resized) try elf.flushResized(ni);
93669406 if (clean_moved or clean_resized or clean_next_moved) try elf.flushPadding(ni);
93679407 break :task;
93689408 }
93699409 }
9370 if (elf.input_sections.items.len > elf.input_section_pending_index) return true;
9410 if (elf.inputs.items.len - elf.input_pending_index > 0) return true;
9411 if (elf.input_sections.items.len - elf.input_section_pending_index > 0) return true;
93719412 if (elf.one_shot_fixups.items.len > 0) return true;
93729413 if (elf.changed_symtab_index.count() > 0) return true;
93739414 if (elf.mf.updates.items.len > 0) return true;
93749415 return false;
93759416}
93769417
9377fn idleProgNode(
9418fn startIdleProgress(
93789419 elf: *Elf,
93799420 tid: Zcu.PerThread.Id,
93809421 prog_node: std.Progress.Node,
......@@ -9405,7 +9446,7 @@ fn idleProgNode(
94059446 }) catch &name,
94069447 .debug_shared => |ss| switch (ss) {
94079448 .debug_abbrev => "debug info abbrevs",
9408 .debug_str, .debug_str_offsets => "debug info strings",
9449 .debug_str => "debug info strings",
94099450 .debug_line_str => "line info strings",
94109451 },
94119452 .unit_frame,
......@@ -9474,29 +9515,43 @@ fn genPending(elf: *Elf, pt: Zcu.PerThread) link.Error!void {
94749515 try elf.genUav(pt, umi);
94759516 }
94769517 var lazy_it = elf.lazy.iterator();
9477 while (lazy_it.next()) |lazy| while (lazy.value.pending_index < lazy.value.map.count()) {
9518 while (lazy_it.next()) |lazy| while (lazy.value.map.count() - lazy.value.pending_index > 0) {
94789519 try elf.genLazy(pt, .{ .kind = lazy.key, .index = lazy.value.pending_index });
94799520 lazy.value.pending_index += 1;
94809521 };
9522 const gpa = elf.base.comp.gpa;
94819523 switch (elf.base.comp.config.debug_format) {
94829524 .strip => {},
9483 .dwarf => {
9484 const gpa = elf.base.comp.gpa;
9485 while (true) {
9486 const pending = elf.dwarf.pending_decl;
9487 if (pending.instance == .none) break;
9488 elf.dwarf.pending_decl = .{ .di = undefined, .instance = .none };
9489 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;
9490 try debug_info_ni.moved(gpa, &elf.mf);
9491 var di_nw: MappedFile.Node.Writer = undefined;
9492 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
9493 defer di_nw.deinit();
9494 elf.resetNodeRelocs(debug_info_ni);
9495 try elf.dwarf.genDecl(pt, &di_nw, pending.instance);
9496 }
9525 .dwarf => while (true) {
9526 const pending = elf.dwarf.pending_decl;
9527 if (pending.instance == .none) break;
9528 elf.dwarf.pending_decl = .{ .di = undefined, .instance = .none };
9529 const debug_info_ni = pending.di.get(&elf.dwarf).debug_info_ni.unwrap().?;
9530 try debug_info_ni.moved(gpa, &elf.mf);
9531 var di_nw: MappedFile.Node.Writer = undefined;
9532 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
9533 defer di_nw.deinit();
9534 elf.resetNodeRelocs(debug_info_ni);
9535 try elf.dwarf.genDecl(pt, &di_nw, pending.instance);
94979536 },
94989537 .code_view => unreachable,
94999538 }
9539 try elf.genPendingDebugStrings(gpa);
9540}
9541fn genPendingDebugStrings(elf: *Elf, gpa: std.mem.Allocator) link.Error!void {
9542 while (elf.dwarf.debug_str_offsets.map.count() - elf.dwarf.debug_str_offsets.pending_index > 0) {
9543 const debug_str_offsets_ni = elf.dwarf.debug_str_offsets.ni.unwrap().?;
9544 try debug_str_offsets_ni.moved(gpa, &elf.mf);
9545 var dso_nw: link.MappedFile.Node.Writer = undefined;
9546 debug_str_offsets_ni.writer(gpa, &elf.mf, &dso_nw);
9547 defer dso_nw.deinit();
9548 const first_node_ri = elf.node_relocs.items.len;
9549 try elf.dwarf.genPendingDebugStrOffsets(&dso_nw);
9550 const node_relocs = &elf.dwarf_str_offsets.node_relocs;
9551 try node_relocs.ensureUnusedCapacity(gpa, elf.node_relocs.items.len - first_node_ri);
9552 for (first_node_ri..elf.node_relocs.items.len) |node_ri|
9553 node_relocs.appendAssumeCapacity(@fromBackingInt(@intCast(node_ri)));
9554 }
95009555}
95019556
95029557fn genUav(
......@@ -9897,7 +9952,28 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
98979952 target_ri = target_reloc.next;
98989953 }
98999954 },
9900 .eh_frame_footer, .unit_padding, .unit_frame, .unit_debug_info, .unit_debug_line => {},
9955 .eh_frame_footer,
9956 .unit_padding,
9957 .unit_frame,
9958 .unit_debug_info,
9959 .unit_debug_line,
9960 => {},
9961 .debug_str_offsets => {
9962 const target_section_offset = elf.computeNodeSectionOffset(ni);
9963 var target_ri = elf.dwarf_str_offsets.first_target_reloc;
9964 while (target_ri != .none) {
9965 const target_reloc = target_ri.get(elf);
9966 assert(target_reloc.target == ni);
9967 target_reloc.flushMovedTarget(elf, target_section_offset);
9968 target_ri = target_reloc.next;
9969 }
9970 const node_vaddr = elf.computeNodeVAddr(ni);
9971 for (elf.dwarf_str_offsets.node_relocs.items) |node_ri| {
9972 const node_reloc = node_ri.get(elf);
9973 assert(node_reloc.node.unwrap().? == ni);
9974 node_reloc.flushMovedNode(elf, node_vaddr);
9975 }
9976 },
99019977 .unit_frame_cie => |ui| {
99029978 const target_section_offset = elf.computeNodeSectionOffset(ni);
99039979 var target_ri = elf.dwarf_units[@backingInt(ui)].frame_cie_first_target_reloc;
......@@ -9948,7 +10024,7 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
994810024 target_ri = target_reloc.next;
994910025 }
995010026 const node_vaddr = elf.computeNodeVAddr(ni);
9951 for (dwarf_unit.debug_rnglists_symbol_relocs.keys()) |symbol_ri| {
10027 for (dwarf_unit.debug_rnglists_symbol_relocs.items) |symbol_ri| {
995210028 const symbol_reloc = symbol_ri.get(elf);
995310029 assert(symbol_reloc.node.unwrap().? == ni);
995410030 symbol_reloc.flushMovedNode(elf, node_vaddr);
......@@ -10281,6 +10357,7 @@ fn flushResized(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1028110357 .lazy_const_data,
1028210358 .debug_shared,
1028310359 .eh_frame_footer,
10360 .debug_str_offsets,
1028410361 .unit_padding,
1028510362 .unit_frame,
1028610363 .unit_frame_cie,
......@@ -10304,7 +10381,8 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1030410381 const trace = tracy.trace(@src());
1030510382 defer trace.end();
1030610383
10307 switch (elf.getNode(ni)) {
10384 const node = elf.getNode(ni);
10385 switch (node) {
1030810386 .deleted => unreachable,
1030910387 .archive,
1031010388 .archive_input_member,
......@@ -10352,6 +10430,7 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1035210430 error.NoSpaceLeft => archive.strtab_member_too_big = true,
1035310431 }
1035410432 },
10433 .debug_str_offsets,
1035510434 .unit_padding,
1035610435 .unit_frame_cie,
1035710436 .unit_debug_info_header,
......@@ -10363,8 +10442,26 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1036310442 .func_debug_info,
1036410443 .func_debug_line,
1036510444 .decl_debug_info,
10366 => |_, tag| {
10367 const offset, const size = ni.location(&elf.mf).resolve(&elf.mf);
10445 => {
10446 const offset, const size = location: {
10447 const offset, const size = ni.location(&elf.mf).resolve(&elf.mf);
10448 break :location .{ offset, switch (node) {
10449 else => unreachable,
10450 .debug_str_offsets => elf.dwarf.debug_str_offsets.size(&elf.dwarf),
10451 .unit_padding,
10452 .unit_frame_cie,
10453 .unit_debug_info_header,
10454 .unit_debug_line_header,
10455 .const_debug_info,
10456 .global_debug_info,
10457 .func_frame_fde,
10458 .func_debug_info,
10459 .func_debug_line,
10460 .decl_debug_info,
10461 => size,
10462 .unit_debug_rnglists => |ui| Dwarf.Rnglists.size(&elf.dwarf, ui),
10463 } };
10464 };
1036810465 const parent_ni = ni.parent(&elf.mf).unwrap().?;
1036910466 const slice = slice: {
1037010467 if (ni.next(&elf.mf).unwrap()) |next_ni| switch (next_ni.position(&elf.mf)) {
......@@ -10376,9 +10473,9 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1037610473 break :slice parent_slice[@intCast(offset)..@intCast(next_offset)];
1037710474 },
1037810475 };
10379 switch (tag) {
10476 switch (node) {
1038010477 else => unreachable,
10381 .unit_padding, .unit_debug_rnglists => {
10478 .debug_str_offsets, .unit_padding, .unit_debug_rnglists => {
1038210479 const parent_slice = parent_ni.slicePadding(&elf.mf);
1038310480 const frame_shndx = elf.getNodeShndx(parent_ni);
1038410481 const frame_format = frame_shndx.debugFrameFormat(elf) orelse
......@@ -10453,7 +10550,7 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1045310550 break :buffer debug_slice[@intCast(parent_offset)..];
1045410551 });
1045510552 fw.end = @intCast(offset + size);
10456 switch (tag) {
10553 switch (node) {
1045710554 else => unreachable,
1045810555 .unit_debug_info_header,
1045910556 .const_debug_info,
......@@ -10470,7 +10567,7 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1047010567 error.WriteFailed => {
1047110568 fw.end = unit_padding_offset;
1047210569 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);
10473 switch (tag) {
10570 switch (node) {
1047410571 else => unreachable,
1047510572 .unit_debug_info_header,
1047610573 .const_debug_info,
......@@ -10501,8 +10598,23 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1050110598 }
1050210599 };
1050310600 var fw: Io.Writer = .fixed(slice[@intCast(size)..]);
10504 switch (tag) {
10601 switch (node) {
1050510602 else => unreachable,
10603 .debug_str_offsets, .unit_debug_rnglists => {
10604 elf.dwarf.genUnitPadding(&fw) catch |err| switch (err) {
10605 error.WriteFailed => {
10606 elf.dwarf.updateUnitLength(slice, slice.len);
10607 @memset(fw.buffer, switch (node) {
10608 else => unreachable,
10609 .debug_str_offsets => std.math.maxInt(u8),
10610 .unit_debug_rnglists => std.dwarf.RLE.end_of_list,
10611 });
10612 return;
10613 },
10614 };
10615 elf.dwarf.updateUnitLength(slice, size);
10616 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);
10617 },
1050610618 .unit_padding => elf.dwarf.updateUnitLength(slice, slice.len),
1050710619 .unit_frame_cie, .func_frame_fde => {
1050810620 elf.dwarf.updateUnitLength(slice, slice.len);
......@@ -10517,17 +10629,6 @@ fn flushPadding(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo
1051710629 .unit_debug_line_header,
1051810630 .func_debug_line,
1051910631 => Dwarf.genDebugLinePadding(&fw, fw.buffer.len) catch unreachable,
10520 .unit_debug_rnglists => {
10521 elf.dwarf.genUnitPadding(&fw) catch |err| switch (err) {
10522 error.WriteFailed => {
10523 elf.dwarf.updateUnitLength(slice, slice.len);
10524 @memset(fw.buffer, std.dwarf.RLE.end_of_list);
10525 return;
10526 },
10527 };
10528 elf.dwarf.updateUnitLength(slice, size);
10529 elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len);
10530 },
1053110632 }
1053210633 },
1053310634 .unit_frame, .unit_debug_info, .unit_debug_line => {