authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-06 11:52:49-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-07 16:11:00-04:00
log804b044235954830e66a27b2365e1b26db51478a
tree32d0f61bd6a97ba94738971f3d8ed3aad4a2be39
parentf6d272651274897c10a75f12a2f146ad27f08628

Dwarf2: implement runtime globals


5 files changed, 454 insertions(+), 266 deletions(-)

src/codegen/x86_64/Mir.zig+1-1
...@@ -2009,7 +2009,7 @@ pub fn emit(...@@ -2009,7 +2009,7 @@ pub fn emit(
2009 .column = func.lbrace_column,2009 .column = func.lbrace_column,
2010 .is_stmt = switch (debug_output) {2010 .is_stmt = switch (debug_output) {
2011 .dwarf => |dwarf| dwarf.dwarf.debug_line.header.default_is_stmt,2011 .dwarf => |dwarf| dwarf.dwarf.debug_line.header.default_is_stmt,
2012 .dwarf2 => |dwarf| dwarf.wip_nav.dwarf.debug_line.header.default_is_stmt,2012 .dwarf2 => |dwarf| dwarf.wip_func.dwarf.debug_line.header.default_is_stmt,
2013 .eh_frame, .none => undefined,2013 .eh_frame, .none => undefined,
2014 },2014 },
2015 },2015 },
src/link.zig+2-2
...@@ -755,8 +755,8 @@ pub const File = struct {...@@ -755,8 +755,8 @@ pub const File = struct {
755755
756 pub const DebugInfoOutput = union(enum) {756 pub const DebugInfoOutput = union(enum) {
757 dwarf: *Dwarf.WipNav,757 dwarf: *Dwarf.WipNav,
758 eh_frame: *Dwarf2.WipNav,758 eh_frame: *Dwarf2.WipFunc,
759 dwarf2: *Dwarf2.WipNav.Debug,759 dwarf2: *Dwarf2.WipFunc.Debug,
760 none,760 none,
761 };761 };
762 pub const UpdateDebugInfoError = Dwarf.UpdateError;762 pub const UpdateDebugInfoError = Dwarf.UpdateError;
src/link/Dwarf2.zig+358-207
...@@ -497,33 +497,33 @@ pub const Cfa = union(enum) {...@@ -497,33 +497,33 @@ pub const Cfa = union(enum) {
497 const RegOff = struct { reg: u32, off: i64 };497 const RegOff = struct { reg: u32, off: i64 };
498 const RegExpr = struct { reg: u32, expr: Loc };498 const RegExpr = struct { reg: u32, expr: Loc };
499499
500 fn write(cfa: Cfa, wip_nav: *WipNav) link.EmitError!void {500 fn write(cfa: Cfa, wip_func: *WipFunc) link.EmitError!void {
501 const df_nw = &wip_nav.fde_writer;501 const df_nw = &wip_func.fde_writer;
502 const df_w = &df_nw.interface;502 const df_w = &df_nw.interface;
503 switch (cfa) {503 switch (cfa) {
504 .nop => try df_w.writeByte(DW.CFA.nop),504 .nop => try df_w.writeByte(DW.CFA.nop),
505 .advance_loc => |loc| {505 .advance_loc => |loc| {
506 const delta =506 const delta =
507 @divExact(loc - wip_nav.cfi.loc, wip_nav.dwarf.frame.header.code_alignment_factor);507 @divExact(loc - wip_func.cfi.loc, wip_func.dwarf.frame.header.code_alignment_factor);
508 if (delta == 0) {} else if (std.math.cast(u6, delta)) |small_delta|508 if (delta == 0) {} else if (std.math.cast(u6, delta)) |small_delta|
509 try df_w.writeByte(@as(u8, DW.CFA.advance_loc) + small_delta)509 try df_w.writeByte(@as(u8, DW.CFA.advance_loc) + small_delta)
510 else if (std.math.cast(u8, delta)) |ubyte_delta|510 else if (std.math.cast(u8, delta)) |ubyte_delta|
511 try df_w.writeAll(&.{ DW.CFA.advance_loc1, ubyte_delta })511 try df_w.writeAll(&.{ DW.CFA.advance_loc1, ubyte_delta })
512 else if (std.math.cast(u16, delta)) |uhalf_delta| {512 else if (std.math.cast(u16, delta)) |uhalf_delta| {
513 try df_w.writeByte(DW.CFA.advance_loc2);513 try df_w.writeByte(DW.CFA.advance_loc2);
514 try df_w.writeInt(u16, uhalf_delta, wip_nav.dwarf.endian);514 try df_w.writeInt(u16, uhalf_delta, wip_func.dwarf.endian);
515 } else if (std.math.cast(u32, delta)) |uword_delta| {515 } else if (std.math.cast(u32, delta)) |uword_delta| {
516 try df_w.writeByte(DW.CFA.advance_loc4);516 try df_w.writeByte(DW.CFA.advance_loc4);
517 try df_w.writeInt(u32, uword_delta, wip_nav.dwarf.endian);517 try df_w.writeInt(u32, uword_delta, wip_func.dwarf.endian);
518 }518 }
519 wip_nav.cfi.loc = loc;519 wip_func.cfi.loc = loc;
520 },520 },
521 .offset, .rel_offset => |reg_off| {521 .offset, .rel_offset => |reg_off| {
522 const factored_off = @divExact(reg_off.off - switch (cfa) {522 const factored_off = @divExact(reg_off.off - switch (cfa) {
523 else => unreachable,523 else => unreachable,
524 .offset => 0,524 .offset => 0,
525 .rel_offset => wip_nav.cfi.cfa.off,525 .rel_offset => wip_func.cfi.cfa.off,
526 }, wip_nav.dwarf.frame.header.data_alignment_factor);526 }, wip_func.dwarf.frame.header.data_alignment_factor);
527 if (std.math.cast(u63, factored_off)) |unsigned_off| {527 if (std.math.cast(u63, factored_off)) |unsigned_off| {
528 if (std.math.cast(u6, reg_off.reg)) |small_reg| {528 if (std.math.cast(u6, reg_off.reg)) |small_reg| {
529 try df_w.writeByte(@as(u8, DW.CFA.offset) + small_reg);529 try df_w.writeByte(@as(u8, DW.CFA.offset) + small_reg);
...@@ -565,21 +565,21 @@ pub const Cfa = union(enum) {...@@ -565,21 +565,21 @@ pub const Cfa = union(enum) {
565 const reg_off: RegOff = switch (cfa) {565 const reg_off: RegOff = switch (cfa) {
566 else => unreachable,566 else => unreachable,
567 .def_cfa => |reg_off| reg_off,567 .def_cfa => |reg_off| reg_off,
568 .def_cfa_register => |reg| .{ .reg = reg, .off = wip_nav.cfi.cfa.off },568 .def_cfa_register => |reg| .{ .reg = reg, .off = wip_func.cfi.cfa.off },
569 .def_cfa_offset => |off| .{ .reg = wip_nav.cfi.cfa.reg, .off = off },569 .def_cfa_offset => |off| .{ .reg = wip_func.cfi.cfa.reg, .off = off },
570 .adjust_cfa_offset => |off| .{570 .adjust_cfa_offset => |off| .{
571 .reg = wip_nav.cfi.cfa.reg,571 .reg = wip_func.cfi.cfa.reg,
572 .off = wip_nav.cfi.cfa.off + off,572 .off = wip_func.cfi.cfa.off + off,
573 },573 },
574 };574 };
575 const changed_reg = reg_off.reg != wip_nav.cfi.cfa.reg;575 const changed_reg = reg_off.reg != wip_func.cfi.cfa.reg;
576 const unsigned_off = std.math.cast(u63, reg_off.off);576 const unsigned_off = std.math.cast(u63, reg_off.off);
577 if (reg_off.off == wip_nav.cfi.cfa.off) {577 if (reg_off.off == wip_func.cfi.cfa.off) {
578 if (changed_reg) {578 if (changed_reg) {
579 try df_w.writeByte(DW.CFA.def_cfa_register);579 try df_w.writeByte(DW.CFA.def_cfa_register);
580 try df_w.writeUleb128(reg_off.reg);580 try df_w.writeUleb128(reg_off.reg);
581 }581 }
582 } else if (switch (wip_nav.dwarf.frame.header.data_alignment_factor) {582 } else if (switch (wip_func.dwarf.frame.header.data_alignment_factor) {
583 0 => unreachable,583 0 => unreachable,
584 1 => unsigned_off != null,584 1 => unsigned_off != null,
585 else => |data_alignment_factor| @rem(reg_off.off, data_alignment_factor) != 0,585 else => |data_alignment_factor| @rem(reg_off.off, data_alignment_factor) != 0,
...@@ -591,23 +591,23 @@ pub const Cfa = union(enum) {...@@ -591,23 +591,23 @@ pub const Cfa = union(enum) {
591 try df_w.writeByte(if (changed_reg) DW.CFA.def_cfa_sf else DW.CFA.def_cfa_offset_sf);591 try df_w.writeByte(if (changed_reg) DW.CFA.def_cfa_sf else DW.CFA.def_cfa_offset_sf);
592 if (changed_reg) try df_w.writeUleb128(reg_off.reg);592 if (changed_reg) try df_w.writeUleb128(reg_off.reg);
593 try df_w.writeSleb128(593 try df_w.writeSleb128(
594 @divExact(reg_off.off, wip_nav.dwarf.frame.header.data_alignment_factor),594 @divExact(reg_off.off, wip_func.dwarf.frame.header.data_alignment_factor),
595 );595 );
596 }596 }
597 wip_nav.cfi.cfa = reg_off;597 wip_func.cfi.cfa = reg_off;
598 },598 },
599 .def_cfa_expression => |expr| {599 .def_cfa_expression => |expr| {
600 try df_w.writeByte(DW.CFA.def_cfa_expression);600 try df_w.writeByte(DW.CFA.def_cfa_expression);
601 try wip_nav.dwarf.exprLoc(df_nw, expr);601 try wip_func.dwarf.exprLoc(df_nw, expr);
602 },602 },
603 .expression => |reg_expr| {603 .expression => |reg_expr| {
604 try df_w.writeByte(DW.CFA.expression);604 try df_w.writeByte(DW.CFA.expression);
605 try df_w.writeUleb128(reg_expr.reg);605 try df_w.writeUleb128(reg_expr.reg);
606 try wip_nav.dwarf.exprLoc(df_nw, reg_expr.expr);606 try wip_func.dwarf.exprLoc(df_nw, reg_expr.expr);
607 },607 },
608 .val_offset => |reg_off| {608 .val_offset => |reg_off| {
609 const factored_off =609 const factored_off =
610 @divExact(reg_off.off, wip_nav.dwarf.frame.header.data_alignment_factor);610 @divExact(reg_off.off, wip_func.dwarf.frame.header.data_alignment_factor);
611 if (std.math.cast(u63, factored_off)) |unsigned_off| {611 if (std.math.cast(u63, factored_off)) |unsigned_off| {
612 try df_w.writeByte(DW.CFA.val_offset);612 try df_w.writeByte(DW.CFA.val_offset);
613 try df_w.writeUleb128(reg_off.reg);613 try df_w.writeUleb128(reg_off.reg);
...@@ -621,14 +621,14 @@ pub const Cfa = union(enum) {...@@ -621,14 +621,14 @@ pub const Cfa = union(enum) {
621 .val_expression => |reg_expr| {621 .val_expression => |reg_expr| {
622 try df_w.writeByte(DW.CFA.val_expression);622 try df_w.writeByte(DW.CFA.val_expression);
623 try df_w.writeUleb128(reg_expr.reg);623 try df_w.writeUleb128(reg_expr.reg);
624 try wip_nav.dwarf.exprLoc(df_nw, reg_expr.expr);624 try wip_func.dwarf.exprLoc(df_nw, reg_expr.expr);
625 },625 },
626 .escape => |bytes| try df_w.writeAll(bytes),626 .escape => |bytes| try df_w.writeAll(bytes),
627 }627 }
628 }628 }
629};629};
630630
631pub const WipNav = struct {631pub const WipFunc = struct {
632 dwarf: *Dwarf,632 dwarf: *Dwarf,
633 unit: Unit.Index,633 unit: Unit.Index,
634 func: InternPool.Index,634 func: InternPool.Index,
...@@ -642,7 +642,7 @@ pub const WipNav = struct {...@@ -642,7 +642,7 @@ pub const WipNav = struct {
642 frame_func_length: struct { offset: usize, size: AddressSize },642 frame_func_length: struct { offset: usize, size: AddressSize },
643643
644 pub const Debug = struct {644 pub const Debug = struct {
645 wip_nav: WipNav,645 wip_func: WipFunc,
646 pt: Zcu.PerThread,646 pt: Zcu.PerThread,
647 empty: bool,647 empty: bool,
648 blocks: std.ArrayList(struct {648 blocks: std.ArrayList(struct {
...@@ -659,27 +659,26 @@ pub const WipNav = struct {...@@ -659,27 +659,26 @@ pub const WipNav = struct {
659 debug.line_writer.deinit();659 debug.line_writer.deinit();
660 debug.info_writer.deinit();660 debug.info_writer.deinit();
661 debug.blocks.deinit(gpa);661 debug.blocks.deinit(gpa);
662 debug.wip_nav.deinit();662 debug.wip_func.deinit();
663 debug.* = undefined;663 debug.* = undefined;
664 }664 }
665665
666 pub fn genDebugFrame(debug: *Debug, loc: u32, cfa: Cfa) link.Error!void {666 pub fn genDebugFrame(debug: *Debug, loc: u32, cfa: Cfa) link.Error!void {
667 return debug.wip_nav.genDebugFrame(loc, cfa);667 return debug.wip_func.genDebugFrame(loc, cfa);
668 }668 }
669669
670 pub fn startFuncDebugInfo(debug: *Debug) link.Error!void {670 pub fn startDebugInfo(debug: *Debug) link.Error!void {
671 assert(debug.wip_nav.func != .none);671 debug.startDebugInfoInner() catch |err| switch (err) {
672 debug.startFuncDebugInfoInner() catch |err| switch (err) {
673 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
674 else => |e| return e,672 else => |e| return e,
673 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
675 };674 };
676 }675 }
677 fn startFuncDebugInfoInner(debug: *Debug) link.EmitError!void {676 fn startDebugInfoInner(debug: *Debug) link.EmitError!void {
678 const dwarf = debug.wip_nav.dwarf;677 const dwarf = debug.wip_func.dwarf;
679 const pt = debug.pt;678 const pt = debug.pt;
680 const zcu = pt.zcu;679 const zcu = pt.zcu;
681 const ip = &zcu.intern_pool;680 const ip = &zcu.intern_pool;
682 const func = zcu.funcInfo(debug.wip_nav.func);681 const func = zcu.funcInfo(debug.wip_func.func);
683 const nav = ip.getNav(func.owner_nav);682 const nav = ip.getNav(func.owner_nav);
684 const func_type = ip.indexToKey(func.ty).func_type;683 const func_type = ip.indexToKey(func.ty).func_type;
685 const inst_info = nav.srcInst(ip).resolveFull(ip).?;684 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
...@@ -702,7 +701,7 @@ pub const WipNav = struct {...@@ -702,7 +701,7 @@ pub const WipNav = struct {
702 .@"extern", .@"export" => nav.name,701 .@"extern", .@"export" => nav.name,
703 }.toSlice(ip));702 }.toSlice(ip));
704 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));703 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
705 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, 0);704 try dwarf.addrSym(di_nw, debug.wip_func.func_si, 0);
706 debug.info_func_length_offset = di_w.end;705 debug.info_func_length_offset = di_w.end;
707 try di_w.writeInt(u32, undefined, dwarf.endian);706 try di_w.writeInt(u32, undefined, dwarf.endian);
708 try di_w.writeUleb128(707 try di_w.writeUleb128(
...@@ -713,17 +712,16 @@ pub const WipNav = struct {...@@ -713,17 +712,16 @@ pub const WipNav = struct {
713 }712 }
714713
715 pub fn startDebugLine(debug: *Debug) link.Error!void {714 pub fn startDebugLine(debug: *Debug) link.Error!void {
716 assert(debug.wip_nav.func != .none);
717 debug.startDebugLineInner() catch |err| switch (err) {715 debug.startDebugLineInner() catch |err| switch (err) {
718 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
719 else => |e| return e,716 else => |e| return e,
717 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
720 };718 };
721 }719 }
722 fn startDebugLineInner(debug: *Debug) link.EmitError!void {720 fn startDebugLineInner(debug: *Debug) link.EmitError!void {
723 const dwarf = debug.wip_nav.dwarf;721 const dwarf = debug.wip_func.dwarf;
724 const zcu = debug.pt.zcu;722 const zcu = debug.pt.zcu;
725 const ip = &zcu.intern_pool;723 const ip = &zcu.intern_pool;
726 const func = zcu.funcInfo(debug.wip_nav.func);724 const func = zcu.funcInfo(debug.wip_func.func);
727 const inst_info = ip.getNav(func.owner_nav).srcInst(ip).resolveFull(ip).?;725 const inst_info = ip.getNav(func.owner_nav).srcInst(ip).resolveFull(ip).?;
728 const zf = zcu.fileByIndex(inst_info.file);726 const zf = zcu.fileByIndex(inst_info.file);
729 const decl = zf.zir.?.getDeclaration(inst_info.inst);727 const decl = zf.zir.?.getDeclaration(inst_info.inst);
...@@ -742,7 +740,7 @@ pub const WipNav = struct {...@@ -742,7 +740,7 @@ pub const WipNav = struct {
742 } else {740 } else {
743 try dl_w.writeUleb128(1 + @backingInt(dwarf.address_size));741 try dl_w.writeUleb128(1 + @backingInt(dwarf.address_size));
744 try dl_w.writeByte(DW.LNE.set_address);742 try dl_w.writeByte(DW.LNE.set_address);
745 try dwarf.addrSym(dl_nw, debug.wip_nav.func_si, 0);743 try dwarf.addrSym(dl_nw, debug.wip_func.func_si, 0);
746744
747 const ui = dwarf.getUnit(zf.mod.?);745 const ui = dwarf.getUnit(zf.mod.?);
748 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, inst_info.file);746 _, const fi = try ui.get(dwarf).getFile(zcu.gpa, ui, inst_info.file);
...@@ -756,20 +754,19 @@ pub const WipNav = struct {...@@ -756,20 +754,19 @@ pub const WipNav = struct {
756 }754 }
757 }755 }
758756
759 pub fn finishFunc(debug: *Debug, func_length: u64) link.Error!void {757 pub fn finish(debug: *Debug, func_length: u64) link.Error!void {
760 assert(debug.wip_nav.func != .none);
761 const di_nw = &debug.info_writer;758 const di_nw = &debug.info_writer;
762 debug.finishDebugInfo(func_length) catch |err| switch (err) {759 debug.finishDebugInfo(func_length) catch |err| switch (err) {
763 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(di_nw),
764 else => |e| return e,760 else => |e| return e,
761 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(di_nw),
765 };762 };
766 debug.finishDebugLine() catch |err| switch (err) {763 debug.finishDebugLine() catch |err| switch (err) {
767 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(di_nw),
768 else => |e| return e,764 else => |e| return e,
765 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(di_nw),
769 };766 };
770 }767 }
771 fn finishDebugInfo(debug: *Debug, func_length: u64) link.EmitError!void {768 fn finishDebugInfo(debug: *Debug, func_length: u64) link.EmitError!void {
772 const dwarf = debug.wip_nav.dwarf;769 const dwarf = debug.wip_func.dwarf;
773 const di_nw = &debug.info_writer;770 const di_nw = &debug.info_writer;
774 const di_w = &di_nw.interface;771 const di_w = &di_nw.interface;
775 std.mem.writeInt(772 std.mem.writeInt(
...@@ -799,8 +796,8 @@ pub const WipNav = struct {...@@ -799,8 +796,8 @@ pub const WipNav = struct {
799 loc: Loc,796 loc: Loc,
800 ) link.Error!void {797 ) link.Error!void {
801 return debug.genLocalVarDebugInfoInner(tag, opt_name, ty, loc) catch |err| switch (err) {798 return debug.genLocalVarDebugInfoInner(tag, opt_name, ty, loc) catch |err| switch (err) {
802 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
803 else => |e| e,799 else => |e| e,
800 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
804 };801 };
805 }802 }
806 fn genLocalVarDebugInfoInner(803 fn genLocalVarDebugInfoInner(
...@@ -810,8 +807,7 @@ pub const WipNav = struct {...@@ -810,8 +807,7 @@ pub const WipNav = struct {
810 ty: Type,807 ty: Type,
811 loc: Loc,808 loc: Loc,
812 ) link.EmitError!void {809 ) link.EmitError!void {
813 assert(debug.wip_nav.func != .none);810 const dwarf = debug.wip_func.dwarf;
814 const dwarf = debug.wip_nav.dwarf;
815 const di_nw = &debug.info_writer;811 const di_nw = &debug.info_writer;
816 try dwarf.abbrevCode(di_nw, switch (tag) {812 try dwarf.abbrevCode(di_nw, switch (tag) {
817 .arg => if (opt_name) |_| .arg else .unnamed_arg,813 .arg => if (opt_name) |_| .arg else .unnamed_arg,
...@@ -831,8 +827,8 @@ pub const WipNav = struct {...@@ -831,8 +827,8 @@ pub const WipNav = struct {
831 val: Value,827 val: Value,
832 ) link.Error!void {828 ) link.Error!void {
833 return debug.genLocalConstDebugInfoInner(tag, opt_name, val) catch |err| switch (err) {829 return debug.genLocalConstDebugInfoInner(tag, opt_name, val) catch |err| switch (err) {
834 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
835 else => |e| e,830 else => |e| e,
831 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
836 };832 };
837 }833 }
838 fn genLocalConstDebugInfoInner(834 fn genLocalConstDebugInfoInner(
...@@ -841,8 +837,7 @@ pub const WipNav = struct {...@@ -841,8 +837,7 @@ pub const WipNav = struct {
841 opt_name: ?[]const u8,837 opt_name: ?[]const u8,
842 val: Value,838 val: Value,
843 ) link.EmitError!void {839 ) link.EmitError!void {
844 assert(debug.wip_nav.func != .none);840 const dwarf = debug.wip_func.dwarf;
845 const dwarf = debug.wip_nav.dwarf;
846 const pt = debug.pt;841 const pt = debug.pt;
847 const zcu = debug.pt.zcu;842 const zcu = debug.pt.zcu;
848 const ty = val.typeOf(zcu);843 const ty = val.typeOf(zcu);
...@@ -879,13 +874,12 @@ pub const WipNav = struct {...@@ -879,13 +874,12 @@ pub const WipNav = struct {
879874
880 pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void {875 pub fn genVarArgsDebugInfo(debug: *Debug) link.Error!void {
881 return debug.genVarArgsDebugInfoInner() catch |err| switch (err) {876 return debug.genVarArgsDebugInfoInner() catch |err| switch (err) {
882 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
883 else => |e| e,877 else => |e| e,
878 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
884 };879 };
885 }880 }
886 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {881 fn genVarArgsDebugInfoInner(debug: *Debug) link.EmitError!void {
887 assert(debug.wip_nav.func != .none);882 try debug.wip_func.dwarf.abbrevCode(&debug.info_writer, .is_var_args);
888 try debug.wip_nav.dwarf.abbrevCode(&debug.info_writer, .is_var_args);
889 debug.empty = false;883 debug.empty = false;
890 }884 }
891885
...@@ -896,7 +890,7 @@ pub const WipNav = struct {...@@ -896,7 +890,7 @@ pub const WipNav = struct {
896 end: bool,890 end: bool,
897 ) link.Error!void {891 ) link.Error!void {
898 return debug.advanceLineAndPcInner(delta_line, delta_pc, end) catch |err| switch (err) {892 return debug.advanceLineAndPcInner(delta_line, delta_pc, end) catch |err| switch (err) {
899 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),893 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
900 };894 };
901 }895 }
902 fn advanceLineAndPcInner(896 fn advanceLineAndPcInner(
...@@ -907,7 +901,7 @@ pub const WipNav = struct {...@@ -907,7 +901,7 @@ pub const WipNav = struct {
907 ) std.Io.Writer.Error!void {901 ) std.Io.Writer.Error!void {
908 const dl_w = &debug.line_writer.interface;902 const dl_w = &debug.line_writer.interface;
909903
910 const header = debug.wip_nav.dwarf.debug_line.header;904 const header = debug.wip_func.dwarf.debug_line.header;
911 assert(header.maximum_operations_per_instruction == 1);905 assert(header.maximum_operations_per_instruction == 1);
912 const delta_op: u64 = 0;906 const delta_op: u64 = 0;
913907
...@@ -951,7 +945,7 @@ pub const WipNav = struct {...@@ -951,7 +945,7 @@ pub const WipNav = struct {
951945
952 pub fn setColumn(debug: *Debug, column: u32) link.Error!void {946 pub fn setColumn(debug: *Debug, column: u32) link.Error!void {
953 return debug.setColumnInner(column) catch |err| switch (err) {947 return debug.setColumnInner(column) catch |err| switch (err) {
954 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),948 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
955 };949 };
956 }950 }
957 fn setColumnInner(debug: *Debug, column: u32) std.Io.Writer.Error!void {951 fn setColumnInner(debug: *Debug, column: u32) std.Io.Writer.Error!void {
...@@ -962,7 +956,7 @@ pub const WipNav = struct {...@@ -962,7 +956,7 @@ pub const WipNav = struct {
962956
963 pub fn negateStmt(debug: *Debug) link.Error!void {957 pub fn negateStmt(debug: *Debug) link.Error!void {
964 return debug.negateStmtInner() catch |err| switch (err) {958 return debug.negateStmtInner() catch |err| switch (err) {
965 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),959 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
966 };960 };
967 }961 }
968 fn negateStmtInner(debug: *Debug) std.Io.Writer.Error!void {962 fn negateStmtInner(debug: *Debug) std.Io.Writer.Error!void {
...@@ -971,7 +965,7 @@ pub const WipNav = struct {...@@ -971,7 +965,7 @@ pub const WipNav = struct {
971965
972 pub fn setPrologueEnd(debug: *Debug) link.Error!void {966 pub fn setPrologueEnd(debug: *Debug) link.Error!void {
973 return debug.setPrologueEndInner() catch |err| switch (err) {967 return debug.setPrologueEndInner() catch |err| switch (err) {
974 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),968 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
975 };969 };
976 }970 }
977 fn setPrologueEndInner(debug: *Debug) std.Io.Writer.Error!void {971 fn setPrologueEndInner(debug: *Debug) std.Io.Writer.Error!void {
...@@ -980,7 +974,7 @@ pub const WipNav = struct {...@@ -980,7 +974,7 @@ pub const WipNav = struct {
980974
981 pub fn setEpilogueBegin(debug: *Debug) link.Error!void {975 pub fn setEpilogueBegin(debug: *Debug) link.Error!void {
982 return debug.setEpilogueBeginInner() catch |err| switch (err) {976 return debug.setEpilogueBeginInner() catch |err| switch (err) {
983 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),977 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
984 };978 };
985 }979 }
986 fn setEpilogueBeginInner(debug: *Debug) std.Io.Writer.Error!void {980 fn setEpilogueBeginInner(debug: *Debug) std.Io.Writer.Error!void {
...@@ -989,12 +983,12 @@ pub const WipNav = struct {...@@ -989,12 +983,12 @@ pub const WipNav = struct {
989983
990 pub fn enterBlock(debug: *Debug, code_off: usize) link.Error!void {984 pub fn enterBlock(debug: *Debug, code_off: usize) link.Error!void {
991 return debug.enterBlockInner(code_off) catch |err| switch (err) {985 return debug.enterBlockInner(code_off) catch |err| switch (err) {
992 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
993 else => |e| e,986 else => |e| e,
987 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
994 };988 };
995 }989 }
996 fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {990 fn enterBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
997 const dwarf = debug.wip_nav.dwarf;991 const dwarf = debug.wip_func.dwarf;
998 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);992 const block = try debug.blocks.addOne(dwarf.lf.comp.gpa);
999993
1000 const di_nw = &debug.info_writer;994 const di_nw = &debug.info_writer;
...@@ -1002,7 +996,7 @@ pub const WipNav = struct {...@@ -1002,7 +996,7 @@ pub const WipNav = struct {
1002 block.abbrev_code = @intCast(di_w.end);996 block.abbrev_code = @intCast(di_w.end);
1003 try dwarf.abbrevCode(di_nw, .block);997 try dwarf.abbrevCode(di_nw, .block);
1004 block.low_pc_off = code_off;998 block.low_pc_off = code_off;
1005 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, code_off);999 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_off);
1006 block.high_pc = @intCast(di_w.end);1000 block.high_pc = @intCast(di_w.end);
1007 try di_w.writeInt(u32, 0, dwarf.endian);1001 try di_w.writeInt(u32, 0, dwarf.endian);
1008 debug.empty = true;1002 debug.empty = true;
...@@ -1010,12 +1004,12 @@ pub const WipNav = struct {...@@ -1010,12 +1004,12 @@ pub const WipNav = struct {
10101004
1011 pub fn leaveBlock(debug: *Debug, code_off: usize) link.Error!void {1005 pub fn leaveBlock(debug: *Debug, code_off: usize) link.Error!void {
1012 return debug.leaveBlockInner(code_off) catch |err| switch (err) {1006 return debug.leaveBlockInner(code_off) catch |err| switch (err) {
1013 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
1014 else => |e| e,1007 else => |e| e,
1008 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
1015 };1009 };
1016 }1010 }
1017 fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {1011 fn leaveBlockInner(debug: *Debug, code_off: usize) link.EmitError!void {
1018 const dwarf = debug.wip_nav.dwarf;1012 const dwarf = debug.wip_func.dwarf;
1019 const block = debug.blocks.pop().?;1013 const block = debug.blocks.pop().?;
10201014
1021 const di_nw = &debug.info_writer;1015 const di_nw = &debug.info_writer;
...@@ -1043,8 +1037,8 @@ pub const WipNav = struct {...@@ -1043,8 +1037,8 @@ pub const WipNav = struct {
1043 column: u32,1037 column: u32,
1044 ) link.Error!void {1038 ) link.Error!void {
1045 return debug.enterInlineFuncInner(func, code_off, line, column) catch |err| switch (err) {1039 return debug.enterInlineFuncInner(func, code_off, line, column) catch |err| switch (err) {
1046 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
1047 else => |e| e,1040 else => |e| e,
1041 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
1048 };1042 };
1049 }1043 }
1050 fn enterInlineFuncInner(1044 fn enterInlineFuncInner(
...@@ -1054,22 +1048,23 @@ pub const WipNav = struct {...@@ -1054,22 +1048,23 @@ pub const WipNav = struct {
1054 line: u32,1048 line: u32,
1055 column: u32,1049 column: u32,
1056 ) link.EmitError!void {1050 ) link.EmitError!void {
1057 const dwarf = debug.wip_nav.dwarf;1051 const dwarf = debug.wip_func.dwarf;
1058 const zcu = debug.pt.zcu;1052 const pt = debug.pt;
1053 const zcu = pt.zcu;
1059 const block = try debug.blocks.addOne(zcu.gpa);1054 const block = try debug.blocks.addOne(zcu.gpa);
10601055
1061 const di_nw = &debug.info_writer;1056 const di_nw = &debug.info_writer;
1062 const di_w = &di_nw.interface;1057 const di_w = &di_nw.interface;
1063 block.abbrev_code = @intCast(di_w.end);1058 block.abbrev_code = @intCast(di_w.end);
1064 try dwarf.abbrevCode(di_nw, .inlined_func);1059 try dwarf.abbrevCode(di_nw, .inlined_func);
1065 try debug.refFunc(func);1060 try dwarf.refConst(pt, di_nw, .fromInterned(func));
1066 try di_w.writeUleb128((if (zcu.comp.config.incremental)1061 try di_w.writeUleb128((if (zcu.comp.config.incremental)
1067 01062 0
1068 else1063 else
1069 zcu.navSrcLine(zcu.funcInfo(debug.wip_nav.func).owner_nav) + 1) + line);1064 zcu.navSrcLine(zcu.funcInfo(debug.wip_func.func).owner_nav) + 1) + line);
1070 try di_w.writeUleb128(column + 1);1065 try di_w.writeUleb128(column + 1);
1071 block.low_pc_off = code_off;1066 block.low_pc_off = code_off;
1072 try dwarf.addrSym(di_nw, debug.wip_nav.func_si, code_off);1067 try dwarf.addrSym(di_nw, debug.wip_func.func_si, code_off);
1073 block.high_pc = @intCast(di_w.end);1068 block.high_pc = @intCast(di_w.end);
1074 try di_w.writeInt(u32, 0, dwarf.endian);1069 try di_w.writeInt(u32, 0, dwarf.endian);
1075 try debug.setInlineFunc(func);1070 try debug.setInlineFunc(func);
...@@ -1078,8 +1073,8 @@ pub const WipNav = struct {...@@ -1078,8 +1073,8 @@ pub const WipNav = struct {
10781073
1079 pub fn leaveInlineFunc(debug: *Debug, func: InternPool.Index, code_off: usize) link.Error!void {1074 pub fn leaveInlineFunc(debug: *Debug, func: InternPool.Index, code_off: usize) link.Error!void {
1080 return debug.leaveInlineFuncInner(func, code_off) catch |err| switch (err) {1075 return debug.leaveInlineFuncInner(func, code_off) catch |err| switch (err) {
1081 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.info_writer),
1082 else => |e| e,1076 else => |e| e,
1077 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.info_writer),
1083 };1078 };
1084 }1079 }
1085 fn leaveInlineFuncInner(1080 fn leaveInlineFuncInner(
...@@ -1087,7 +1082,7 @@ pub const WipNav = struct {...@@ -1087,7 +1082,7 @@ pub const WipNav = struct {
1087 func: InternPool.Index,1082 func: InternPool.Index,
1088 code_off: usize,1083 code_off: usize,
1089 ) link.EmitError!void {1084 ) link.EmitError!void {
1090 const dwarf = debug.wip_nav.dwarf;1085 const dwarf = debug.wip_func.dwarf;
1091 const block = debug.blocks.pop().?;1086 const block = debug.blocks.pop().?;
10921087
1093 const di_nw = &debug.info_writer;1088 const di_nw = &debug.info_writer;
...@@ -1110,15 +1105,15 @@ pub const WipNav = struct {...@@ -1110,15 +1105,15 @@ pub const WipNav = struct {
11101105
1111 pub fn setInlineFunc(debug: *Debug, func: InternPool.Index) link.Error!void {1106 pub fn setInlineFunc(debug: *Debug, func: InternPool.Index) link.Error!void {
1112 return debug.setInlineFuncInner(func) catch |err| switch (err) {1107 return debug.setInlineFuncInner(func) catch |err| switch (err) {
1113 error.WriteFailed => return debug.wip_nav.dwarf.reportWriteError(&debug.line_writer),
1114 else => |e| e,1108 else => |e| e,
1109 error.WriteFailed => return debug.wip_func.dwarf.reportWriteError(&debug.line_writer),
1115 };1110 };
1116 }1111 }
1117 fn setInlineFuncInner(debug: *Debug, func: InternPool.Index) link.EmitError!void {1112 fn setInlineFuncInner(debug: *Debug, func: InternPool.Index) link.EmitError!void {
1118 const zcu = debug.pt.zcu;1113 const zcu = debug.pt.zcu;
1119 const ip = &zcu.intern_pool;1114 const ip = &zcu.intern_pool;
1120 const dwarf = debug.wip_nav.dwarf;1115 const dwarf = debug.wip_func.dwarf;
1121 if (debug.wip_nav.func == func) return;1116 if (debug.wip_func.func == func) return;
11221117
1123 const dl_nw = &debug.line_writer;1118 const dl_nw = &debug.line_writer;
1124 const dl_w = &dl_nw.interface;1119 const dl_w = &dl_nw.interface;
...@@ -1132,7 +1127,7 @@ pub const WipNav = struct {...@@ -1132,7 +1127,7 @@ pub const WipNav = struct {
1132 return;1127 return;
1133 }1128 }
11341129
1135 const old_owner_nav = zcu.funcInfo(debug.wip_nav.func).owner_nav;1130 const old_owner_nav = zcu.funcInfo(debug.wip_func.func).owner_nav;
1136 const old_inst_info = ip.getNav(old_owner_nav).srcInst(ip).resolveFull(ip).?;1131 const old_inst_info = ip.getNav(old_owner_nav).srcInst(ip).resolveFull(ip).?;
1137 const old_zf = zcu.fileByIndex(old_inst_info.file);1132 const old_zf = zcu.fileByIndex(old_inst_info.file);
1138 const new_inst_info = ip.getNav(new_owner_nav).srcInst(ip).resolveFull(ip).?;1133 const new_inst_info = ip.getNav(new_owner_nav).srcInst(ip).resolveFull(ip).?;
...@@ -1140,7 +1135,7 @@ pub const WipNav = struct {...@@ -1140,7 +1135,7 @@ pub const WipNav = struct {
1140 if (old_inst_info.file != new_inst_info.file) {1135 if (old_inst_info.file != new_inst_info.file) {
1141 const new_ui = dwarf.getUnit(new_zf.mod.?);1136 const new_ui = dwarf.getUnit(new_zf.mod.?);
1142 _, const new_fi =1137 _, const new_fi =
1143 try debug.wip_nav.unit.get(dwarf).getFile(zcu.gpa, new_ui, new_inst_info.file);1138 try debug.wip_func.unit.get(dwarf).getFile(zcu.gpa, new_ui, new_inst_info.file);
11441139
1145 try dl_w.writeByte(DW.LNS.set_file);1140 try dl_w.writeByte(DW.LNS.set_file);
1146 try dl_w.writeUleb128(@backingInt(new_fi));1141 try dl_w.writeUleb128(@backingInt(new_fi));
...@@ -1153,38 +1148,27 @@ pub const WipNav = struct {...@@ -1153,38 +1148,27 @@ pub const WipNav = struct {
1153 try dl_w.writeSleb128(new_src_line - old_src_line);1148 try dl_w.writeSleb128(new_src_line - old_src_line);
1154 }1149 }
11551150
1156 debug.wip_nav.func = func;1151 debug.wip_func.func = func;
1157 }
1158
1159 fn refFunc(debug: *Debug, func: InternPool.Index) link.EmitError!void {
1160 const dwarf = debug.wip_nav.dwarf;
1161 const fi = try dwarf.getFunc(debug.pt.zcu.funcInfo(func).owner_nav);
1162 try debug.wip_nav.dwarf.secOffset(
1163 &debug.info_writer,
1164 fi.get(dwarf).debug_info_ni.unwrap().?,
1165 0,
1166 );
1167 }1152 }
1168 };1153 };
11691154
1170 pub fn deinit(wip_nav: *WipNav) void {1155 pub fn deinit(wip_func: *WipFunc) void {
1171 wip_nav.fde_writer.deinit();1156 wip_func.fde_writer.deinit();
1172 wip_nav.* = undefined;1157 wip_func.* = undefined;
1173 }1158 }
11741159
1175 pub fn genDebugFrameHeader(wip_nav: *WipNav) link.Error!void {1160 pub fn genDebugFrameHeader(wip_func: *WipFunc) link.Error!void {
1176 wip_nav.genDebugFrameHeaderInner() catch |err| switch (err) {1161 wip_func.genDebugFrameHeaderInner() catch |err| switch (err) {
1177 error.WriteFailed => return wip_nav.dwarf.reportWriteError(&wip_nav.fde_writer),
1178 else => |e| return e,1162 else => |e| return e,
1163 error.WriteFailed => return wip_func.dwarf.reportWriteError(&wip_func.fde_writer),
1179 };1164 };
1180 }1165 }
1181 fn genDebugFrameHeaderInner(wip_nav: *WipNav) link.EmitError!void {1166 fn genDebugFrameHeaderInner(wip_func: *WipFunc) link.EmitError!void {
1182 assert(wip_nav.func != .none);1167 const dwarf = wip_func.dwarf;
1183 const dwarf = wip_nav.dwarf;1168 const df_nw = &wip_func.fde_writer;
1184 const df_nw = &wip_nav.fde_writer;
1185 const df_w = &df_nw.interface;1169 const df_w = &df_nw.interface;
1186 try dwarf.genUnitLength(df_w);1170 try dwarf.genUnitLength(df_w);
1187 switch (wip_nav.frame_format) {1171 switch (wip_func.frame_format) {
1188 .eh_frame => {1172 .eh_frame => {
1189 try df_w.writeInt(u32, undefined, dwarf.endian);1173 try df_w.writeInt(u32, undefined, dwarf.endian);
1190 {1174 {
...@@ -1193,51 +1177,50 @@ pub const WipNav = struct {...@@ -1193,51 +1177,50 @@ pub const WipNav = struct {
1193 if (dwarf.lf.cast(.elf2)) |elf| try elf.addReloc(1177 if (dwarf.lf.cast(.elf2)) |elf| try elf.addReloc(
1194 @bitCast(df_nw.ni),1178 @bitCast(df_nw.ni),
1195 offset,1179 offset,
1196 wip_nav.func_si,1180 wip_func.func_si,
1197 0,1181 0,
1198 .rel32(elf),1182 .rel32(elf),
1199 ) else unreachable;1183 ) else unreachable;
1200 }1184 }
1201 wip_nav.frame_func_length = .{ .offset = df_w.end, .size = .@"32" };1185 wip_func.frame_func_length = .{ .offset = df_w.end, .size = .@"32" };
1202 try df_w.writeInt(u32, undefined, dwarf.endian);1186 try df_w.writeInt(u32, undefined, dwarf.endian);
1203 try df_w.writeUleb128(0);1187 try df_w.writeUleb128(0);
1204 },1188 },
1205 .debug_frame => {1189 .debug_frame => {
1206 try dwarf.secOffset(df_nw, wip_nav.unit.get(dwarf).cie_ni.unwrap().?, 0);1190 try dwarf.secOffset(df_nw, wip_func.unit.get(dwarf).cie_ni.unwrap().?, 0);
1207 try dwarf.addrSym(df_nw, wip_nav.func_si, 0);1191 try dwarf.addrSym(df_nw, wip_func.func_si, 0);
1208 wip_nav.frame_func_length = .{ .offset = df_w.end, .size = dwarf.address_size };1192 wip_func.frame_func_length = .{ .offset = df_w.end, .size = dwarf.address_size };
1209 try dwarf.addrPlaceholder(df_w);1193 try dwarf.addrPlaceholder(df_w);
1210 },1194 },
1211 }1195 }
1212 }1196 }
12131197
1214 pub fn genDebugFrame(wip_nav: *WipNav, loc: u32, cfa: Cfa) link.Error!void {1198 pub fn genDebugFrame(wip_func: *WipFunc, loc: u32, cfa: Cfa) link.Error!void {
1215 return wip_nav.genDebugFrameInner(loc, cfa) catch |err| switch (err) {1199 return wip_func.genDebugFrameInner(loc, cfa) catch |err| switch (err) {
1216 error.WriteFailed => return wip_nav.dwarf.reportWriteError(&wip_nav.fde_writer),
1217 else => |e| return e,1200 else => |e| return e,
1201 error.WriteFailed => return wip_func.dwarf.reportWriteError(&wip_func.fde_writer),
1218 };1202 };
1219 }1203 }
1220 fn genDebugFrameInner(wip_nav: *WipNav, loc: u32, cfa: Cfa) link.EmitError!void {1204 fn genDebugFrameInner(wip_func: *WipFunc, loc: u32, cfa: Cfa) link.EmitError!void {
1221 assert(wip_nav.func != .none);
1222 const loc_cfa: Cfa = .{ .advance_loc = loc };1205 const loc_cfa: Cfa = .{ .advance_loc = loc };
1223 try loc_cfa.write(wip_nav);1206 try loc_cfa.write(wip_func);
1224 try cfa.write(wip_nav);1207 try cfa.write(wip_func);
1225 }1208 }
12261209
1227 pub fn finishDebugFrameFde(wip_nav: *WipNav, func_length: u64) void {1210 pub fn finishDebugFrameFde(wip_func: *WipFunc, func_length: u64) void {
1228 const dwarf = wip_nav.dwarf;1211 const dwarf = wip_func.dwarf;
1229 const df_w = &wip_nav.fde_writer.interface;1212 const df_w = &wip_func.fde_writer.interface;
1230 switch (wip_nav.frame_func_length.size) {1213 switch (wip_func.frame_func_length.size) {
1231 _ => unreachable,1214 _ => unreachable,
1232 .@"32" => std.mem.writeInt(1215 .@"32" => std.mem.writeInt(
1233 u32,1216 u32,
1234 df_w.buffered()[wip_nav.frame_func_length.offset..][0..4],1217 df_w.buffered()[wip_func.frame_func_length.offset..][0..4],
1235 @intCast(func_length),1218 @intCast(func_length),
1236 dwarf.endian,1219 dwarf.endian,
1237 ),1220 ),
1238 .@"64" => std.mem.writeInt(1221 .@"64" => std.mem.writeInt(
1239 u64,1222 u64,
1240 df_w.buffered()[wip_nav.frame_func_length.offset..][0..8],1223 df_w.buffered()[wip_func.frame_func_length.offset..][0..8],
1241 func_length,1224 func_length,
1242 dwarf.endian,1225 dwarf.endian,
1243 ),1226 ),
...@@ -1966,6 +1949,197 @@ pub fn genDebugRnglists(...@@ -1966,6 +1949,197 @@ pub fn genDebugRnglists(
1966 try dr_w.writeByte(DW.RLE.end_of_list);1949 try dr_w.writeByte(DW.RLE.end_of_list);
1967}1950}
19681951
1952pub fn updateExtern(
1953 dwarf: *Dwarf,
1954 pt: Zcu.PerThread,
1955 di_nw: *link.MappedFile.Node.Writer,
1956 arch: std.Target.Cpu.Arch,
1957 si: link.File.SymbolId,
1958 global: InternPool.Nav.Index,
1959) link.Error!void {
1960 dwarf.updateExternInner(pt, di_nw, arch, si, global) catch |err| switch (err) {
1961 else => |e| return e,
1962 error.WriteFailed => return dwarf.reportWriteError(di_nw),
1963 };
1964}
1965fn updateExternInner(
1966 dwarf: *Dwarf,
1967 pt: Zcu.PerThread,
1968 di_nw: *link.MappedFile.Node.Writer,
1969 arch: std.Target.Cpu.Arch,
1970 si: link.File.SymbolId,
1971 global: InternPool.Nav.Index,
1972) link.EmitError!void {
1973 const zcu = pt.zcu;
1974 const ip = &zcu.intern_pool;
1975 const nav = ip.getNav(global);
1976 log.debug("updateExtern({f})", .{nav.fqn.fmt(ip)});
1977 const nav_align, const nav_const, const nav_threadlocal, const nav_extern = nav_resolved: {
1978 const nav_resolved = nav.resolved.?;
1979 break :nav_resolved .{
1980 nav_resolved.@"align",
1981 nav_resolved.@"const",
1982 nav_resolved.@"threadlocal",
1983 ip.indexToKey(nav_resolved.value).@"extern",
1984 };
1985 };
1986 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
1987 const decl = switch (nav_extern.source) {
1988 .builtin => undefined,
1989 .syntax => zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst),
1990 };
1991 const maybe_func_type = switch (ip.indexToKey(nav_extern.ty)) {
1992 .func_type => |func_type| func_type,
1993 else => null,
1994 };
1995 const is_empty = if (maybe_func_type) |func_type| func_type.param_types.len == 0 and
1996 !func_type.is_var_args else undefined;
1997 const di_w = &di_nw.interface;
1998 switch (nav_extern.source) {
1999 .builtin => {
2000 try dwarf.abbrevCode(di_nw, if (maybe_func_type) |_|
2001 if (is_empty) .builtin_extern_empty_func else .builtin_extern_func
2002 else
2003 .builtin_extern_var);
2004 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
2005 },
2006 .syntax => if (maybe_func_type) |_| {
2007 try dwarf.abbrevCode(
2008 di_nw,
2009 if (is_empty) .decl_extern_empty_func else .decl_extern_func,
2010 );
2011 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
2012 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2013 try di_w.writeUleb128(decl.src_column + 1);
2014 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));
2016 } else {
2017 try dwarf.abbrevCode(di_nw, .decl_var);
2018 try dwarf.refType(pt, di_nw, .fromInterned(zcu.fileRootType(inst_info.file)));
2019 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2020 try di_w.writeUleb128(decl.src_column + 1);
2021 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));
2023 },
2024 }
2025 try dwarf.strp(&dwarf.debug_str, di_nw, nav_extern.name.toSlice(ip));
2026 if (maybe_func_type) |func_type| {
2027 try dwarf.refType(pt, di_nw, .fromInterned(func_type.return_type));
2028 try dwarf.addrSym(di_nw, si, 0);
2029 try di_w.writeByte(@intFromBool(Type.fromInterned(func_type.return_type).isNoReturn(zcu)));
2030 for (func_type.param_types.get(ip)) |param_type| {
2031 try dwarf.abbrevCode(di_nw, .extern_param);
2032 try dwarf.refType(pt, di_nw, .fromInterned(param_type));
2033 }
2034 if (func_type.is_var_args) try dwarf.abbrevCode(di_nw, .is_var_args);
2035 if (!is_empty) try di_w.writeUleb128(@backingInt(AbbrevCode.null));
2036 } else {
2037 const addr: Loc = .{ .addr_reloc = si };
2038 const loc: Loc = if (nav_threadlocal) switch (arch) {
2039 .x86_64 => .{ .form_tls_address = &addr },
2040 else => unreachable,
2041 } else addr;
2042 const type_offset = di_w.end;
2043 if (nav_const)
2044 try dwarf.secOffsetPlaceholder(di_w)
2045 else
2046 try dwarf.refType(pt, di_nw, .fromInterned(nav_extern.ty));
2047 try dwarf.exprLoc(di_nw, loc);
2048 try di_w.writeUleb128(nav_align.toByteUnits() orelse
2049 Type.fromInterned(nav_extern.ty).abiAlignment(zcu).toByteUnits().?);
2050 switch (nav_extern.source) {
2051 .builtin => {},
2052 .syntax => try di_w.writeByte(@intFromBool(decl.linkage != .normal)),
2053 }
2054 if (nav_const) {
2055 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2056 try dwarf.abbrevCode(di_nw, .is_const);
2057 try dwarf.refType(pt, di_nw, .fromInterned(nav_extern.ty));
2058 }
2059 }
2060 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2061}
2062
2063pub fn updateGlobal(
2064 dwarf: *Dwarf,
2065 pt: Zcu.PerThread,
2066 di_nw: *link.MappedFile.Node.Writer,
2067 arch: std.Target.Cpu.Arch,
2068 si: link.File.SymbolId,
2069 global: InternPool.Nav.Index,
2070) link.Error!void {
2071 const ip = &pt.zcu.intern_pool;
2072 log.debug("updateGlobal({f})", .{ip.getNav(global).fqn.fmt(ip)});
2073 dwarf.updateGlobalInner(pt, di_nw, arch, si, global) catch |err| switch (err) {
2074 else => |e| return e,
2075 error.WriteFailed => return dwarf.reportWriteError(di_nw),
2076 };
2077}
2078fn updateGlobalInner(
2079 dwarf: *Dwarf,
2080 pt: Zcu.PerThread,
2081 di_nw: *link.MappedFile.Node.Writer,
2082 arch: std.Target.Cpu.Arch,
2083 si: link.File.SymbolId,
2084 global: InternPool.Nav.Index,
2085) link.EmitError!void {
2086 const zcu = pt.zcu;
2087 const ip = &zcu.intern_pool;
2088 const nav = ip.getNav(global);
2089 const nav_ty: Type, const nav_align, const nav_const, const nav_threadlocal = nav_resolved: {
2090 const nav_resolved = nav.resolved.?;
2091 break :nav_resolved .{
2092 .fromInterned(nav_resolved.type),
2093 nav_resolved.@"align",
2094 nav_resolved.@"const",
2095 nav_resolved.@"threadlocal",
2096 };
2097 };
2098 const inst_info = nav.srcInst(ip).resolveFull(ip).?;
2099 const decl = zcu.fileByIndex(inst_info.file).zir.?.getDeclaration(inst_info.inst);
2100 switch (decl.kind) {
2101 .unnamed_test, .@"test", .decltest, .@"comptime" => unreachable,
2102 .@"const" => assert(nav_const),
2103 .@"var" => assert(!nav_const),
2104 }
2105 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2106 const di_w = &di_nw.interface;
2107 if (parent_ty.getCaptures(zcu).len > 0) {
2108 try dwarf.abbrevCode(di_nw, .decl_instance_var);
2109 try dwarf.refType(pt, di_nw, parent_ty);
2110 try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0);
2111 } else {
2112 const parent_ni = try dwarf.getConstDecl(pt, parent_ty.toIntern());
2113 try dwarf.abbrevCode(di_nw, .decl_var);
2114 try dwarf.secOffset(di_nw, parent_ni, 0);
2115 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
2116 try di_w.writeUleb128(decl.src_column + 1);
2117 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));
2119 }
2120 try dwarf.strp(&dwarf.debug_str, di_nw, switch (decl.linkage) {
2121 .normal => nav.fqn,
2122 .@"extern" => unreachable,
2123 .@"export" => nav.name,
2124 }.toSlice(ip));
2125 const addr: Loc = .{ .addr_reloc = si };
2126 const loc: Loc = if (nav_threadlocal) switch (arch) {
2127 .x86_64 => .{ .form_tls_address = &addr },
2128 else => unreachable,
2129 } else addr;
2130 const type_offset = di_w.end;
2131 if (nav_const) try dwarf.secOffsetPlaceholder(di_w) else try dwarf.refType(pt, di_nw, nav_ty);
2132 try dwarf.exprLoc(di_nw, loc);
2133 try di_w.writeUleb128(nav_align.toByteUnits() orelse nav_ty.abiAlignment(zcu).toByteUnits().?);
2134 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
2135 if (nav_const) {
2136 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2137 try dwarf.abbrevCode(di_nw, .is_const);
2138 try dwarf.refType(pt, di_nw, nav_ty);
2139 }
2140 try dwarf.genDebugInfoPadding(di_w, di_w.unusedCapacityLen());
2141}
2142
1969pub fn updateComptimeGlobal(2143pub fn updateComptimeGlobal(
1970 dwarf: *Dwarf,2144 dwarf: *Dwarf,
1971 pt: Zcu.PerThread,2145 pt: Zcu.PerThread,
...@@ -2010,30 +2184,30 @@ pub fn updateComptimeGlobal(...@@ -2010,30 +2184,30 @@ pub fn updateComptimeGlobal(
2010 .aggregate,2184 .aggregate,
2011 .un,2185 .un,
2012 .bitpack,2186 .bitpack,
2013 => try dwarf.genGlobal(pt, global, &decl),2187 => try dwarf.genComptimeGlobal(pt, global, &decl),
2014 .struct_type => {2188 .struct_type => {
2015 const loaded_struct = ip.loadStructType(nav_val.toIntern());2189 const loaded_struct = ip.loadStructType(nav_val.toIntern());
2016 if (global.toOptional() == loaded_struct.name_nav) {2190 if (global.toOptional() == loaded_struct.name_nav) {
2017 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2191 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2018 } else try dwarf.genGlobal(pt, global, &decl);2192 } else try dwarf.genComptimeGlobal(pt, global, &decl);
2019 },2193 },
2020 .enum_type => {2194 .enum_type => {
2021 const loaded_enum = ip.loadEnumType(nav_val.toIntern());2195 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
2022 if (global.toOptional() == loaded_enum.name_nav) {2196 if (global.toOptional() == loaded_enum.name_nav) {
2023 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2197 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2024 } else try dwarf.genGlobal(pt, global, &decl);2198 } else try dwarf.genComptimeGlobal(pt, global, &decl);
2025 },2199 },
2026 .union_type => {2200 .union_type => {
2027 const loaded_union = ip.loadUnionType(nav_val.toIntern());2201 const loaded_union = ip.loadUnionType(nav_val.toIntern());
2028 if (global.toOptional() == loaded_union.name_nav) {2202 if (global.toOptional() == loaded_union.name_nav) {
2029 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2203 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2030 } else try dwarf.genGlobal(pt, global, &decl);2204 } else try dwarf.genComptimeGlobal(pt, global, &decl);
2031 },2205 },
2032 .opaque_type => {2206 .opaque_type => {
2033 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());2207 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
2034 if (global.toOptional() == loaded_opaque.name_nav) {2208 if (global.toOptional() == loaded_opaque.name_nav) {
2035 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());2209 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
2036 } else try dwarf.genGlobal(pt, global, &decl);2210 } else try dwarf.genComptimeGlobal(pt, global, &decl);
2037 },2211 },
2038 .@"extern" => unreachable,2212 .@"extern" => unreachable,
2039 .func => |func| if (func.owner_nav == global and func.generic_owner == .none) {2213 .func => |func| if (func.owner_nav == global and func.generic_owner == .none) {
...@@ -2042,26 +2216,28 @@ pub fn updateComptimeGlobal(...@@ -2042,26 +2216,28 @@ pub fn updateComptimeGlobal(
2042 .memoized_call => unreachable, // not a value2216 .memoized_call => unreachable, // not a value
2043 }2217 }
2044}2218}
2045fn genGlobal(2219fn genComptimeGlobal(
2046 dwarf: *Dwarf,2220 dwarf: *Dwarf,
2047 pt: Zcu.PerThread,2221 pt: Zcu.PerThread,
2048 global: InternPool.Nav.Index,2222 global: InternPool.Nav.Index,
2049 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,2223 decl: *const std.zig.Zir.Inst.Declaration.Unwrapped,
2050) link.Error!void {2224) link.Error!void {
2225 const gpa = pt.zcu.gpa;
2051 const gi = try dwarf.getGlobal(global);2226 const gi = try dwarf.getGlobal(global);
2052 const debug_info_ni = gi.get(dwarf).debug_info_ni.unwrap().?;2227 const debug_info_ni = gi.get(dwarf).debug_info_ni.unwrap().?;
2053 var di_nw: link.MappedFile.Node.Writer = undefined;2228 var di_nw: link.MappedFile.Node.Writer = undefined;
2054 if (dwarf.lf.cast(.elf2)) |elf| {2229 if (dwarf.lf.cast(.elf2)) |elf| {
2055 debug_info_ni.writer(pt.zcu.gpa, &elf.mf, &di_nw);2230 try debug_info_ni.moved(gpa, &elf.mf);
2231 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
2056 elf.resetNodeRelocs(debug_info_ni);2232 elf.resetNodeRelocs(debug_info_ni);
2057 } else unreachable;2233 } else unreachable;
2058 defer di_nw.deinit();2234 defer di_nw.deinit();
2059 dwarf.genGlobalInner(pt, &di_nw, global, decl) catch |err| switch (err) {2235 dwarf.genComptimeGlobalInner(pt, &di_nw, global, decl) catch |err| switch (err) {
2060 error.WriteFailed => return dwarf.reportWriteError(&di_nw),
2061 else => |e| return e,2236 else => |e| return e,
2237 error.WriteFailed => return dwarf.reportWriteError(&di_nw),
2062 };2238 };
2063}2239}
2064fn genGlobalInner(2240fn genComptimeGlobalInner(
2065 dwarf: *Dwarf,2241 dwarf: *Dwarf,
2066 pt: Zcu.PerThread,2242 pt: Zcu.PerThread,
2067 di_nw: *link.MappedFile.Node.Writer,2243 di_nw: *link.MappedFile.Node.Writer,
...@@ -2071,40 +2247,40 @@ fn genGlobalInner(...@@ -2071,40 +2247,40 @@ fn genGlobalInner(
2071 const zcu = pt.zcu;2247 const zcu = pt.zcu;
2072 const ip = &zcu.intern_pool;2248 const ip = &zcu.intern_pool;
2073 const nav = ip.getNav(global);2249 const nav = ip.getNav(global);
2074 const nav_const, const nav_ty: Type, const nav_align, const nav_val: Value = nav_resolved: {2250 const nav_ty: Type, const nav_align, const nav_const, const nav_val: Value = nav_resolved: {
2075 const nav_resolved = nav.resolved.?;2251 const nav_resolved = nav.resolved.?;
2076 break :nav_resolved .{2252 break :nav_resolved .{
2077 nav_resolved.@"const",
2078 .fromInterned(nav_resolved.type),2253 .fromInterned(nav_resolved.type),
2079 nav_resolved.@"align",2254 nav_resolved.@"align",
2255 nav_resolved.@"const",
2080 .fromInterned(nav_resolved.value),2256 .fromInterned(nav_resolved.value),
2081 };2257 };
2082 };2258 };
2083 const nav_class = nav_ty.classify(zcu);2259 const nav_class = nav_ty.classify(zcu);
2084 const parent_ty = ip.namespacePtr(nav.analysis.?.namespace).owner_type;2260 const parent_ty: Type = .fromInterned(ip.namespacePtr(nav.analysis.?.namespace).owner_type);
2085 const di_w = &di_nw.interface;2261 const di_w = &di_nw.interface;
2086 if (Type.fromInterned(parent_ty).getCaptures(zcu).len > 0) {2262 if (parent_ty.getCaptures(zcu).len > 0) {
2087 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {2263 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {
2088 .type_type => .decl_instance_type,2264 .type_type => .decl_instance_type,
2089 else => if (nav_const) switch (nav_class) {2265 else => switch (nav_class) {
2090 .no_possible_value, .one_possible_value => .decl_instance_const,2266 .no_possible_value, .one_possible_value => .decl_instance_const,
2091 .runtime => .decl_instance_const_fully_runtime,2267 .runtime => .decl_instance_const_fully_runtime,
2092 .partially_comptime => .decl_instance_const_partially_comptime,2268 .partially_comptime => .decl_instance_const_partially_comptime,
2093 .fully_comptime => .decl_instance_const_fully_comptime,2269 .fully_comptime => .decl_instance_const_fully_comptime,
2094 } else .decl_instance_var,2270 },
2095 });2271 });
2096 try dwarf.refType(pt, di_nw, .fromInterned(parent_ty));2272 try dwarf.refType(pt, di_nw, parent_ty);
2097 try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0);2273 try dwarf.secOffset(di_nw, try dwarf.getGlobalDecl(pt, global), 0);
2098 } else {2274 } else {
2099 const parent_ni = try dwarf.getConstDecl(pt, parent_ty);2275 const parent_ni = try dwarf.getConstDecl(pt, parent_ty.toIntern());
2100 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {2276 try dwarf.abbrevCode(di_nw, switch (nav_ty.toIntern()) {
2101 .type_type => .decl_type,2277 .type_type => .decl_type,
2102 else => if (nav_const) switch (nav_class) {2278 else => switch (nav_class) {
2103 .no_possible_value, .one_possible_value => .decl_const,2279 .no_possible_value, .one_possible_value => .decl_const,
2104 .runtime => .decl_const_fully_runtime,2280 .runtime => .decl_const_fully_runtime,
2105 .partially_comptime => .decl_const_partially_comptime,2281 .partially_comptime => .decl_const_partially_comptime,
2106 .fully_comptime => .decl_const_fully_comptime,2282 .fully_comptime => .decl_const_fully_comptime,
2107 } else .decl_var,2283 },
2108 });2284 });
2109 try dwarf.secOffset(di_nw, parent_ni, 0);2285 try dwarf.secOffset(di_nw, parent_ni, 0);
2110 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);2286 try di_w.writeInt(u32, decl.src_line + 1, dwarf.endian);
...@@ -2120,16 +2296,16 @@ fn genGlobalInner(...@@ -2120,16 +2296,16 @@ fn genGlobalInner(
2120 .@"extern", .@"export" => nav.name,2296 .@"extern", .@"export" => nav.name,
2121 }.toSlice(ip));2297 }.toSlice(ip));
2122 const type_offset = di_w.end;2298 const type_offset = di_w.end;
2123 if (nav_const) try dwarf.secOffsetPlaceholder(di_w) else {2299 if (nav_const)
2300 try dwarf.secOffsetPlaceholder(di_w)
2301 else
2124 try dwarf.refType(pt, di_nw, nav_ty);2302 try dwarf.refType(pt, di_nw, nav_ty);
2125 try dwarf.blockConst(pt, di_nw, nav_val);
2126 }
2127 try di_w.writeUleb128(nav_align.toByteUnits() orelse2303 try di_w.writeUleb128(nav_align.toByteUnits() orelse
2128 nav_ty.abiAlignment(zcu).toByteUnits().?);2304 nav_ty.abiAlignment(zcu).toByteUnits().?);
2129 try di_w.writeByte(@intFromBool(decl.linkage != .normal));2305 try di_w.writeByte(@intFromBool(decl.linkage != .normal));
2306 if (nav_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, nav_val);
2307 if (nav_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, nav_val);
2130 if (nav_const) {2308 if (nav_const) {
2131 if (nav_class.hasRuntimeBits()) try dwarf.blockConst(pt, di_nw, nav_val);
2132 if (nav_class.comptimeOnly()) try dwarf.refConst(pt, di_nw, nav_val);
2133 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);2309 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2134 try dwarf.abbrevCode(di_nw, .is_const);2310 try dwarf.abbrevCode(di_nw, .is_const);
2135 try dwarf.refType(pt, di_nw, nav_ty);2311 try dwarf.refType(pt, di_nw, nav_ty);
...@@ -2229,36 +2405,34 @@ fn updateConstInner(...@@ -2229,36 +2405,34 @@ fn updateConstInner(
2229 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});2405 const name = try zcu.gpa.print("{f}", .{Type.fromInterned(val).fmt(pt)});
2230 defer zcu.gpa.free(name);2406 defer zcu.gpa.free(name);
2231 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {2407 try dwarf.abbrevCode(di_nw, switch (ptr_type.sentinel) {
2232 .none => switch (ptr_type.flags.alignment) {2408 .none => .ptr_type,
2233 .none => .ptr_type,2409 else => .ptr_sentinel_type,
2234 else => .ptr_aligned_type,
2235 },
2236 else => switch (ptr_type.flags.alignment) {
2237 .none => .ptr_sentinel_type,
2238 else => .ptr_aligned_sentinel_type,
2239 },
2240 });2410 });
2241 try dwarf.strp(&dwarf.debug_str, di_nw, name);2411 try dwarf.strp(&dwarf.debug_str, di_nw, name);
2242 switch (ptr_type.sentinel) {2412 switch (ptr_type.sentinel) {
2243 .none => {},2413 .none => {},
2244 else => |sentinel| try dwarf.blockConst(pt, di_nw, .fromInterned(sentinel)),2414 else => |sentinel| try dwarf.blockConst(pt, di_nw, .fromInterned(sentinel)),
2245 }2415 }
2246 if (ptr_type.flags.alignment.toByteUnits()) |a| try di_w.writeUleb128(a);
2247 try di_w.writeByte(@backingInt(ptr_type.flags.address_space));2416 try di_w.writeByte(@backingInt(ptr_type.flags.address_space));
2248 if (ptr_type.flags.is_const or ptr_type.flags.is_volatile) try dwarf.secOffset(2417 if (ptr_type.flags.alignment.toByteUnits()) |a| {
2249 di_nw,2418 const type_offset = di_w.end;
2250 di_nw.ni,2419 try dwarf.secOffsetPlaceholder(di_w);
2251 di_w.end + dwarf.secOffsetSize(),2420 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2252 );2421 try dwarf.abbrevCode(di_nw, .is_aligned);
2422 try di_w.writeUleb128(a);
2423 }
2253 if (ptr_type.flags.is_const) {2424 if (ptr_type.flags.is_const) {
2425 const type_offset = di_w.end;
2426 try dwarf.secOffsetPlaceholder(di_w);
2427 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2254 try dwarf.abbrevCode(di_nw, .is_const);2428 try dwarf.abbrevCode(di_nw, .is_const);
2255 if (ptr_type.flags.is_volatile) try dwarf.secOffset(
2256 di_nw,
2257 di_nw.ni,
2258 di_w.end + dwarf.secOffsetSize(),
2259 );
2260 }2429 }
2261 if (ptr_type.flags.is_volatile) try dwarf.abbrevCode(di_nw, .is_volatile);2430 if (ptr_type.flags.is_volatile) {
2431 const type_offset = di_w.end;
2432 try dwarf.secOffsetPlaceholder(di_w);
2433 try dwarf.secOffsetFinish(di_nw, type_offset, di_nw.ni, di_w.end);
2434 try dwarf.abbrevCode(di_nw, .is_volatile);
2435 }
2262 try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child));2436 try dwarf.refType(pt, di_nw, .fromInterned(ptr_type.child));
2263 },2437 },
2264 .slice => {2438 .slice => {
...@@ -2328,8 +2502,10 @@ fn updateConstInner(...@@ -2328,8 +2502,10 @@ fn updateConstInner(
2328 },2502 },
2329 .unpacked, .error_set, .pointer => {2503 .unpacked, .error_set, .pointer => {
2330 try dwarf.abbrevCode(di_nw, .tagged_union);2504 try dwarf.abbrevCode(di_nw, .tagged_union);
2331 try dwarf.secOffset(di_nw, di_nw.ni, di_w.end + dwarf.secOffsetSize());2505 const discr_offset = di_w.end;
2506 try dwarf.secOffsetPlaceholder(di_w);
2332 {2507 {
2508 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
2333 try dwarf.abbrevCode(di_nw, .generated_field);2509 try dwarf.abbrevCode(di_nw, .generated_field);
2334 try dwarf.strp(&dwarf.debug_str, di_nw, "has_value");2510 try dwarf.strp(&dwarf.debug_str, di_nw, "has_value");
2335 switch (opt_repr) {2511 switch (opt_repr) {
...@@ -2342,7 +2518,10 @@ fn updateConstInner(...@@ -2342,7 +2518,10 @@ fn updateConstInner(
2342 0);2518 0);
2343 },2519 },
2344 .error_set => {2520 .error_set => {
2345 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));2521 try dwarf.refType(pt, di_nw, try pt.intType(
2522 .unsigned,
2523 zcu.errorSetBits(),
2524 ));
2346 try di_w.writeUleb128(0);2525 try di_w.writeUleb128(0);
2347 },2526 },
2348 .pointer => {2527 .pointer => {
...@@ -2404,8 +2583,10 @@ fn updateConstInner(...@@ -2404,8 +2583,10 @@ fn updateConstInner(
2404 }2583 }
2405 {2584 {
2406 try dwarf.abbrevCode(di_nw, .tagged_union);2585 try dwarf.abbrevCode(di_nw, .tagged_union);
2407 try dwarf.secOffset(di_nw, di_nw.ni, di_w.end + dwarf.secOffsetSize());2586 const discr_offset = di_w.end;
2587 try dwarf.secOffsetPlaceholder(di_w);
2408 {2588 {
2589 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
2409 try dwarf.abbrevCode(di_nw, .generated_field);2590 try dwarf.abbrevCode(di_nw, .generated_field);
2410 try dwarf.strp(&dwarf.debug_str, di_nw, "is_error");2591 try dwarf.strp(&dwarf.debug_str, di_nw, "is_error");
2411 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));2592 try dwarf.refType(pt, di_nw, try pt.intType(.unsigned, zcu.errorSetBits()));
...@@ -2771,8 +2952,10 @@ fn updateConstInner(...@@ -2771,8 +2952,10 @@ fn updateConstInner(
2771 try dwarf.genCaptures(pt, di_nw, loaded_union.captures);2952 try dwarf.genCaptures(pt, di_nw, loaded_union.captures);
2772 if (loaded_union.has_runtime_tag) {2953 if (loaded_union.has_runtime_tag) {
2773 try dwarf.abbrevCode(di_nw, .tagged_union);2954 try dwarf.abbrevCode(di_nw, .tagged_union);
2774 try dwarf.secOffset(di_nw, di_nw.ni, di_w.end + dwarf.secOffsetSize());2955 const discr_offset = di_w.end;
2956 try dwarf.secOffsetPlaceholder(di_w);
2775 {2957 {
2958 try dwarf.secOffsetFinish(di_nw, discr_offset, di_nw.ni, di_w.end);
2776 try dwarf.abbrevCode(di_nw, .generated_field);2959 try dwarf.abbrevCode(di_nw, .generated_field);
2777 try dwarf.strp(&dwarf.debug_str, di_nw, "tag");2960 try dwarf.strp(&dwarf.debug_str, di_nw, "tag");
2778 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.enum_tag_type));2961 try dwarf.refType(pt, di_nw, .fromInterned(loaded_union.enum_tag_type));
...@@ -4084,8 +4267,11 @@ fn refAbbrevCode(...@@ -4084,8 +4267,11 @@ fn refAbbrevCode(
4084 @branchHint(.likely);4267 @branchHint(.likely);
4085 return backing_int;4268 return backing_int;
4086 }4269 }
4270 const gpa = dwarf.lf.comp.gpa;
4271 const debug_abbrev_ni = dwarf.debug_abbrev.ni.unwrap().?;
4272 try debug_abbrev_ni.moved(gpa, mf);
4087 var da_nw: link.MappedFile.Node.Writer = undefined;4273 var da_nw: link.MappedFile.Node.Writer = undefined;
4088 dwarf.debug_abbrev.ni.unwrap().?.writer(dwarf.lf.comp.gpa, mf, &da_nw);4274 debug_abbrev_ni.writer(gpa, mf, &da_nw);
4089 defer da_nw.deinit();4275 defer da_nw.deinit();
4090 dwarf.genDebugAbbrev(&da_nw, abbrev_code) catch |err| switch (err) {4276 dwarf.genDebugAbbrev(&da_nw, abbrev_code) catch |err| switch (err) {
4091 else => |e| return e,4277 else => |e| return e,
...@@ -4294,10 +4480,10 @@ fn exprLoc(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, loc: Loc) link.EmitE...@@ -4294,10 +4480,10 @@ fn exprLoc(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, loc: Loc) link.EmitE
4294fn strp(dwarf: *Dwarf, s: *Str, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {4480fn strp(dwarf: *Dwarf, s: *Str, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
4295 const comp = dwarf.lf.comp;4481 const comp = dwarf.lf.comp;
4296 try dwarf.secOffset(nw, s.ni.unwrap().?, s.get(comp.gpa, nw.mf, str) catch |err| switch (err) {4482 try dwarf.secOffset(nw, s.ni.unwrap().?, s.get(comp.gpa, nw.mf, str) catch |err| switch (err) {
4483 else => |e| return e,
4297 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{4484 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
4298 nw.mf.io_err.?,4485 nw.mf.io_err.?,
4299 }),4486 }),
4300 else => |e| return e,
4301 });4487 });
4302}4488}
43034489
...@@ -4433,8 +4619,6 @@ pub const AbbrevCode = enum {...@@ -4433,8 +4619,6 @@ pub const AbbrevCode = enum {
4433 decl_instance_func,4619 decl_instance_func,
4434 decl_instance_empty_func_generic,4620 decl_instance_empty_func_generic,
4435 decl_instance_func_generic,4621 decl_instance_func_generic,
4436 decl_instance_extern_empty_func,
4437 decl_instance_extern_func,
4438 // the rest are unrestricted other than empty variants must not be longer4622 // the rest are unrestricted other than empty variants must not be longer
4439 // than the non-empty variant, and so should appear first4623 // than the non-empty variant, and so should appear first
4440 compile_unit,4624 compile_unit,
...@@ -4462,8 +4646,7 @@ pub const AbbrevCode = enum {...@@ -4462,8 +4646,7 @@ pub const AbbrevCode = enum {
4462 inferred_error_set_type,4646 inferred_error_set_type,
4463 ptr_type,4647 ptr_type,
4464 ptr_sentinel_type,4648 ptr_sentinel_type,
4465 ptr_aligned_type,4649 is_aligned,
4466 ptr_aligned_sentinel_type,
4467 is_const,4650 is_const,
4468 is_volatile,4651 is_volatile,
4469 array_type,4652 array_type,
...@@ -4522,7 +4705,7 @@ pub const AbbrevCode = enum {...@@ -4522,7 +4705,7 @@ pub const AbbrevCode = enum {
4522 comptime_value_elem_runtime,4705 comptime_value_elem_runtime,
4523 comptime_value_elem_comptime,4706 comptime_value_elem_comptime,
45244707
4525 const decl_size = uleb128Size(@backingInt(AbbrevCode.decl_instance_extern_func));4708 const decl_size = uleb128Size(@backingInt(AbbrevCode.decl_func_generic));
4526 comptime {4709 comptime {
4527 assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1);4710 assert(uleb128Size(@backingInt(AbbrevCode.pad_1)) == 1);
4528 assert(uleb128Size(@backingInt(AbbrevCode.pad_n)) == 1);4711 assert(uleb128Size(@backingInt(AbbrevCode.pad_n)) == 1);
...@@ -5142,27 +5325,6 @@ pub const AbbrevCode = enum {...@@ -5142,27 +5325,6 @@ pub const AbbrevCode = enum {
5142 .{ .type, .ref_addr },5325 .{ .type, .ref_addr },
5143 },5326 },
5144 },5327 },
5145 .decl_instance_extern_empty_func = .{
5146 .tag = .subprogram,
5147 .attrs = decl_instance_attrs ++ .{
5148 .{ .linkage_name, .strp },
5149 .{ .type, .ref_addr },
5150 .{ .low_pc, .addr },
5151 .{ .external, .flag_present },
5152 .{ .noreturn, .flag },
5153 },
5154 },
5155 .decl_instance_extern_func = .{
5156 .tag = .subprogram,
5157 .children = true,
5158 .attrs = decl_instance_attrs ++ .{
5159 .{ .linkage_name, .strp },
5160 .{ .type, .ref_addr },
5161 .{ .low_pc, .addr },
5162 .{ .external, .flag_present },
5163 .{ .noreturn, .flag },
5164 },
5165 },
5166 .compile_unit = .{5328 .compile_unit = .{
5167 .tag = .compile_unit,5329 .tag = .compile_unit,
5168 .children = true,5330 .children = true,
...@@ -5375,22 +5537,10 @@ pub const AbbrevCode = enum {...@@ -5375,22 +5537,10 @@ pub const AbbrevCode = enum {
5375 .{ .type, .ref_addr },5537 .{ .type, .ref_addr },
5376 },5538 },
5377 },5539 },
5378 .ptr_aligned_type = .{5540 .is_aligned = .{
5379 .tag = .pointer_type,5541 .tag = .typedef,
5380 .attrs = &.{
5381 .{ .name, .strp },
5382 .{ .alignment, .udata },
5383 .{ .address_class, .data1 },
5384 .{ .type, .ref_addr },
5385 },
5386 },
5387 .ptr_aligned_sentinel_type = .{
5388 .tag = .pointer_type,
5389 .attrs = &.{5542 .attrs = &.{
5390 .{ .name, .strp },
5391 .{ .ZIG_sentinel, .block },
5392 .{ .alignment, .udata },5543 .{ .alignment, .udata },
5393 .{ .address_class, .data1 },
5394 .{ .type, .ref_addr },5544 .{ .type, .ref_addr },
5395 },5545 },
5396 },5546 },
...@@ -5594,6 +5744,7 @@ pub const AbbrevCode = enum {...@@ -5594,6 +5744,7 @@ pub const AbbrevCode = enum {
5594 .{ .linkage_name, .strp },5744 .{ .linkage_name, .strp },
5595 .{ .type, .ref_addr },5745 .{ .type, .ref_addr },
5596 .{ .location, .exprloc },5746 .{ .location, .exprloc },
5747 .{ .alignment, .udata },
5597 .{ .external, .flag_present },5748 .{ .external, .flag_present },
5598 },5749 },
5599 },5750 },
src/link/Elf2.zig+92-55
...@@ -5856,10 +5856,11 @@ fn dynsymPtr(elf: *Elf, index: u32) SymPtr {...@@ -5856,10 +5856,11 @@ fn dynsymPtr(elf: *Elf, index: u32) SymPtr {
5856}5856}
58575857
5858fn navType(elf: *const Elf, nav_resolved: InternPool.Nav.Resolved) std.elf.STT {5858fn navType(elf: *const Elf, nav_resolved: InternPool.Nav.Resolved) std.elf.STT {
5859 const any_non_single_threaded = elf.base.comp.config.any_non_single_threaded;5859 const comp = elf.base.comp;
5860 const any_non_single_threaded = comp.config.any_non_single_threaded;
5860 return if (any_non_single_threaded and nav_resolved.@"threadlocal")5861 return if (any_non_single_threaded and nav_resolved.@"threadlocal")
5861 .TLS5862 .TLS
5862 else if (elf.base.comp.zcu.?.intern_pool.isFunctionType(nav_resolved.type))5863 else if (comp.zcu.?.intern_pool.isFunctionType(nav_resolved.type))
5863 .FUNC5864 .FUNC
5864 else5865 else
5865 .OBJECT;5866 .OBJECT;
...@@ -7406,7 +7407,6 @@ fn flushFiles(elf: *Elf) Error!void {...@@ -7406,7 +7407,6 @@ fn flushFiles(elf: *Elf) Error!void {
7406 const debug_line_header_ni = unit.debug_line_header_ni.unwrap().?;7407 const debug_line_header_ni = unit.debug_line_header_ni.unwrap().?;
7407 try debug_line_header_ni.parent(&elf.mf).unwrap().?.nextMoved(gpa, &elf.mf);7408 try debug_line_header_ni.parent(&elf.mf).unwrap().?.nextMoved(gpa, &elf.mf);
7408 try debug_line_header_ni.moved(gpa, &elf.mf);7409 try debug_line_header_ni.moved(gpa, &elf.mf);
7409 try debug_line_header_ni.nextMoved(gpa, &elf.mf);
7410 var dlh_nw: MappedFile.Node.Writer = undefined;7410 var dlh_nw: MappedFile.Node.Writer = undefined;
7411 debug_line_header_ni.writer(gpa, &elf.mf, &dlh_nw);7411 debug_line_header_ni.writer(gpa, &elf.mf, &dlh_nw);
7412 defer dlh_nw.deinit();7412 defer dlh_nw.deinit();
...@@ -8632,38 +8632,77 @@ fn updateNavInner(elf: *Elf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index)...@@ -8632,38 +8632,77 @@ fn updateNavInner(elf: *Elf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index)
8632 const ip = &zcu.intern_pool;8632 const ip = &zcu.intern_pool;
86338633
8634 const nav = ip.getNav(nav_index);8634 const nav = ip.getNav(nav_index);
8635 if (ip.indexToKey(nav.resolved.?.value) == .@"extern") return;8635 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;
8636 if (Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) {8636 switch (ip.indexToKey(nav.resolved.?.value)) {
8637 const nmi = try elf.navMapIndex(zcu, nav_index);8637 .@"extern" => |@"extern"| {
8638 const ni = nmi.symbol(elf).index().ptr(elf).node.unwrap().?;8638 if (mod.strip or elf.ehdrMachine() != .X86_64) return;
8639 const si = try elf.externSymbol(.{
8640 .name = @"extern".name.toSlice(ip),
8641 .lib_name = @"extern".lib_name.toSlice(ip),
8642 .type = elf.navType(nav.resolved.?),
8643 .linkage = @"extern".linkage,
8644 .visibility = @"extern".visibility,
8645 });
8646 const dwarf_gi = try elf.dwarf.getGlobal(nav_index);
8647 const dwarf_global = dwarf_gi.get(&elf.dwarf);
8648 const debug_info_ni = dwarf_global.debug_info_ni.unwrap().?;
8649 try debug_info_ni.moved(gpa, &elf.mf);
8650 var di_nw: MappedFile.Node.Writer = undefined;
8651 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
8652 defer di_nw.deinit();
8653 elf.resetNodeRelocs(debug_info_ni);
8654 try elf.dwarf.updateExtern(pt, &di_nw, switch (elf.ehdrMachine()) {
8655 else => unreachable,
8656 .X86_64 => .x86_64,
8657 }, si, nav_index);
8658 },
8659 else => if (Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) {
8660 const nmi = try elf.navMapIndex(zcu, nav_index);
8661 const lsi = nmi.symbol(elf);
8662 const ni = lsi.index().ptr(elf).node.unwrap().?;
86398663
8640 // Ensure the NAV is marked as moved so that once we're done, `flushMoved` will eventually be8664 // Ensure the NAV is marked as moved so that once we're done, `flushMoved`
8641 // called to apply the NAV's new relocations.8665 // will eventually be called to apply the NAV's new relocations.
8642 try ni.moved(gpa, &elf.mf);8666 try ni.moved(gpa, &elf.mf);
86438667
8644 {8668 {
8645 var nw: MappedFile.Node.Writer = undefined;8669 var nw: MappedFile.Node.Writer = undefined;
8646 ni.writer(gpa, &elf.mf, &nw);8670 ni.writer(gpa, &elf.mf, &nw);
8647 defer nw.deinit();8671 defer nw.deinit();
8648 elf.resetNodeRelocs(ni);8672 elf.resetNodeRelocs(ni);
8649 codegen.generateSymbol(8673 codegen.generateSymbol(
8650 &elf.base,8674 &elf.base,
8651 pt,8675 pt,
8652 .fromInterned(nav.resolved.?.value),8676 .fromInterned(nav.resolved.?.value),
8653 &nw.interface,8677 &nw.interface,
8654 .{ .atom_index = Node.toAtom(ni) },8678 .{ .atom_index = Node.toAtom(ni) },
8655 ) catch |err| switch (err) {8679 ) catch |err| switch (err) {
8656 else => |e| return e,8680 else => |e| return e,
8657 error.WriteFailed => return nw.err.?,8681 error.WriteFailed => return nw.err.?,
8658 };8682 };
8659 switch (elf.symPtr(nmi.symbol(elf).index())) {8683 switch (elf.symPtr(nmi.symbol(elf).index())) {
8660 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),8684 inline else => |sym| elf.targetStore(&sym.size, @intCast(nw.interface.end)),
8685 }
8661 }8686 }
8662 }8687
8663 } else {8688 if (!mod.strip and elf.ehdrMachine() == .X86_64) {
8664 if (elf.ehdrMachine() != .X86_64) return;8689 const dwarf_gi = try elf.dwarf.getGlobal(nav_index);
8665 const mod = zcu.fileByIndex(nav.srcInst(ip).resolveFile(ip)).mod.?;8690 const dwarf_global = dwarf_gi.get(&elf.dwarf);
8666 if (!mod.strip) try elf.dwarf.updateComptimeGlobal(pt, nav_index);8691 const debug_info_ni = dwarf_global.debug_info_ni.unwrap().?;
8692 try debug_info_ni.moved(gpa, &elf.mf);
8693 var di_nw: MappedFile.Node.Writer = undefined;
8694 debug_info_ni.writer(gpa, &elf.mf, &di_nw);
8695 defer di_nw.deinit();
8696 elf.resetNodeRelocs(debug_info_ni);
8697 try elf.dwarf.updateGlobal(pt, &di_nw, switch (elf.ehdrMachine()) {
8698 else => unreachable,
8699 .X86_64 => .x86_64,
8700 }, Symbol.Id.local(lsi).toTypeErased(), nav_index);
8701 }
8702 } else {
8703 if (mod.strip or elf.ehdrMachine() != .X86_64) return;
8704 try elf.dwarf.updateComptimeGlobal(pt, nav_index);
8705 },
8667 }8706 }
86688707
8669 // The NAV's node is done---now generate any UAVs or lazy code/data which the NAV needs.8708 // The NAV's node is done---now generate any UAVs or lazy code/data which the NAV needs.
...@@ -8851,7 +8890,7 @@ fn updateFuncInner(...@@ -8851,7 +8890,7 @@ fn updateFuncInner(
8851 var nw: MappedFile.Node.Writer = undefined;8890 var nw: MappedFile.Node.Writer = undefined;
8852 ni.writer(gpa, &elf.mf, &nw);8891 ni.writer(gpa, &elf.mf, &nw);
8853 defer nw.deinit();8892 defer nw.deinit();
8854 var debug_output_buf: Dwarf.WipNav.Debug = undefined;8893 var debug_output_buf: Dwarf.WipFunc.Debug = undefined;
8855 const debug_output: link.File.DebugInfoOutput, const dwarf_func = debug_output: {8894 const debug_output: link.File.DebugInfoOutput, const dwarf_func = debug_output: {
8856 if (elf.ehdrMachine() != .X86_64) break :debug_output .{ .none, undefined };8895 if (elf.ehdrMachine() != .X86_64) break :debug_output .{ .none, undefined };
8857 const dwarf = &elf.dwarf;8896 const dwarf = &elf.dwarf;
...@@ -8862,8 +8901,8 @@ fn updateFuncInner(...@@ -8862,8 +8901,8 @@ fn updateFuncInner(
8862 try elf.nodes.ensureUnusedCapacity(gpa, 4);8901 try elf.nodes.ensureUnusedCapacity(gpa, 4);
8863 const dwarf_fi = try dwarf.getFunc(func.owner_nav);8902 const dwarf_fi = try dwarf.getFunc(func.owner_nav);
88648903
8865 const wip_nav = &debug_output_buf.wip_nav;8904 const wip_func = &debug_output_buf.wip_func;
8866 wip_nav.* = .{8905 wip_func.* = .{
8867 .dwarf = dwarf,8906 .dwarf = dwarf,
8868 .unit = dwarf.getUnit(mod),8907 .unit = dwarf.getUnit(mod),
8869 .func = func_index,8908 .func = func_index,
...@@ -8879,7 +8918,7 @@ fn updateFuncInner(...@@ -8879,7 +8918,7 @@ fn updateFuncInner(
8879 .fde_writer = undefined,8918 .fde_writer = undefined,
8880 .frame_func_length = undefined,8919 .frame_func_length = undefined,
8881 };8920 };
8882 const unit = wip_nav.unit.get(dwarf);8921 const unit = wip_func.unit.get(dwarf);
88838922
8884 const frame_align: Alignment = switch (elf.identClass()) {8923 const frame_align: Alignment = switch (elf.identClass()) {
8885 .NONE, _ => unreachable,8924 .NONE, _ => unreachable,
...@@ -8887,13 +8926,13 @@ fn updateFuncInner(...@@ -8887,13 +8926,13 @@ fn updateFuncInner(
8887 .@"64" => .@"8",8926 .@"64" => .@"8",
8888 };8927 };
8889 const frame_ni = unit.frame_ni.unwrap() orelse frame_ni: {8928 const frame_ni = unit.frame_ni.unwrap() orelse frame_ni: {
8890 const frame_ni = elf.addNodeAssumeCapacity(try switch (wip_nav.frame_format) {8929 const frame_ni = elf.addNodeAssumeCapacity(try switch (wip_func.frame_format) {
8891 .debug_frame => elf.shndx.debug_frame,8930 .debug_frame => elf.shndx.debug_frame,
8892 .eh_frame => elf.shndx.eh_frame,8931 .eh_frame => elf.shndx.eh_frame,
8893 }.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{8932 }.get(elf).ni.addFloatingChild(gpa, &elf.mf, .{
8894 .alignment = frame_align.max(elf.mf.flags.block_size),8933 .alignment = frame_align.max(elf.mf.flags.block_size),
8895 .enable_next_moved = true,8934 .enable_next_moved = true,
8896 }), .{ .unit_frame = wip_nav.unit });8935 }), .{ .unit_frame = wip_func.unit });
8897 unit.frame_ni = .wrap(frame_ni);8936 unit.frame_ni = .wrap(frame_ni);
8898 break :frame_ni frame_ni;8937 break :frame_ni frame_ni;
8899 };8938 };
...@@ -8904,7 +8943,7 @@ fn updateFuncInner(...@@ -8904,7 +8943,7 @@ fn updateFuncInner(
8904 .next_moved = true,8943 .next_moved = true,
8905 .enable_next_moved = true,8944 .enable_next_moved = true,
8906 }),8945 }),
8907 .{ .unit_frame_cie = wip_nav.unit },8946 .{ .unit_frame_cie = wip_func.unit },
8908 );8947 );
8909 unit.cie_ni = .wrap(cie_ni);8948 unit.cie_ni = .wrap(cie_ni);
8910 var cie_nw: MappedFile.Node.Writer = undefined;8949 var cie_nw: MappedFile.Node.Writer = undefined;
...@@ -8913,14 +8952,13 @@ fn updateFuncInner(...@@ -8913,14 +8952,13 @@ fn updateFuncInner(
8913 dwarf.genDebugFrameCie(&cie_nw.interface, switch (elf.ehdrMachine()) {8952 dwarf.genDebugFrameCie(&cie_nw.interface, switch (elf.ehdrMachine()) {
8914 else => unreachable,8953 else => unreachable,
8915 .X86_64 => .x86_64,8954 .X86_64 => .x86_64,
8916 }, wip_nav.frame_format) catch |err| switch (err) {8955 }, wip_func.frame_format) catch |err| switch (err) {
8917 error.WriteFailed => return cie_nw.err.?,8956 error.WriteFailed => return cie_nw.err.?,
8918 };8957 };
8919 }8958 }
8920 const dwarf_func = dwarf_fi.get(dwarf);8959 const dwarf_func = dwarf_fi.get(dwarf);
8921 const fde_ni = if (dwarf_func.fde_ni.unwrap()) |fde_ni| fde_ni: {8960 const fde_ni = if (dwarf_func.fde_ni.unwrap()) |fde_ni| fde_ni: {
8922 try fde_ni.moved(gpa, &elf.mf);8961 try fde_ni.moved(gpa, &elf.mf);
8923 try fde_ni.nextMoved(gpa, &elf.mf);
8924 break :fde_ni fde_ni;8962 break :fde_ni fde_ni;
8925 } else fde_ni: {8963 } else fde_ni: {
8926 const fde_ni = elf.addNodeAssumeCapacity(try frame_ni.addFloatingChild(gpa, &elf.mf, .{8964 const fde_ni = elf.addNodeAssumeCapacity(try frame_ni.addFloatingChild(gpa, &elf.mf, .{
...@@ -8932,9 +8970,9 @@ fn updateFuncInner(...@@ -8932,9 +8970,9 @@ fn updateFuncInner(
8932 dwarf_func.fde_ni = .wrap(fde_ni);8970 dwarf_func.fde_ni = .wrap(fde_ni);
8933 break :fde_ni fde_ni;8971 break :fde_ni fde_ni;
8934 };8972 };
8935 fde_ni.writer(gpa, &elf.mf, &wip_nav.fde_writer);8973 fde_ni.writer(gpa, &elf.mf, &wip_func.fde_writer);
89368974
8937 if (mod.strip) break :debug_output .{ .{ .eh_frame = wip_nav }, dwarf_func };8975 if (mod.strip) break :debug_output .{ .{ .eh_frame = wip_func }, dwarf_func };
89388976
8939 const debug = &debug_output_buf;8977 const debug = &debug_output_buf;
8940 debug.pt = pt;8978 debug.pt = pt;
...@@ -8947,7 +8985,6 @@ fn updateFuncInner(...@@ -8947,7 +8985,6 @@ fn updateFuncInner(
8947 .debug_info_ni = debug_info_ni.toOptional(),8985 .debug_info_ni = debug_info_ni.toOptional(),
8948 });8986 });
8949 try debug_info_ni.moved(gpa, &elf.mf);8987 try debug_info_ni.moved(gpa, &elf.mf);
8950 try debug_info_ni.nextMoved(gpa, &elf.mf);
8951 debug_info_ni.writer(gpa, &elf.mf, &debug.info_writer);8988 debug_info_ni.writer(gpa, &elf.mf, &debug.info_writer);
89528989
8953 const debug_line_ni = dwarf_func.debug_line_ni.unwrap() orelse debug_line_ni: {8990 const debug_line_ni = dwarf_func.debug_line_ni.unwrap() orelse debug_line_ni: {
...@@ -8973,17 +9010,17 @@ fn updateFuncInner(...@@ -8973,17 +9010,17 @@ fn updateFuncInner(
8973 };9010 };
8974 switch (debug_output) {9011 switch (debug_output) {
8975 .dwarf => unreachable,9012 .dwarf => unreachable,
8976 .eh_frame => |wip_nav| {9013 .eh_frame => |wip_func| {
8977 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);9014 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);
8978 try wip_nav.genDebugFrameHeader();9015 try wip_func.genDebugFrameHeader();
8979 },9016 },
8980 .dwarf2 => |debug| {9017 .dwarf2 => |debug| {
8981 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);9018 elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?);
8982 try debug.wip_nav.genDebugFrameHeader();9019 try debug.wip_func.genDebugFrameHeader();
8983 elf.resetNodeRelocs(dwarf_func.debug_line_ni.unwrap().?);9020 elf.resetNodeRelocs(dwarf_func.debug_line_ni.unwrap().?);
8984 try debug.startDebugLine();9021 try debug.startDebugLine();
8985 elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?);9022 elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?);
8986 try debug.startFuncDebugInfo();9023 try debug.startDebugInfo();
8987 },9024 },
8988 .none => {},9025 .none => {},
8989 }9026 }
...@@ -9006,25 +9043,25 @@ fn updateFuncInner(...@@ -9006,25 +9043,25 @@ fn updateFuncInner(
9006 }9043 }
9007 switch (debug_output) {9044 switch (debug_output) {
9008 .dwarf => unreachable,9045 .dwarf => unreachable,
9009 .eh_frame => |wip_nav| wip_nav.finishDebugFrameFde(func_length),9046 .eh_frame => |wip_func| wip_func.finishDebugFrameFde(func_length),
9010 .dwarf2 => |debug| {9047 .dwarf2 => |debug| {
9011 try debug.finishFunc(func_length);9048 try debug.finish(func_length);
9012 const unit = debug.wip_nav.unit.get(debug.wip_nav.dwarf);9049 const unit = debug.wip_func.unit.get(debug.wip_func.dwarf);
9013 {9050 {
9014 var dr_nw: MappedFile.Node.Writer = undefined;9051 var dr_nw: MappedFile.Node.Writer = undefined;
9015 unit.debug_rnglists_ni.unwrap().?.writer(gpa, &elf.mf, &dr_nw);9052 unit.debug_rnglists_ni.unwrap().?.writer(gpa, &elf.mf, &dr_nw);
9016 defer dr_nw.deinit();9053 defer dr_nw.deinit();
9017 const first_symbol_reloc = elf.symbol_relocs.items.len;9054 const first_symbol_reloc = elf.symbol_relocs.items.len;
9018 debug.wip_nav.dwarf.genDebugRnglists(9055 debug.wip_func.dwarf.genDebugRnglists(
9019 unit,9056 unit,
9020 &dr_nw,9057 &dr_nw,
9021 debug.wip_nav.func_si,9058 debug.wip_func.func_si,
9022 func_length,9059 func_length,
9023 ) catch |err| switch (err) {9060 ) catch |err| switch (err) {
9024 else => |e| return e,9061 else => |e| return e,
9025 error.WriteFailed => return dr_nw.err.?,9062 error.WriteFailed => return dr_nw.err.?,
9026 };9063 };
9027 const symbol_relocs = &elf.dwarf_units[@backingInt(debug.wip_nav.unit)]9064 const symbol_relocs = &elf.dwarf_units[@backingInt(debug.wip_func.unit)]
9028 .debug_rnglists_symbol_relocs;9065 .debug_rnglists_symbol_relocs;
9029 try symbol_relocs.ensureUnusedCapacity(gpa, elf.symbol_relocs.items.len -9066 try symbol_relocs.ensureUnusedCapacity(gpa, elf.symbol_relocs.items.len -
9030 first_symbol_reloc);9067 first_symbol_reloc);
...@@ -9034,7 +9071,7 @@ fn updateFuncInner(...@@ -9034,7 +9071,7 @@ fn updateFuncInner(
9034 {},9071 {},
9035 );9072 );
9036 }9073 }
9037 debug.wip_nav.finishDebugFrameFde(func_length);9074 debug.wip_func.finishDebugFrameFde(func_length);
9038 if (func.analysisUnordered(ip).inferred_error_set) {9075 if (func.analysisUnordered(ip).inferred_error_set) {
9039 const ies = ip.getIfExists(.{ .inferred_error_set_type = func_index }).?;9076 const ies = ip.getIfExists(.{ .inferred_error_set_type = func_index }).?;
9040 if (elf.dwarf.const_pool.getIfExists(ies)) |cpi|9077 if (elf.dwarf.const_pool.getIfExists(ies)) |cpi|
test/src/Debugger.zig+1-1
...@@ -868,7 +868,7 @@ pub fn addTests(db: *Debugger) void {...@@ -868,7 +868,7 @@ pub fn addTests(db: *Debugger) void {
868 \\(lldb) breakpoint delete --force 1868 \\(lldb) breakpoint delete --force 1
869 \\1 breakpoints deleted; 0 breakpoint locations disabled.869 \\1 breakpoints deleted; 0 breakpoint locations disabled.
870 },870 },
871 .{ .skip_new_linker = true },871 .{},
872 );872 );
873 db.addLldbTest(873 db.addLldbTest(
874 "if_blocks",874 "if_blocks",