authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-08-11 10:50:03-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-03 11:00:56-04:00
logb9b1174d069fcf201df79cb2fbaecdfc1fc74206
tree7bad94fb34cf0c32679cea7a913d6e65e48f1fc3
parent2a122576c3042c30f9a78492252cbbc4c0424a40

Dwarf2: implement line info for inline calls


3 files changed, 250 insertions(+), 231 deletions(-)

lib/std/dwarf/AT.zig+1
......@@ -225,6 +225,7 @@ pub const ZIG_padding = 0x2cce;
225225pub const ZIG_relative_decl = 0x2cd0;
226226pub const ZIG_decl_line_relative = 0x2cd1;
227227pub const ZIG_comptime_value = 0x2cd2;
228pub const ZIG_call_line_relative = 0x2cd3;
228229pub const ZIG_sentinel = 0x2ce2;
229230
230231// UPC extension.
src/link/Dwarf2.zig+188-168
......@@ -6,9 +6,7 @@ const_pool: link.ConstPool,
66
77units: std.array_hash_map.Auto(*Module, Unit),
88/// Indices are `link.ConstPool.Index`.
9values: std.ArrayList(struct {
10 debug_info_ni: MappedFile.Node.Index,
11}),
9values: std.ArrayList(Value),
1210globals: std.array_hash_map.Auto(InternPool.Nav.Index, Global),
1311funcs: std.array_hash_map.Auto(InternPool.Nav.Index, Func),
1412
......@@ -92,6 +90,22 @@ pub const Unit = struct {
9290 }
9391};
9492
93pub const Value = struct {
94 debug_info_ni: MappedFile.Node.Index,
95
96 pub const Index = enum(u32) {
97 _,
98
99 pub fn cpi(vi: Value.Index, dwarf: *Dwarf) link.ConstPool.Index {
100 return dwarf.values[@backingInt(vi)];
101 }
102
103 pub fn get(vi: Value.Index, dwarf: *Dwarf) *Global {
104 return &dwarf.values[@backingInt(vi)];
105 }
106 };
107};
108
95109pub const Global = struct {
96110 debug_info_ni: MappedFile.Node.Index.Optional,
97111
......@@ -574,7 +588,7 @@ pub const Cfa = union(enum) {
574588pub const WipNav = struct {
575589 dwarf: *Dwarf,
576590 unit: Unit.Index,
577 func: ?Func.Index,
591 func: InternPool.Index,
578592 func_si: link.File.SymbolId,
579593 cfi: struct {
580594 loc: u32,
......@@ -590,7 +604,7 @@ pub const WipNav = struct {
590604 any_children: bool,
591605 blocks: std.ArrayList(struct {
592606 abbrev_code: u32,
593 low_pc_off: u64,
607 low_pc_off: usize,
594608 high_pc: u32,
595609 }),
596610 info_writer: MappedFile.Node.Writer,
......@@ -610,21 +624,18 @@ pub const WipNav = struct {
610624 return debug.wip_nav.genDebugFrame(loc, cfa);
611625 }
612626
613 pub fn startFunc(debug: *Debug) link.Error!void {
614 assert(debug.wip_nav.func != null);
615 debug.startDebugInfo() catch |err| switch (err) {
627 pub fn startDebugInfo(debug: *Debug) link.Error!void {
628 assert(debug.wip_nav.func != .none);
629 debug.startDebugInfoInner() catch |err| switch (err) {
616630 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.info_writer),
617631 else => |e| return e,
618632 };
619 debug.startDebugLine() catch |err| switch (err) {
620 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.line_writer),
621 else => |e| return e,
622 };
623633 }
624 fn startDebugInfo(debug: *Debug) link.EmitError!void {
634 fn startDebugInfoInner(debug: *Debug) link.EmitError!void {
625635 const dwarf = debug.wip_nav.dwarf;
626 const ip = &debug.pt.zcu.intern_pool;
627 const nav = ip.getNav(debug.wip_nav.func.?.nav(dwarf));
636 const zcu = debug.pt.zcu;
637 const ip = &zcu.intern_pool;
638 const nav = ip.getNav(zcu.funcInfo(debug.wip_nav.func).owner_nav);
628639 const diw = &debug.info_writer.interface;
629640 try diw.writeUleb128(try dwarf.refAbbrevCode(.decl_func));
630641 try debug.strp(nav.name.toSlice(ip));
......@@ -633,23 +644,27 @@ pub const WipNav = struct {
633644 debug.info_func_length_offset = diw.end;
634645 try diw.writeInt(u32, undefined, dwarf.endian);
635646 }
636 fn startDebugLine(debug: *Debug) link.EmitError!void {
647
648 pub fn startDebugLine(debug: *Debug) link.Error!void {
649 assert(debug.wip_nav.func != .none);
650 debug.startDebugLineInner() catch |err| switch (err) {
651 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.line_writer),
652 else => |e| return e,
653 };
654 }
655 fn startDebugLineInner(debug: *Debug) link.EmitError!void {
637656 const dwarf = debug.wip_nav.dwarf;
638657 const zcu = debug.pt.zcu;
639658 const ip = &zcu.intern_pool;
640 const nav = debug.wip_nav.func.?.nav(dwarf);
641 const func = zcu.funcInfo(zcu.navValue(nav).toIntern());
642 const zfi = zcu.navFileScopeIndex(nav);
659 const func = zcu.funcInfo(debug.wip_nav.func);
660 const zfi = zcu.navFileScopeIndex(func.owner_nav);
643661 const zf = zcu.fileByIndex(zfi);
644 const inst_info = ip.getNav(nav).srcInst(ip).resolveFull(ip).?;
662 const inst_info = ip.getNav(func.owner_nav).srcInst(ip).resolveFull(ip).?;
645663 const decl = zf.zir.?.getDeclaration(inst_info.inst);
646664 const dlw = &debug.line_writer.interface;
647665 try dlw.writeByte(DW.LNS.extended_op);
648666 if (zcu.comp.config.incremental) {
649 try dlw.writeUleb128(1 + @as(u7, switch (dwarf.format) {
650 .@"32" => 4,
651 .@"64" => 8,
652 }));
667 try dlw.writeUleb128(1 + dwarf.sectionOffsetSize());
653668 try dlw.writeByte(DW.LNE.ZIG_set_decl);
654669 try dwarf.sectionOffset(&debug.line_writer, debug.info_writer.ni, 0);
655670
......@@ -675,7 +690,7 @@ pub const WipNav = struct {
675690 }
676691
677692 pub fn finishFunc(debug: *Debug, func_length: u64) link.Error!void {
678 assert(debug.wip_nav.func != null);
693 assert(debug.wip_nav.func != .none);
679694 debug.finishDebugInfo(func_length) catch |err| switch (err) {
680695 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.info_writer),
681696 else => |e| return e,
......@@ -706,10 +721,9 @@ pub const WipNav = struct {
706721 debug: *Debug,
707722 tag: LocalVarTag,
708723 opt_name: ?[]const u8,
709 ty: Type,
724 ty: ZigType,
710725 loc: Loc,
711726 ) link.Error!void {
712 if (true) return;
713727 return debug.genLocalVarDebugInfoInner(tag, opt_name, ty, loc) catch |err| switch (err) {
714728 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.info_writer),
715729 else => |e| e,
......@@ -719,16 +733,16 @@ pub const WipNav = struct {
719733 debug: *Debug,
720734 tag: LocalVarTag,
721735 opt_name: ?[]const u8,
722 ty: Type,
736 ty: ZigType,
723737 loc: Loc,
724738 ) link.EmitError!void {
725 assert(debug.wip_nav.func != null);
739 assert(debug.wip_nav.func != .none);
726740 try debug.abbrevCode(switch (tag) {
727741 .arg => if (opt_name) |_| .arg else .unnamed_arg,
728742 .local_var => if (opt_name) |_| .local_var else unreachable,
729743 });
730744 if (opt_name) |name| try debug.strp(name);
731 try debug.refType(ty);
745 if (false) try debug.refType(ty);
732746 try debug.infoExprLoc(loc);
733747 debug.any_children = true;
734748 }
......@@ -738,9 +752,8 @@ pub const WipNav = struct {
738752 debug: *Debug,
739753 tag: LocalConstTag,
740754 opt_name: ?[]const u8,
741 val: Value,
755 val: ZigValue,
742756 ) link.Error!void {
743 if (true) return;
744757 return debug.genLocalConstDebugInfoInner(tag, opt_name, val) catch |err| switch (err) {
745758 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.info_writer),
746759 else => |e| e,
......@@ -750,9 +763,9 @@ pub const WipNav = struct {
750763 debug: *Debug,
751764 tag: LocalConstTag,
752765 opt_name: ?[]const u8,
753 val: Value,
766 val: ZigValue,
754767 ) link.EmitError!void {
755 assert(debug.wip_nav.func != null);
768 assert(debug.wip_nav.func != .none);
756769 const zcu = debug.pt.zcu;
757770 const ty = val.typeOf(zcu);
758771 const has_runtime_bits = ty.hasRuntimeBits(zcu);
......@@ -771,21 +784,20 @@ pub const WipNav = struct {
771784 .local_const => if (opt_name) |_| .local_const else unreachable,
772785 });
773786 if (opt_name) |name| try debug.strp(name);
774 try debug.refType(ty);
787 if (false) try debug.refType(ty);
775788 if (has_runtime_bits) try debug.blockValue(val);
776 if (has_comptime_state) try debug.refValue(val);
789 if (false and has_comptime_state) try debug.refValue(val);
777790 debug.any_children = true;
778791 }
779792
780793 pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void {
781 if (true) return;
782794 return debug.genVarArgsDebugInfoInner() catch |err| switch (err) {
783795 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.info_writer),
784796 else => |e| e,
785797 };
786798 }
787799 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {
788 assert(debug.wip_nav.func != null);
800 assert(debug.wip_nav.func != .none);
789801 try debug.abbrevCode(.is_var_args);
790802 debug.any_children = true;
791803 }
......@@ -888,14 +900,13 @@ pub const WipNav = struct {
888900 try debug.line_writer.interface.writeByte(DW.LNS.set_epilogue_begin);
889901 }
890902
891 pub fn enterBlock(debug: *Debug, code_off: u64) link.Error!void {
903 pub fn enterBlock(debug: *Debug, code_off: usize) link.Error!void {
892904 return debug.enterBlockInner(code_off) catch |err| switch (err) {
893905 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.info_writer),
894906 else => |e| e,
895907 };
896908 }
897 fn enterBlockInner(debug: *Debug, code_off: u64) link.EmitError!void {
898 if (true) return;
909 fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
899910 const dwarf = debug.wip_nav.dwarf;
900911 const diw = &debug.info_writer.interface;
901912 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);
......@@ -909,14 +920,13 @@ pub const WipNav = struct {
909920 debug.any_children = false;
910921 }
911922
912 pub fn leaveBlock(debug: *Debug, code_off: u64) link.Error!void {
913 if (true) return;
923 pub fn leaveBlock(debug: *Debug, code_off: usize) link.Error!void {
914924 return debug.leaveBlockInner(code_off) catch |err| switch (err) {
915925 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.info_writer),
916926 else => |e| e,
917927 };
918928 }
919 fn leaveBlockInner(debug: *Debug, code_off: u64) link.EmitError!void {
929 fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
920930 const dwarf = debug.wip_nav.dwarf;
921931 const block_bytes = comptime uleb128Bytes(@backingInt(AbbrevCode.block));
922932 const block = debug.blocks.pop().?;
......@@ -940,11 +950,10 @@ pub const WipNav = struct {
940950 pub fn enterInlineFunc(
941951 debug: *Debug,
942952 func: InternPool.Index,
943 code_off: u64,
953 code_off: usize,
944954 line: u32,
945955 column: u32,
946956 ) link.Error!void {
947 if (true) return;
948957 return debug.enterInlineFuncInner(func, code_off, line, column) catch |err| switch (err) {
949958 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.info_writer),
950959 else => |e| e,
......@@ -953,7 +962,7 @@ pub const WipNav = struct {
953962 fn enterInlineFuncInner(
954963 debug: *Debug,
955964 func: InternPool.Index,
956 code_off: u64,
965 code_off: usize,
957966 line: u32,
958967 column: u32,
959968 ) link.EmitError!void {
......@@ -964,8 +973,12 @@ pub const WipNav = struct {
964973
965974 block.abbrev_code = @intCast(diw.end);
966975 try debug.abbrevCode(.inlined_func);
967 try debug.refNav(zcu.funcInfo(func).owner_nav);
968 try diw.writeUleb128(zcu.navSrcLine(debug.wip_nav.func.?.nav(dwarf)) + line + 1);
976 try debug.refFunc(func);
977 try diw.writeUleb128((if (zcu.comp.config.incremental)
978 0
979 else
980 zcu.navSrcLine(zcu.funcInfo(debug.wip_nav.func).owner_nav) + 1) + line);
981 try diw.writeUleb128(line);
969982 try diw.writeUleb128(column + 1);
970983 block.low_pc_off = code_off;
971984 try debug.infoAddrSym(debug.wip_nav.func_si, code_off);
......@@ -975,8 +988,7 @@ pub const WipNav = struct {
975988 debug.any_children = false;
976989 }
977990
978 pub fn leaveInlineFunc(debug: *Debug, func: InternPool.Index, code_off: u64) link.Error!void {
979 if (true) return;
991 pub fn leaveInlineFunc(debug: *Debug, func: InternPool.Index, code_off: usize) link.Error!void {
980992 return debug.leaveInlineFuncInner(func, code_off) catch |err| switch (err) {
981993 error.WriteFailed => return debug.wip_nav.reportWriteError(&debug.info_writer),
982994 else => |e| e,
......@@ -985,7 +997,7 @@ pub const WipNav = struct {
985997 fn leaveInlineFuncInner(
986998 debug: *Debug,
987999 func: InternPool.Index,
988 code_off: u64,
1000 code_off: usize,
9891001 ) link.EmitError!void {
9901002 const dwarf = debug.wip_nav.dwarf;
9911003 const inlined_func_bytes = comptime uleb128Bytes(@backingInt(AbbrevCode.inlined_func));
......@@ -1016,55 +1028,35 @@ pub const WipNav = struct {
10161028 };
10171029 }
10181030 fn setInlineFuncInner(debug: *Debug, func: InternPool.Index) link.EmitError!void {
1019 const wip_nav = &debug.wip_nav;
10201031 const zcu = debug.pt.zcu;
1021 const dwarf = wip_nav.dwarf;
1022
1023 const func_index = try dwarf.getFunc(zcu.funcInfo(func).owner_nav);
1024 if (wip_nav.func == func_index) return;
1032 const dwarf = debug.wip_nav.dwarf;
1033 if (debug.wip_nav.func == func) return;
10251034
1026 if (true) @panic("TODO");
10271035 const new_func_info = zcu.funcInfo(func);
1028 const new_file = zcu.navFileScopeIndex(new_func_info.owner_nav);
1029 const new_unit = try dwarf.getUnit(zcu.fileByIndex(new_file).mod.?);
10301036
10311037 const dlw = &debug.line_writer.interface;
10321038 if (zcu.comp.config.incremental) {
1033 const new_func_gop = try dwarf.funcs.getOrPut(zcu.gpa, new_func_info.owner_nav);
1034 errdefer _ = if (!new_func_gop.found_existing) dwarf.funcs.pop();
1035 if (!new_func_gop.found_existing) new_func_gop.value_ptr.* = .{
1036 .frame_node = .none,
1037 .debug_info_node = .none,
1038 .debug_line_node = .none,
1039 };
1040
1041 const section_offset_size: u4 = switch (dwarf.format) {
1042 .@"32" => 4,
1043 .@"64" => 8,
1044 };
1045
1039 const new_func = try dwarf.getFunc(new_func_info.owner_nav);
10461040 try dlw.writeByte(DW.LNS.extended_op);
1047 try dlw.writeUleb128(1 + section_offset_size);
1041 try dlw.writeUleb128(1 + dwarf.sectionOffsetSize());
10481042 try dlw.writeByte(DW.LNE.ZIG_set_decl);
1049 try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_section_relocs.append(zcu.gpa, .{
1050 .source_off = @bitCast(@as(u64, dlw.end)),
1051 .target_sec = .debug_info,
1052 .target_unit = new_unit,
1053 .target_entry = new_func_gop.value_ptr.toOptional(),
1054 });
1055 try dlw.splatByteAll(0, section_offset_size);
1043 try dwarf.sectionOffset(
1044 &debug.line_writer,
1045 new_func.get(dwarf).debug_info_ni.unwrap().?,
1046 0,
1047 );
10561048 return;
10571049 }
10581050
1059 const old_func_info = zcu.funcInfo(wip_nav.func);
1060 const old_file = zcu.navFileScopeIndex(old_func_info.owner_nav);
1061 if (old_file != new_file) {
1062 const mod_info = dwarf.getModInfo(wip_nav.unit);
1063 try mod_info.dirs.put(zcu.gpa, new_unit, {});
1064 const file_gop = try mod_info.files.getOrPut(zcu.gpa, new_file);
1051 const old_func_info = zcu.funcInfo(debug.wip_nav.func);
1052 const old_zfi = zcu.navFileScopeIndex(old_func_info.owner_nav);
1053 const new_zfi = zcu.navFileScopeIndex(new_func_info.owner_nav);
1054 if (old_zfi != new_zfi) {
1055 const new_ui = dwarf.getUnit(zcu.fileByIndex(new_zfi).mod.?);
1056 _, const new_fi = try debug.wip_nav.unit.get(dwarf).getFile(zcu.gpa, new_ui, new_zfi);
10651057
10661058 try dlw.writeByte(DW.LNS.set_file);
1067 try dlw.writeUleb128(file_gop.index);
1059 try dlw.writeUleb128(@backingInt(new_fi));
10681060 }
10691061
10701062 const old_src_line: i33 = zcu.navSrcLine(old_func_info.owner_nav);
......@@ -1074,7 +1066,7 @@ pub const WipNav = struct {
10741066 try dlw.writeSleb128(new_src_line - old_src_line);
10751067 }
10761068
1077 wip_nav.func = func;
1069 debug.wip_nav.func = func;
10781070 }
10791071
10801072 fn abbrevCode(debug: *Debug, abbrev_code: AbbrevCode) link.EmitError!void {
......@@ -1083,14 +1075,6 @@ pub const WipNav = struct {
10831075 );
10841076 }
10851077
1086 fn infoSectionOffset(
1087 debug: *Debug,
1088 target_ni: MappedFile.Node.Index,
1089 addend: i64,
1090 ) link.EmitError!void {
1091 try debug.wip_nav.dwarf.sectionOffset(&debug.info_writer, target_ni, addend);
1092 }
1093
10941078 fn strp(debug: *Debug, str: []const u8) link.EmitError!void {
10951079 const dwarf = debug.wip_nav.dwarf;
10961080 try dwarf.strp(&dwarf.debug_str, &debug.info_writer, str);
......@@ -1119,8 +1103,8 @@ pub const WipNav = struct {
11191103 fn addrSym(ctx: @This(), si: link.File.SymbolId) link.EmitError!void {
11201104 try ctx.debug.infoAddrSym(si, 0);
11211105 }
1122 fn infoEntry(ctx: @This(), node: MappedFile.Node.Index) link.EmitError!void {
1123 try ctx.debug.infoSectionOffset(node, 0);
1106 fn infoEntry(ctx: @This(), ni: MappedFile.Node.Index) link.EmitError!void {
1107 try ctx.debug.wip_nav.dwarf.sectionOffset(&ctx.debug.info_writer, ni, 0);
11241108 }
11251109 } = .{ .debug = debug };
11261110 try adapter.writer().writeUleb128(counter.dw.fullCount());
......@@ -1131,28 +1115,37 @@ pub const WipNav = struct {
11311115 try debug.wip_nav.dwarf.symbolAddress(&debug.info_writer, si, addend);
11321116 }
11331117
1134 fn refNav(debug: *Debug, nav_index: InternPool.Nav.Index) link.EmitError!void {
1135 try debug.infoSectionOffset(try debug.wip_nav.dwarf.getNavNode(nav_index), 0);
1118 fn refFunc(debug: *Debug, func: InternPool.Index) link.EmitError!void {
1119 const dwarf = debug.wip_nav.dwarf;
1120 const fi = try dwarf.getFunc(debug.pt.zcu.funcInfo(func).owner_nav);
1121 try debug.wip_nav.dwarf.sectionOffset(
1122 &debug.info_writer,
1123 fi.get(dwarf).debug_info_ni.unwrap().?,
1124 0,
1125 );
11361126 }
11371127
1138 fn refType(debug: *Debug, ty: Type) link.EmitError!void {
1128 fn refType(debug: *Debug, ty: ZigType) link.EmitError!void {
11391129 return debug.refValue(ty.toValue());
11401130 }
11411131
1142 fn refValue(debug: *Debug, value: Value) link.EmitError!void {
1143 try debug.infoSectionOffset(.debug_info, try debug.getValueNode(value), 0);
1132 fn refValue(debug: *Debug, value: ZigValue) link.EmitError!void {
1133 try debug.wip_nav.dwarf.sectionOffset(&debug.info_writer, try debug.getValueNode(value), 0);
11441134 }
11451135
1146 fn getValueNode(debug: *Debug, value: Value) link.Error!MappedFile.Node.Index {
1147 if (value.typeOf(debug.zcu).toIntern() != .type_type) {
1148 assert(value.typeOf(debug.zcu).comptimeOnly(debug.zcu));
1136 fn getValueNode(debug: *Debug, value: ZigValue) link.Error!MappedFile.Node.Index {
1137 const zcu = debug.pt.zcu;
1138 if (value.typeOf(zcu).toIntern() != .type_type) {
1139 assert(value.typeOf(zcu).comptimeOnly(zcu));
11491140 }
11501141 const dwarf = debug.wip_nav.dwarf;
1151 const index = try dwarf.const_pool.get(debug.pt, .{ .dwarf = dwarf }, value.toIntern());
1152 return dwarf.values.items[@backingInt(index)];
1142 const index = try dwarf.const_pool.get(debug.pt, .{
1143 .elf2 = dwarf.lf.cast(.elf2).?,
1144 }, value.toIntern());
1145 return dwarf.values.items[@backingInt(index)].debug_info_ni;
11531146 }
11541147
1155 fn blockValue(debug: *Debug, val: Value) link.EmitError!void {
1148 fn blockValue(debug: *Debug, val: ZigValue) link.EmitError!void {
11561149 const ty = val.typeOf(debug.pt.zcu);
11571150 const diw = &debug.info_writer.interface;
11581151 const size = ty.abiSize(debug.pt.zcu);
......@@ -1190,7 +1183,7 @@ pub const WipNav = struct {
11901183 };
11911184 }
11921185 fn genDebugFrameHeaderInner(wip_nav: *WipNav) link.EmitError!void {
1193 assert(wip_nav.func != null);
1186 assert(wip_nav.func != .none);
11941187 const dwarf = wip_nav.dwarf;
11951188 const dfw = &wip_nav.fde_writer.interface;
11961189 try dwarf.genUnitLength(dfw);
......@@ -1214,7 +1207,11 @@ pub const WipNav = struct {
12141207 try dfw.writeUleb128(0);
12151208 },
12161209 .debug_frame => {
1217 try wip_nav.frameSectionOffset(wip_nav.unit.get(dwarf).cie_ni.unwrap().?, 0);
1210 try dwarf.sectionOffset(
1211 &wip_nav.fde_writer,
1212 wip_nav.unit.get(dwarf).cie_ni.unwrap().?,
1213 0,
1214 );
12181215 try wip_nav.frameAddrSym(wip_nav.func_si, 0);
12191216 wip_nav.frame_func_length = .{ .offset = dfw.end, .size = dwarf.address_size };
12201217 try dfw.splatByteAll(undefined, @backingInt(dwarf.address_size));
......@@ -1229,7 +1226,7 @@ pub const WipNav = struct {
12291226 };
12301227 }
12311228 fn genDebugFrameInner(wip_nav: *WipNav, loc: u32, cfa: Cfa) link.EmitError!void {
1232 assert(wip_nav.func != null);
1229 assert(wip_nav.func != .none);
12331230 const loc_cfa: Cfa = .{ .advance_loc = loc };
12341231 try loc_cfa.write(wip_nav);
12351232 try cfa.write(wip_nav);
......@@ -1284,14 +1281,6 @@ pub const WipNav = struct {
12841281 }
12851282 };
12861283
1287 fn frameSectionOffset(
1288 wip_nav: *WipNav,
1289 target_ni: MappedFile.Node.Index,
1290 addend: usize,
1291 ) link.EmitError!void {
1292 try wip_nav.dwarf.sectionOffset(&wip_nav.fde_writer, target_ni, addend);
1293 }
1294
12951284 fn frameExprLoc(wip_nav: *WipNav, loc: Loc) link.EmitError!void {
12961285 var buf: [64]u8 = undefined;
12971286 var counter: ExprLocCounter = .init(wip_nav.dwarf, &buf);
......@@ -1308,8 +1297,8 @@ pub const WipNav = struct {
13081297 fn addrSym(ctx: @This(), si: link.File.SymbolId) link.EmitError!void {
13091298 try ctx.wip_nav.frameAddrSym(si, 0);
13101299 }
1311 fn infoEntry(ctx: @This(), node: MappedFile.Node.Index) link.EmitError!void {
1312 try ctx.wip_nav.frameSectionOffset(node, 0);
1300 fn infoEntry(ctx: @This(), ni: MappedFile.Node.Index) link.EmitError!void {
1301 try ctx.wip_nav.dwarf.sectionOffset(&ctx.wip_nav.fde_writer, ni, 0);
13131302 }
13141303 } = .{ .wip_nav = wip_nav };
13151304 try adapter.writer().writeUleb128(counter.dw.fullCount());
......@@ -1476,33 +1465,57 @@ pub fn getUnit(dwarf: *Dwarf, mod: *Module) Unit.Index {
14761465 return @fromBackingInt(@intCast(dwarf.units.getIndex(mod).?));
14771466}
14781467
1479fn getNavNode(dwarf: *Dwarf, nav_index: InternPool.Nav.Index) link.Error!MappedFile.Node.Index {
1480 if (true) @panic("TODO");
1481 const zcu = dwarf.linkFile().comp.zcu.?;
1482 const ip = &zcu.intern_pool;
1483 const nav = ip.getNav(nav_index);
1484 const unit = try dwarf.getUnit(zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?);
1485 const gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index);
1486 if (gop.found_existing) return .{ unit, gop.value_ptr.* };
1487 const entry = try dwarf.addCommonEntry(unit);
1488 gop.value_ptr.* = entry;
1489 return .{ unit, entry };
1490}
1491
1492pub fn getFunc(dwarf: *Dwarf, owner_nav: InternPool.Nav.Index) std.mem.Allocator.Error!Func.Index {
1493 const func_gop = try dwarf.funcs.getOrPut(dwarf.lf.comp.gpa, owner_nav);
1468pub fn getFunc(dwarf: *Dwarf, owner_nav: InternPool.Nav.Index) link.Error!Func.Index {
1469 const comp = dwarf.lf.comp;
1470 const gpa = comp.gpa;
1471 const func_gop = try dwarf.funcs.getOrPut(gpa, owner_nav);
14941472 if (!func_gop.found_existing) func_gop.value_ptr.* = .{
14951473 .fde_ni = .none,
14961474 .debug_info_ni = .none,
14971475 .debug_line_ni = .none,
14981476 };
1499 return @fromBackingInt(@intCast(func_gop.index));
1477 const fi: Func.Index = @fromBackingInt(@intCast(func_gop.index));
1478 if (func_gop.value_ptr.debug_info_ni == .none) {
1479 const elf = dwarf.lf.cast(.elf2).?;
1480 try elf.nodes.ensureUnusedCapacity(gpa, 1);
1481 try elf.dwarf_funcs.ensureUnusedCapacity(gpa, 1);
1482 const unit = dwarf.getUnit(comp.zcu.?.navFileScope(owner_nav).mod.?).get(dwarf);
1483 func_gop.value_ptr.debug_info_ni =
1484 .wrap(unit.debug_info_ni.unwrap().?.addFloatingChild(&elf.mf, gpa, .{
1485 .enable_next_moved = true,
1486 }) catch |err| switch (err) {
1487 else => |e| return e,
1488 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
1489 elf.mf.io_err.?,
1490 }),
1491 });
1492 elf.nodes.appendAssumeCapacity(.{ .func_debug_info = fi });
1493 elf.dwarf_funcs.addOneAssumeCapacity().* = .{
1494 .frame_fde_first_symbol_reloc = .none,
1495 .frame_fde_first_node_reloc = .none,
1496 .debug_info_first_target_reloc = .none,
1497 .debug_info_first_symbol_reloc = .none,
1498 .debug_info_first_node_reloc = .none,
1499 .debug_line_first_symbol_reloc = .none,
1500 .debug_line_first_node_reloc = .none,
1501 };
1502 }
1503 return fi;
1504}
1505pub fn getFuncIfExists(dwarf: *Dwarf, owner_nav: InternPool.Nav.Index) ?Func.Index {
1506 return @fromBackingInt(@intCast(dwarf.funcs.getIndex(owner_nav) orelse return null));
15001507}
15011508
15021509pub fn unitLengthSize(dwarf: *Dwarf) usize {
15031510 return switch (dwarf.format) {
15041511 .@"32" => 4,
1505 .@"64" => 12,
1512 .@"64" => 4 + 8,
1513 };
1514}
1515pub fn sectionOffsetSize(dwarf: *Dwarf) usize {
1516 return switch (dwarf.format) {
1517 .@"32" => 4,
1518 .@"64" => 8,
15061519 };
15071520}
15081521pub fn genUnitLength(dwarf: *Dwarf, w: *Writer) Writer.Error!void {
......@@ -1896,8 +1909,9 @@ fn refAbbrevCode(
18961909 return backing_int;
18971910 }
18981911 const elf = dwarf.lf.cast(.elf2).?;
1912 const comp = elf.base.comp;
18991913 var nw: MappedFile.Node.Writer = undefined;
1900 dwarf.debug_abbrev.ni.unwrap().?.writer(&elf.mf, elf.base.comp.gpa, &nw);
1914 dwarf.debug_abbrev.ni.unwrap().?.writer(&elf.mf, comp.gpa, &nw);
19011915 defer nw.deinit();
19021916 const abbrev = AbbrevCode.abbrevs.get(abbrev_code);
19031917 const daw = &nw.interface;
......@@ -1905,7 +1919,13 @@ fn refAbbrevCode(
19051919 try daw.writeUleb128(@backingInt(abbrev_code));
19061920 try daw.writeUleb128(@backingInt(abbrev.tag));
19071921 try daw.writeByte(if (abbrev.children) DW.CHILDREN.yes else DW.CHILDREN.no);
1908 for (abbrev.attrs) |*attr| inline for (attr) |info| try daw.writeUleb128(@backingInt(info));
1922 for (abbrev.attrs) |*attr| {
1923 try daw.writeUleb128(@backingInt(switch (attr[0]) {
1924 else => |at| at,
1925 .ZIG_call_line_relative => |at| if (comp.config.incremental) at else .call_line,
1926 }));
1927 try daw.writeUleb128(@backingInt(attr[1]));
1928 }
19091929 for (0..2) |_| try daw.writeUleb128(0);
19101930 dwarf.debug_abbrev.offset = daw.end;
19111931 dwarf.debug_abbrev.set.insert(abbrev_code);
......@@ -2958,7 +2978,7 @@ pub const AbbrevCode = enum {
29582978 .tag = .inlined_subroutine,
29592979 .attrs = &.{
29602980 .{ .abstract_origin, .ref_addr },
2961 .{ .call_line, .udata },
2981 .{ .ZIG_call_line_relative, .udata },
29622982 .{ .call_column, .udata },
29632983 .{ .low_pc, .addr },
29642984 .{ .high_pc, .data4 },
......@@ -2969,7 +2989,7 @@ pub const AbbrevCode = enum {
29692989 .children = true,
29702990 .attrs = &.{
29712991 .{ .abstract_origin, .ref_addr },
2972 .{ .call_line, .udata },
2992 .{ .ZIG_call_line_relative, .udata },
29732993 .{ .call_column, .udata },
29742994 .{ .low_pc, .addr },
29752995 .{ .high_pc, .data4 },
......@@ -2979,14 +2999,14 @@ pub const AbbrevCode = enum {
29792999 .tag = .formal_parameter,
29803000 .attrs = &.{
29813001 .{ .name, .strp },
2982 .{ .type, .ref_addr },
3002 //.{ .type, .ref_addr },
29833003 .{ .location, .exprloc },
29843004 },
29853005 },
29863006 .unnamed_arg = .{
29873007 .tag = .formal_parameter,
29883008 .attrs = &.{
2989 .{ .type, .ref_addr },
3009 //.{ .type, .ref_addr },
29903010 .{ .location, .exprloc },
29913011 },
29923012 },
......@@ -2995,14 +3015,14 @@ pub const AbbrevCode = enum {
29953015 .attrs = &.{
29963016 .{ .const_expr, .flag_present },
29973017 .{ .name, .strp },
2998 .{ .type, .ref_addr },
3018 //.{ .type, .ref_addr },
29993019 },
30003020 },
30013021 .unnamed_comptime_arg = .{
30023022 .tag = .formal_parameter,
30033023 .attrs = &.{
30043024 .{ .const_expr, .flag_present },
3005 .{ .type, .ref_addr },
3025 //.{ .type, .ref_addr },
30063026 },
30073027 },
30083028 .comptime_arg_runtime_bits = .{
......@@ -3010,7 +3030,7 @@ pub const AbbrevCode = enum {
30103030 .attrs = &.{
30113031 .{ .const_expr, .flag_present },
30123032 .{ .name, .strp },
3013 .{ .type, .ref_addr },
3033 //.{ .type, .ref_addr },
30143034 .{ .const_value, .block },
30153035 },
30163036 },
......@@ -3018,7 +3038,7 @@ pub const AbbrevCode = enum {
30183038 .tag = .formal_parameter,
30193039 .attrs = &.{
30203040 .{ .const_expr, .flag_present },
3021 .{ .type, .ref_addr },
3041 //.{ .type, .ref_addr },
30223042 .{ .const_value, .block },
30233043 },
30243044 },
......@@ -3027,16 +3047,16 @@ pub const AbbrevCode = enum {
30273047 .attrs = &.{
30283048 .{ .const_expr, .flag_present },
30293049 .{ .name, .strp },
3030 .{ .type, .ref_addr },
3031 .{ .ZIG_comptime_value, .ref_addr },
3050 //.{ .type, .ref_addr },
3051 //.{ .ZIG_comptime_value, .ref_addr },
30323052 },
30333053 },
30343054 .unnamed_comptime_arg_comptime_state = .{
30353055 .tag = .formal_parameter,
30363056 .attrs = &.{
30373057 .{ .const_expr, .flag_present },
3038 .{ .type, .ref_addr },
3039 .{ .ZIG_comptime_value, .ref_addr },
3058 //.{ .type, .ref_addr },
3059 //.{ .ZIG_comptime_value, .ref_addr },
30403060 },
30413061 },
30423062 .comptime_arg_runtime_bits_comptime_state = .{
......@@ -3044,31 +3064,31 @@ pub const AbbrevCode = enum {
30443064 .attrs = &.{
30453065 .{ .const_expr, .flag_present },
30463066 .{ .name, .strp },
3047 .{ .type, .ref_addr },
3067 //.{ .type, .ref_addr },
30483068 .{ .const_value, .block },
3049 .{ .ZIG_comptime_value, .ref_addr },
3069 //.{ .ZIG_comptime_value, .ref_addr },
30503070 },
30513071 },
30523072 .unnamed_comptime_arg_runtime_bits_comptime_state = .{
30533073 .tag = .formal_parameter,
30543074 .attrs = &.{
30553075 .{ .const_expr, .flag_present },
3056 .{ .type, .ref_addr },
3076 //.{ .type, .ref_addr },
30573077 .{ .const_value, .block },
3058 .{ .ZIG_comptime_value, .ref_addr },
3078 //.{ .ZIG_comptime_value, .ref_addr },
30593079 },
30603080 },
30613081 .extern_param = .{
30623082 .tag = .formal_parameter,
30633083 .attrs = &.{
3064 .{ .type, .ref_addr },
3084 //.{ .type, .ref_addr },
30653085 },
30663086 },
30673087 .local_var = .{
30683088 .tag = .variable,
30693089 .attrs = &.{
30703090 .{ .name, .strp },
3071 .{ .type, .ref_addr },
3091 //.{ .type, .ref_addr },
30723092 .{ .location, .exprloc },
30733093 },
30743094 },
......@@ -3076,14 +3096,14 @@ pub const AbbrevCode = enum {
30763096 .tag = .constant,
30773097 .attrs = &.{
30783098 .{ .name, .strp },
3079 .{ .type, .ref_addr },
3099 //.{ .type, .ref_addr },
30803100 },
30813101 },
30823102 .local_const_runtime_bits = .{
30833103 .tag = .constant,
30843104 .attrs = &.{
30853105 .{ .name, .strp },
3086 .{ .type, .ref_addr },
3106 //.{ .type, .ref_addr },
30873107 .{ .const_value, .block },
30883108 },
30893109 },
......@@ -3091,17 +3111,17 @@ pub const AbbrevCode = enum {
30913111 .tag = .constant,
30923112 .attrs = &.{
30933113 .{ .name, .strp },
3094 .{ .type, .ref_addr },
3095 .{ .ZIG_comptime_value, .ref_addr },
3114 //.{ .type, .ref_addr },
3115 //.{ .ZIG_comptime_value, .ref_addr },
30963116 },
30973117 },
30983118 .local_const_runtime_bits_comptime_state = .{
30993119 .tag = .constant,
31003120 .attrs = &.{
31013121 .{ .name, .strp },
3102 .{ .type, .ref_addr },
3122 //.{ .type, .ref_addr },
31033123 .{ .const_value, .block },
3104 .{ .ZIG_comptime_value, .ref_addr },
3124 //.{ .ZIG_comptime_value, .ref_addr },
31053125 },
31063126 },
31073127 .undefined_comptime_value = .{
......@@ -3202,7 +3222,7 @@ const link = @import("../link.zig");
32023222const MappedFile = @import("MappedFile.zig");
32033223const Module = @import("../Module.zig");
32043224const std = @import("std");
3205const Type = @import("../Type.zig");
3206const Value = @import("../Value.zig");
3225const ZigType = @import("../Type.zig");
3226const ZigValue = @import("../Value.zig");
32073227const Writer = std.Io.Writer;
32083228const Zcu = @import("../Zcu.zig");
src/link/Elf2.zig+61-63
......@@ -22,7 +22,18 @@ const Alignment = MappedFile.Alignment;
2222base: link.File,
2323options: link.File.OpenOptions,
2424mf: MappedFile,
25ni: Node.Known,
25ni: struct {
26 elf: MappedFile.Node.Index,
27 ehdr: MappedFile.Node.Index,
28 shdr: MappedFile.Node.Index,
29 rodata: MappedFile.Node.Index,
30 phdr: MappedFile.Node.Index,
31 text: MappedFile.Node.Index,
32 data: MappedFile.Node.Index,
33 data_rel_ro: MappedFile.Node.Index,
34 tls: MappedFile.Node.Index.Optional,
35 gnu_eh_frame: MappedFile.Node.Index.Optional,
36},
2637archive: ?Archive,
2738nodes: std.MultiArrayList(Node),
2839/// Does not contain an item for `SHN_UNDEF`.
......@@ -346,7 +357,7 @@ const Node = union(enum) {
346357 pub const NavMapIndex = enum(u32) {
347358 _,
348359
349 pub fn navIndex(nmi: NavMapIndex, elf: *const Elf) InternPool.Nav.Index {
360 pub fn nav(nmi: NavMapIndex, elf: *const Elf) InternPool.Nav.Index {
350361 return elf.navs.keys()[@backingInt(nmi)];
351362 }
352363
......@@ -424,19 +435,6 @@ const Node = union(enum) {
424435 }
425436 };
426437
427 pub const Known = struct {
428 elf: MappedFile.Node.Index,
429 ehdr: MappedFile.Node.Index,
430 shdr: MappedFile.Node.Index,
431 rodata: MappedFile.Node.Index,
432 phdr: MappedFile.Node.Index,
433 text: MappedFile.Node.Index,
434 data: MappedFile.Node.Index,
435 data_rel_ro: MappedFile.Node.Index,
436 tls: MappedFile.Node.Index.Optional,
437 gnu_eh_frame: MappedFile.Node.Index.Optional,
438 };
439
440438 comptime {
441439 if (!std.debug.runtime_safety) std.debug.assert(@sizeOf(Node) == 8);
442440 }
......@@ -3464,7 +3462,11 @@ pub fn getUavVAddr(
34643462}
34653463pub fn getVAddr(elf: *Elf, reloc_info: link.File.RelocInfo, target: link.File.SymbolId) link.Error!u64 {
34663464 try elf.addReloc(
3467 reloc_info.parent.atom_index,
3465 switch (reloc_info.parent) {
3466 .none => unreachable,
3467 .atom_index => |atom_id| atom_id,
3468 .debug_output => |debug_output| Node.toAtom(debug_output.dwarf2.info_writer.ni),
3469 },
34683470 reloc_info.offset,
34693471 target,
34703472 reloc_info.addend,
......@@ -5221,9 +5223,10 @@ fn getNodeElfOffset(elf: *Elf, ni: MappedFile.Node.Index) u64 {
52215223/// the special-case sections '.plt', '.dynamic', and '.eh_frame_hdr'.
52225224fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {
52235225 const opts: struct {
5224 ignore_node: MappedFile.Node.Index.Optional = .none,
52255226 first_symbol_reloc: ?*SymbolReloc.Index = null,
5227 skip_symbol_relocs: MappedFile.Node.Index.Optional = .none,
52265228 first_node_reloc: ?*NodeReloc.Index = null,
5229 skip_node_relocs: MappedFile.Node.Index.Optional = .none,
52275230 first_got_reloc: ?*GotReloc.Index = null,
52285231 } = switch (elf.getNode(ni)) {
52295232 .archive,
......@@ -5280,21 +5283,25 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {
52805283 .first_node_reloc = &elf.dwarf_funcs.items[@backingInt(fi)].frame_fde_first_node_reloc,
52815284 },
52825285 .func_debug_info => |fi| .{
5283 .ignore_node = fi.get(&elf.dwarf).debug_line_ni,
52845286 .first_symbol_reloc = &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_symbol_reloc,
5287 .skip_symbol_relocs = if (elf.navs.getPtr(fi.nav(&elf.dwarf))) |nav|
5288 nav.lsi.index().ptr(elf).node
5289 else
5290 .none,
52855291 .first_node_reloc = &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_node_reloc,
5292 .skip_node_relocs = fi.get(&elf.dwarf).debug_line_ni,
52865293 },
52875294 .func_debug_line => |fi| .{
5288 .ignore_node = fi.get(&elf.dwarf).debug_info_ni,
52895295 .first_symbol_reloc = &elf.dwarf_funcs.items[@backingInt(fi)].debug_line_first_symbol_reloc,
52905296 .first_node_reloc = &elf.dwarf_funcs.items[@backingInt(fi)].debug_line_first_node_reloc,
5297 .skip_node_relocs = fi.get(&elf.dwarf).debug_info_ni,
52915298 },
52925299 };
52935300
52945301 if (opts.first_symbol_reloc) |ptr| {
52955302 if (ptr.* != .none) {
52965303 for (elf.symbol_relocs.items[@backingInt(ptr.*)..], @backingInt(ptr.*)..) |*reloc, index| {
5297 if (reloc.node.toOptional() == opts.ignore_node) continue;
5304 if (reloc.node.toOptional() == opts.skip_symbol_relocs) continue;
52985305 if (reloc.node != ni) break;
52995306 reloc.delete(elf, @fromBackingInt(@intCast(index)));
53005307 }
......@@ -5305,7 +5312,7 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {
53055312 if (opts.first_node_reloc) |ptr| {
53065313 if (ptr.* != .none) {
53075314 for (elf.node_relocs.items[@backingInt(ptr.*)..]) |*reloc| {
5308 if (reloc.node.toOptional() == opts.ignore_node) continue;
5315 if (reloc.node.toOptional() == opts.skip_node_relocs) continue;
53095316 if (reloc.node != ni) break;
53105317 reloc.delete(elf);
53115318 }
......@@ -5316,7 +5323,6 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void {
53165323 if (opts.first_got_reloc) |ptr| {
53175324 if (ptr.* != .none) {
53185325 for (elf.got_relocs.items[@backingInt(ptr.*)..]) |*reloc| {
5319 if (reloc.node == opts.ignore_node) continue;
53205326 if (reloc.node != ni.toOptional()) break;
53215327 reloc.delete(elf);
53225328 }
......@@ -5332,15 +5338,16 @@ fn flushMovedNodeRelocs(
53325338 node: MappedFile.Node.Index,
53335339 node_vaddr: u64,
53345340 opts: struct {
5335 ignore_node: MappedFile.Node.Index.Optional = .none,
53365341 first_symbol_reloc: SymbolReloc.Index = .none,
5342 skip_symbol_relocs: MappedFile.Node.Index.Optional = .none,
53375343 first_node_reloc: NodeReloc.Index = .none,
5344 skip_node_relocs: MappedFile.Node.Index.Optional = .none,
53385345 first_got_reloc: GotReloc.Index = .none,
53395346 },
53405347) void {
53415348 if (opts.first_symbol_reloc != .none) {
53425349 for (elf.symbol_relocs.items[@backingInt(opts.first_symbol_reloc)..]) |*reloc| {
5343 if (reloc.node.toOptional() == opts.ignore_node) continue;
5350 if (reloc.node.toOptional() == opts.skip_symbol_relocs) continue;
53445351 if (reloc.node != node) break;
53455352 if (reloc.rela_index.unwrap()) |rela_index| {
53465353 // The node has moved, so the offset of the relocation within the section might have
......@@ -5358,7 +5365,7 @@ fn flushMovedNodeRelocs(
53585365
53595366 if (opts.first_node_reloc != .none) {
53605367 for (elf.node_relocs.items[@backingInt(opts.first_node_reloc)..]) |*reloc| {
5361 if (reloc.node.toOptional() == opts.ignore_node) continue;
5368 if (reloc.node.toOptional() == opts.skip_node_relocs) continue;
53625369 if (reloc.node != node) break;
53635370 if (reloc.rela_index.unwrap()) |rela_index| {
53645371 assert(elf.ehdrType() == .REL);
......@@ -5374,7 +5381,6 @@ fn flushMovedNodeRelocs(
53745381
53755382 if (opts.first_got_reloc != .none) {
53765383 for (elf.got_relocs.items[@backingInt(opts.first_got_reloc)..]) |*reloc| {
5377 if (reloc.node == opts.ignore_node) continue;
53785384 if (reloc.node != node.toOptional()) break;
53795385 reloc.apply(elf);
53805386 }
......@@ -7193,6 +7199,7 @@ fn flushFiles(elf: *Elf) Error!void {
71937199 if (elf.shndx.debug_line != .UNDEF) for (elf.dwarf.units.keys(), elf.dwarf.units.values()) |mod, *unit| {
71947200 if (!unit.cleanDebugLineHeaderChanged()) continue;
71957201 const debug_line_header_ni = unit.debug_line_header_ni.unwrap().?;
7202 try debug_line_header_ni.parent(&elf.mf).unwrap().?.nextMoved(gpa, &elf.mf);
71967203 try debug_line_header_ni.moved(gpa, &elf.mf);
71977204 try debug_line_header_ni.nextMoved(gpa, &elf.mf);
71987205 var dlh_nw: MappedFile.Node.Writer = undefined;
......@@ -8553,21 +8560,12 @@ fn updateFuncInner(
85538560
85548561 try elf.nodes.ensureUnusedCapacity(gpa, 5);
85558562 const dwarf_fi = try dwarf.getFunc(func.owner_nav);
8556 try elf.dwarf_funcs.appendNTimes(gpa, .{
8557 .frame_fde_first_symbol_reloc = .none,
8558 .frame_fde_first_node_reloc = .none,
8559 .debug_info_first_target_reloc = .none,
8560 .debug_info_first_symbol_reloc = .none,
8561 .debug_info_first_node_reloc = .none,
8562 .debug_line_first_symbol_reloc = .none,
8563 .debug_line_first_node_reloc = .none,
8564 }, @backingInt(dwarf_fi) + 1 -| elf.dwarf_funcs.items.len);
85658563
85668564 const wip_nav = &debug_output_buf.wip_nav;
85678565 wip_nav.* = .{
85688566 .dwarf = dwarf,
85698567 .unit = dwarf.getUnit(mod),
8570 .func = dwarf_fi,
8568 .func = func_index,
85718569 .func_si = Symbol.Id.local(lsi).toTypeErased(),
85728570 .cfi = .{
85738571 .loc = 0,
......@@ -8640,33 +8638,20 @@ fn updateFuncInner(
86408638 debug.pt = pt;
86418639 debug.any_children = false;
86428640 debug.blocks = .empty;
8643 const debug_info_ni = if (dwarf_func.debug_info_ni.unwrap()) |debug_info_ni| debug_info_ni: {
8644 try debug_info_ni.moved(gpa, &elf.mf);
8645 try debug_info_ni.nextMoved(gpa, &elf.mf);
8646 break :debug_info_ni debug_info_ni;
8647 } else debug_info_ni: {
8648 const debug_info_ni =
8649 try unit.debug_info_ni.unwrap().?.addFloatingChild(&elf.mf, gpa, .{
8650 .moved = true,
8651 .next_moved = true,
8652 .enable_next_moved = true,
8653 });
8654 dwarf_func.debug_info_ni = .wrap(debug_info_ni);
8655 elf.nodes.appendAssumeCapacity(.{ .func_debug_info = dwarf_fi });
8656 break :debug_info_ni debug_info_ni;
8657 };
8641
8642 const debug_info_ni = dwarf_func.debug_info_ni.unwrap().?;
8643 try debug_info_ni.moved(gpa, &elf.mf);
8644 try debug_info_ni.nextMoved(gpa, &elf.mf);
86588645 debug_info_ni.writer(&elf.mf, gpa, &debug.info_writer);
8659 const debug_line_ni = if (dwarf_func.debug_line_ni.unwrap()) |debug_line_ni| debug_line_ni: {
8660 try debug_line_ni.moved(gpa, &elf.mf);
8661 try debug_line_ni.nextMoved(gpa, &elf.mf);
8662 break :debug_line_ni debug_line_ni;
8663 } else debug_line_ni: {
8646
8647 const debug_line_ni = dwarf_func.debug_line_ni.unwrap() orelse debug_line_ni: {
86648648 const debug_line_ni =
86658649 try unit.debug_line_ni.unwrap().?.addFloatingChild(&elf.mf, gpa, .{
86668650 .moved = true,
86678651 .next_moved = true,
86688652 .enable_next_moved = true,
86698653 });
8654 dwarf_func.debug_line_ni = .wrap(debug_line_ni);
86708655 elf.nodes.appendAssumeCapacity(.{ .func_debug_line = dwarf_fi });
86718656 break :debug_line_ni debug_line_ni;
86728657 };
......@@ -8688,9 +8673,10 @@ fn updateFuncInner(
86888673 .dwarf2 => |debug| {
86898674 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);
86908675 try debug.wip_nav.genDebugFrameHeader();
8691 elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?);
86928676 elf.resetNodeRelocs(dwarf_func.debug_line_ni.unwrap().?);
8693 try debug.startFunc();
8677 try debug.startDebugLine();
8678 elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?);
8679 try debug.startDebugInfo();
86948680 },
86958681 .none => {},
86968682 }
......@@ -9055,7 +9041,7 @@ fn idleProgNode(
90559041 },
90569042 .nav => |nmi| {
90579043 const ip = &elf.base.comp.zcu.?.intern_pool;
9058 break :name ip.getNav(nmi.navIndex(elf)).fqn.toSlice(ip);
9044 break :name ip.getNav(nmi.nav(elf)).fqn.toSlice(ip);
90599045 },
90609046 .uav => |umi| std.mem.print(&name, "{f}", .{
90619047 Value.fromInterned(umi.uavValue(elf)).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }),
......@@ -9461,7 +9447,7 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
94619447
94629448 Symbol.Id.global(global_name).flushMoved(elf, new_addr);
94639449 },
9464 inline .nav, .uav, .lazy_code, .lazy_const_data => |mi| {
9450 inline .nav, .uav, .lazy_code, .lazy_const_data => |mi, tag| {
94659451 const new_addr = elf.computeNodeVAddr(ni);
94669452 Symbol.Id.local(mi.symbol(elf)).flushMoved(elf, new_addr);
94679453 if (elf.node_global_symbols.get(ni)) |first_name| {
......@@ -9474,6 +9460,14 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
94749460 }
94759461 elf.flushMovedNodeRelocs(ni, new_addr, .{
94769462 .first_symbol_reloc = mi.firstSymbolReloc(elf),
9463 .skip_symbol_relocs = switch (tag) {
9464 else => comptime unreachable,
9465 .nav => if (elf.dwarf.getFuncIfExists(mi.nav(elf))) |dwarf_fi|
9466 dwarf_fi.get(&elf.dwarf).debug_info_ni
9467 else
9468 .none,
9469 .uav, .lazy_code, .lazy_const_data => .none,
9470 },
94779471 .first_got_reloc = mi.firstGotReloc(elf),
94789472 });
94799473 },
......@@ -9599,17 +9593,21 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void
95999593 target_ri = target_reloc.next;
96009594 }
96019595 elf.flushMovedNodeRelocs(ni, elf.computeNodeVAddr(ni), .{
9602 .ignore_node = fi.get(&elf.dwarf).debug_line_ni,
96039596 .first_symbol_reloc = dwarf_func.debug_info_first_symbol_reloc,
9597 .skip_symbol_relocs = if (elf.navs.getPtr(fi.nav(&elf.dwarf))) |nav|
9598 nav.lsi.index().ptr(elf).node
9599 else
9600 .none,
96049601 .first_node_reloc = dwarf_func.debug_info_first_node_reloc,
9602 .skip_node_relocs = fi.get(&elf.dwarf).debug_line_ni,
96059603 });
96069604 },
96079605 .func_debug_line => |fi| {
96089606 const dwarf_func = &elf.dwarf_funcs.items[@backingInt(fi)];
96099607 elf.flushMovedNodeRelocs(ni, elf.computeNodeVAddr(ni), .{
9610 .ignore_node = fi.get(&elf.dwarf).debug_info_ni,
96119608 .first_symbol_reloc = dwarf_func.debug_line_first_symbol_reloc,
96129609 .first_node_reloc = dwarf_func.debug_line_first_node_reloc,
9610 .skip_node_relocs = fi.get(&elf.dwarf).debug_info_ni,
96139611 });
96149612 },
96159613 }
......@@ -10548,7 +10546,7 @@ pub fn printNode(
1054810546 .nav => |nmi| {
1054910547 const zcu = elf.base.comp.zcu.?;
1055010548 const ip = &zcu.intern_pool;
10551 const nav = ip.getNav(nmi.navIndex(elf));
10549 const nav = ip.getNav(nmi.nav(elf));
1055210550 try w.print("({f}, {f})", .{
1055310551 Type.fromInterned(nav.resolved.?.type).fmt(.{ .zcu = zcu, .tid = tid }),
1055410552 nav.fqn.fmt(ip),