| ... | @@ -21,8 +21,9 @@ pub const UpdateError = | ... | @@ -21,8 +21,9 @@ pub const UpdateError = |
| 21 | std.fs.File.OpenError || | 21 | std.fs.File.OpenError || |
| 22 | std.fs.File.SetEndPosError || | 22 | std.fs.File.SetEndPosError || |
| 23 | std.fs.File.CopyRangeError || | 23 | std.fs.File.CopyRangeError || |
| | 24 | std.fs.File.PReadError || |
| 24 | std.fs.File.PWriteError || | 25 | std.fs.File.PWriteError || |
| 25 | error{ Overflow, Underflow, UnexpectedEndOfFile }; | 26 | error{ EndOfStream, Overflow, Underflow, UnexpectedEndOfFile }; |
| 26 | | 27 | |
| 27 | pub const FlushError = | 28 | pub const FlushError = |
| 28 | UpdateError || | 29 | UpdateError || |
| ... | @@ -253,10 +254,8 @@ const Section = struct { | ... | @@ -253,10 +254,8 @@ const Section = struct { |
| 253 | .trailer_len = trailer_len, | 254 | .trailer_len = trailer_len, |
| 254 | .len = header_len + trailer_len, | 255 | .len = header_len + trailer_len, |
| 255 | .entries = .{}, | 256 | .entries = .{}, |
| 256 | .cross_entry_relocs = .{}, | | |
| 257 | .cross_unit_relocs = .{}, | 257 | .cross_unit_relocs = .{}, |
| 258 | .cross_section_relocs = .{}, | 258 | .cross_section_relocs = .{}, |
| 259 | .external_relocs = .{}, | | |
| 260 | }; | 259 | }; |
| 261 | if (sec.last.unwrap()) |last_unit| { | 260 | if (sec.last.unwrap()) |last_unit| { |
| 262 | const last_unit_ptr = sec.getUnit(last_unit); | 261 | const last_unit_ptr = sec.getUnit(last_unit); |
| ... | @@ -358,10 +357,8 @@ const Unit = struct { | ... | @@ -358,10 +357,8 @@ const Unit = struct { |
| 358 | /// data length in bytes | 357 | /// data length in bytes |
| 359 | len: u32, | 358 | len: u32, |
| 360 | entries: std.ArrayListUnmanaged(Entry), | 359 | entries: std.ArrayListUnmanaged(Entry), |
| 361 | cross_entry_relocs: std.ArrayListUnmanaged(CrossEntryReloc), | | |
| 362 | cross_unit_relocs: std.ArrayListUnmanaged(CrossUnitReloc), | 360 | cross_unit_relocs: std.ArrayListUnmanaged(CrossUnitReloc), |
| 363 | cross_section_relocs: std.ArrayListUnmanaged(CrossSectionReloc), | 361 | cross_section_relocs: std.ArrayListUnmanaged(CrossSectionReloc), |
| 364 | external_relocs: std.ArrayListUnmanaged(ExternalReloc), | | |
| 365 | | 362 | |
| 366 | const Index = enum(u32) { | 363 | const Index = enum(u32) { |
| 367 | main, | 364 | main, |
| ... | @@ -381,12 +378,16 @@ const Unit = struct { | ... | @@ -381,12 +378,16 @@ const Unit = struct { |
| 381 | } | 378 | } |
| 382 | }; | 379 | }; |
| 383 | | 380 | |
| | 381 | fn clear(unit: *Unit) void { |
| | 382 | unit.cross_unit_relocs.clearRetainingCapacity(); |
| | 383 | unit.cross_section_relocs.clearRetainingCapacity(); |
| | 384 | } |
| | 385 | |
| 384 | fn deinit(unit: *Unit, gpa: std.mem.Allocator) void { | 386 | fn deinit(unit: *Unit, gpa: std.mem.Allocator) void { |
| | 387 | for (unit.entries.items) |*entry| entry.deinit(gpa); |
| 385 | unit.entries.deinit(gpa); | 388 | unit.entries.deinit(gpa); |
| 386 | unit.cross_entry_relocs.deinit(gpa); | | |
| 387 | unit.cross_unit_relocs.deinit(gpa); | 389 | unit.cross_unit_relocs.deinit(gpa); |
| 388 | unit.cross_section_relocs.deinit(gpa); | 390 | unit.cross_section_relocs.deinit(gpa); |
| 389 | unit.external_relocs.deinit(gpa); | | |
| 390 | unit.* = undefined; | 391 | unit.* = undefined; |
| 391 | } | 392 | } |
| 392 | | 393 | |
| ... | @@ -398,6 +399,10 @@ const Unit = struct { | ... | @@ -398,6 +399,10 @@ const Unit = struct { |
| 398 | .next = .none, | 399 | .next = .none, |
| 399 | .off = 0, | 400 | .off = 0, |
| 400 | .len = 0, | 401 | .len = 0, |
| | 402 | .cross_entry_relocs = .{}, |
| | 403 | .cross_unit_relocs = .{}, |
| | 404 | .cross_section_relocs = .{}, |
| | 405 | .external_relocs = .{}, |
| 401 | }; | 406 | }; |
| 402 | if (unit.last.unwrap()) |last_entry| { | 407 | if (unit.last.unwrap()) |last_entry| { |
| 403 | const last_entry_ptr = unit.getEntry(last_entry); | 408 | const last_entry_ptr = unit.getEntry(last_entry); |
| ... | @@ -451,6 +456,14 @@ const Unit = struct { | ... | @@ -451,6 +456,14 @@ const Unit = struct { |
| 451 | unit_ptr.len = len; | 456 | unit_ptr.len = len; |
| 452 | } | 457 | } |
| 453 | | 458 | |
| | 459 | fn trim(unit: *Unit) void { |
| | 460 | const len = unit.getEntry(unit.first.unwrap() orelse return).off; |
| | 461 | if (len == 0) return; |
| | 462 | for (unit.entries.items) |*entry| entry.off -= len; |
| | 463 | unit.off += len; |
| | 464 | unit.len -= len; |
| | 465 | } |
| | 466 | |
| 454 | fn move(unit: *Unit, sec: *Section, dwarf: *Dwarf, new_off: u32) UpdateError!void { | 467 | fn move(unit: *Unit, sec: *Section, dwarf: *Dwarf, new_off: u32) UpdateError!void { |
| 455 | if (unit.off == new_off) return; | 468 | if (unit.off == new_off) return; |
| 456 | if (try dwarf.getFile().?.copyRangeAll( | 469 | if (try dwarf.getFile().?.copyRangeAll( |
| ... | @@ -463,6 +476,7 @@ const Unit = struct { | ... | @@ -463,6 +476,7 @@ const Unit = struct { |
| 463 | } | 476 | } |
| 464 | | 477 | |
| 465 | fn resizeHeader(unit: *Unit, sec: *Section, dwarf: *Dwarf, len: u32) UpdateError!void { | 478 | fn resizeHeader(unit: *Unit, sec: *Section, dwarf: *Dwarf, len: u32) UpdateError!void { |
| | 479 | unit.trim(); |
| 466 | if (unit.header_len == len) return; | 480 | if (unit.header_len == len) return; |
| 467 | const available_len = if (unit.prev.unwrap()) |prev_unit| prev_excess: { | 481 | const available_len = if (unit.prev.unwrap()) |prev_unit| prev_excess: { |
| 468 | const prev_unit_ptr = sec.getUnit(prev_unit); | 482 | const prev_unit_ptr = sec.getUnit(prev_unit); |
| ... | @@ -535,23 +549,11 @@ const Unit = struct { | ... | @@ -535,23 +549,11 @@ const Unit = struct { |
| 535 | } | 549 | } |
| 536 | | 550 | |
| 537 | fn resolveRelocs(unit: *Unit, sec: *Section, dwarf: *Dwarf) RelocError!void { | 551 | fn resolveRelocs(unit: *Unit, sec: *Section, dwarf: *Dwarf) RelocError!void { |
| 538 | for (unit.cross_entry_relocs.items) |reloc| { | 552 | const unit_off = sec.off + unit.off; |
| 539 | try dwarf.resolveReloc( | | |
| 540 | sec.off + unit.off + (if (reloc.source_entry.unwrap()) |source_entry| | | |
| 541 | unit.header_len + unit.getEntry(source_entry).off | | |
| 542 | else | | |
| 543 | 0) + reloc.source_off, | | |
| 544 | unit.off + unit.header_len + unit.getEntry(reloc.target_entry).assertNonEmpty(unit, sec, dwarf).off + reloc.target_off, | | |
| 545 | dwarf.sectionOffsetBytes(), | | |
| 546 | ); | | |
| 547 | } | | |
| 548 | for (unit.cross_unit_relocs.items) |reloc| { | 553 | for (unit.cross_unit_relocs.items) |reloc| { |
| 549 | const target_unit = sec.getUnit(reloc.target_unit); | 554 | const target_unit = sec.getUnit(reloc.target_unit); |
| 550 | try dwarf.resolveReloc( | 555 | try dwarf.resolveReloc( |
| 551 | sec.off + unit.off + (if (reloc.source_entry.unwrap()) |source_entry| | 556 | unit_off + reloc.source_off, |
| 552 | unit.header_len + unit.getEntry(source_entry).off | | |
| 553 | else | | |
| 554 | 0) + reloc.source_off, | | |
| 555 | target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry| | 557 | target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry| |
| 556 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off | 558 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off |
| 557 | else | 559 | else |
| ... | @@ -565,10 +567,7 @@ const Unit = struct { | ... | @@ -565,10 +567,7 @@ const Unit = struct { |
| 565 | }; | 567 | }; |
| 566 | const target_unit = target_sec.getUnit(reloc.target_unit); | 568 | const target_unit = target_sec.getUnit(reloc.target_unit); |
| 567 | try dwarf.resolveReloc( | 569 | try dwarf.resolveReloc( |
| 568 | sec.off + unit.off + (if (reloc.source_entry.unwrap()) |source_entry| | 570 | unit_off + reloc.source_off, |
| 569 | unit.header_len + unit.getEntry(source_entry).off | | |
| 570 | else | | |
| 571 | 0) + reloc.source_off, | | |
| 572 | target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry| | 571 | target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry| |
| 573 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off | 572 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off |
| 574 | else | 573 | else |
| ... | @@ -576,57 +575,8 @@ const Unit = struct { | ... | @@ -576,57 +575,8 @@ const Unit = struct { |
| 576 | dwarf.sectionOffsetBytes(), | 575 | dwarf.sectionOffsetBytes(), |
| 577 | ); | 576 | ); |
| 578 | } | 577 | } |
| 579 | if (dwarf.bin_file.cast(.elf)) |elf_file| { | 578 | for (unit.entries.items) |*entry| try entry.resolveRelocs(unit, sec, dwarf); |
| 580 | const zo = elf_file.zigObjectPtr().?; | | |
| 581 | for (unit.external_relocs.items) |reloc| { | | |
| 582 | const symbol = zo.symbol(reloc.target_sym); | | |
| 583 | try dwarf.resolveReloc( | | |
| 584 | sec.off + unit.off + unit.header_len + unit.getEntry(reloc.source_entry).off + reloc.source_off, | | |
| 585 | @bitCast(symbol.address(.{}, elf_file) + @as(i64, @intCast(reloc.target_off)) - | | |
| 586 | if (symbol.flags.is_tls) elf_file.dtpAddress() else 0), | | |
| 587 | @intFromEnum(dwarf.address_size), | | |
| 588 | ); | | |
| 589 | } | | |
| 590 | } else if (dwarf.bin_file.cast(.macho)) |macho_file| { | | |
| 591 | const zo = macho_file.getZigObject().?; | | |
| 592 | for (unit.external_relocs.items) |reloc| { | | |
| 593 | const ref = zo.getSymbolRef(reloc.target_sym, macho_file); | | |
| 594 | try dwarf.resolveReloc( | | |
| 595 | sec.off + unit.off + unit.header_len + unit.getEntry(reloc.source_entry).off + reloc.source_off, | | |
| 596 | ref.getSymbol(macho_file).?.getAddress(.{}, macho_file), | | |
| 597 | @intFromEnum(dwarf.address_size), | | |
| 598 | ); | | |
| 599 | } | | |
| 600 | } | | |
| 601 | } | 579 | } |
| 602 | | | |
| 603 | const CrossEntryReloc = struct { | | |
| 604 | source_entry: Entry.Index.Optional = .none, | | |
| 605 | source_off: u32 = 0, | | |
| 606 | target_entry: Entry.Index, | | |
| 607 | target_off: u32 = 0, | | |
| 608 | }; | | |
| 609 | const CrossUnitReloc = struct { | | |
| 610 | source_entry: Entry.Index.Optional = .none, | | |
| 611 | source_off: u32 = 0, | | |
| 612 | target_unit: Unit.Index, | | |
| 613 | target_entry: Entry.Index.Optional = .none, | | |
| 614 | target_off: u32 = 0, | | |
| 615 | }; | | |
| 616 | const CrossSectionReloc = struct { | | |
| 617 | source_entry: Entry.Index.Optional = .none, | | |
| 618 | source_off: u32 = 0, | | |
| 619 | target_sec: Section.Index, | | |
| 620 | target_unit: Unit.Index, | | |
| 621 | target_entry: Entry.Index.Optional = .none, | | |
| 622 | target_off: u32 = 0, | | |
| 623 | }; | | |
| 624 | const ExternalReloc = struct { | | |
| 625 | source_entry: Entry.Index, | | |
| 626 | source_off: u32 = 0, | | |
| 627 | target_sym: u32, | | |
| 628 | target_off: u64 = 0, | | |
| 629 | }; | | |
| 630 | }; | 580 | }; |
| 631 | | 581 | |
| 632 | /// An indivisible entry within a `Unit` containing section-specific data. | 582 | /// An indivisible entry within a `Unit` containing section-specific data. |
| ... | @@ -637,6 +587,25 @@ const Entry = struct { | ... | @@ -637,6 +587,25 @@ const Entry = struct { |
| 637 | off: u32, | 587 | off: u32, |
| 638 | /// data length in bytes | 588 | /// data length in bytes |
| 639 | len: u32, | 589 | len: u32, |
| | 590 | cross_entry_relocs: std.ArrayListUnmanaged(CrossEntryReloc), |
| | 591 | cross_unit_relocs: std.ArrayListUnmanaged(CrossUnitReloc), |
| | 592 | cross_section_relocs: std.ArrayListUnmanaged(CrossSectionReloc), |
| | 593 | external_relocs: std.ArrayListUnmanaged(ExternalReloc), |
| | 594 | |
| | 595 | fn clear(entry: *Entry) void { |
| | 596 | entry.cross_entry_relocs.clearRetainingCapacity(); |
| | 597 | entry.cross_unit_relocs.clearRetainingCapacity(); |
| | 598 | entry.cross_section_relocs.clearRetainingCapacity(); |
| | 599 | entry.external_relocs.clearRetainingCapacity(); |
| | 600 | } |
| | 601 | |
| | 602 | fn deinit(entry: *Entry, gpa: std.mem.Allocator) void { |
| | 603 | entry.cross_entry_relocs.deinit(gpa); |
| | 604 | entry.cross_unit_relocs.deinit(gpa); |
| | 605 | entry.cross_section_relocs.deinit(gpa); |
| | 606 | entry.external_relocs.deinit(gpa); |
| | 607 | entry.* = undefined; |
| | 608 | } |
| 640 | | 609 | |
| 641 | const Index = enum(u32) { | 610 | const Index = enum(u32) { |
| 642 | _, | 611 | _, |
| ... | @@ -803,6 +772,88 @@ const Entry = struct { | ... | @@ -803,6 +772,88 @@ const Entry = struct { |
| 803 | } | 772 | } |
| 804 | @panic("missing dwarf relocation target"); | 773 | @panic("missing dwarf relocation target"); |
| 805 | } | 774 | } |
| | 775 | |
| | 776 | fn resolveRelocs(entry: *Entry, unit: *Unit, sec: *Section, dwarf: *Dwarf) RelocError!void { |
| | 777 | const entry_off = sec.off + unit.off + unit.header_len + entry.off; |
| | 778 | for (entry.cross_entry_relocs.items) |reloc| { |
| | 779 | try dwarf.resolveReloc( |
| | 780 | entry_off + reloc.source_off, |
| | 781 | unit.off + unit.header_len + unit.getEntry(reloc.target_entry).assertNonEmpty(unit, sec, dwarf).off + reloc.target_off, |
| | 782 | dwarf.sectionOffsetBytes(), |
| | 783 | ); |
| | 784 | } |
| | 785 | for (entry.cross_unit_relocs.items) |reloc| { |
| | 786 | const target_unit = sec.getUnit(reloc.target_unit); |
| | 787 | try dwarf.resolveReloc( |
| | 788 | entry_off + reloc.source_off, |
| | 789 | target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry| |
| | 790 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off |
| | 791 | else |
| | 792 | 0) + reloc.target_off, |
| | 793 | dwarf.sectionOffsetBytes(), |
| | 794 | ); |
| | 795 | } |
| | 796 | for (entry.cross_section_relocs.items) |reloc| { |
| | 797 | const target_sec = switch (reloc.target_sec) { |
| | 798 | inline else => |target_sec| &@field(dwarf, @tagName(target_sec)).section, |
| | 799 | }; |
| | 800 | const target_unit = target_sec.getUnit(reloc.target_unit); |
| | 801 | try dwarf.resolveReloc( |
| | 802 | entry_off + reloc.source_off, |
| | 803 | target_unit.off + (if (reloc.target_entry.unwrap()) |target_entry| |
| | 804 | target_unit.header_len + target_unit.getEntry(target_entry).assertNonEmpty(unit, sec, dwarf).off |
| | 805 | else |
| | 806 | 0) + reloc.target_off, |
| | 807 | dwarf.sectionOffsetBytes(), |
| | 808 | ); |
| | 809 | } |
| | 810 | if (dwarf.bin_file.cast(.elf)) |elf_file| { |
| | 811 | const zo = elf_file.zigObjectPtr().?; |
| | 812 | for (entry.external_relocs.items) |reloc| { |
| | 813 | const symbol = zo.symbol(reloc.target_sym); |
| | 814 | try dwarf.resolveReloc( |
| | 815 | entry_off + reloc.source_off, |
| | 816 | @bitCast(symbol.address(.{}, elf_file) + @as(i64, @intCast(reloc.target_off)) - |
| | 817 | if (symbol.flags.is_tls) elf_file.dtpAddress() else 0), |
| | 818 | @intFromEnum(dwarf.address_size), |
| | 819 | ); |
| | 820 | } |
| | 821 | } else if (dwarf.bin_file.cast(.macho)) |macho_file| { |
| | 822 | const zo = macho_file.getZigObject().?; |
| | 823 | for (entry.external_relocs.items) |reloc| { |
| | 824 | const ref = zo.getSymbolRef(reloc.target_sym, macho_file); |
| | 825 | try dwarf.resolveReloc( |
| | 826 | entry_off + reloc.source_off, |
| | 827 | ref.getSymbol(macho_file).?.getAddress(.{}, macho_file), |
| | 828 | @intFromEnum(dwarf.address_size), |
| | 829 | ); |
| | 830 | } |
| | 831 | } |
| | 832 | } |
| | 833 | }; |
| | 834 | |
| | 835 | const CrossEntryReloc = struct { |
| | 836 | source_off: u32 = 0, |
| | 837 | target_entry: Entry.Index, |
| | 838 | target_off: u32 = 0, |
| | 839 | }; |
| | 840 | const CrossUnitReloc = struct { |
| | 841 | source_off: u32 = 0, |
| | 842 | target_unit: Unit.Index, |
| | 843 | target_entry: Entry.Index.Optional = .none, |
| | 844 | target_off: u32 = 0, |
| | 845 | }; |
| | 846 | const CrossSectionReloc = struct { |
| | 847 | source_off: u32 = 0, |
| | 848 | target_sec: Section.Index, |
| | 849 | target_unit: Unit.Index, |
| | 850 | target_entry: Entry.Index.Optional = .none, |
| | 851 | target_off: u32 = 0, |
| | 852 | }; |
| | 853 | const ExternalReloc = struct { |
| | 854 | source_off: u32 = 0, |
| | 855 | target_sym: u32, |
| | 856 | target_off: u64 = 0, |
| 806 | }; | 857 | }; |
| 807 | | 858 | |
| 808 | pub const Loc = union(enum) { | 859 | pub const Loc = union(enum) { |
| ... | @@ -1087,14 +1138,13 @@ pub const WipNav = struct { | ... | @@ -1087,14 +1138,13 @@ pub const WipNav = struct { |
| 1087 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 1138 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1088 | try wip_nav.inlined_funcs_high_reloc.ensureUnusedCapacity(dwarf.gpa, 1); | 1139 | try wip_nav.inlined_funcs_high_reloc.ensureUnusedCapacity(dwarf.gpa, 1); |
| 1089 | | 1140 | |
| 1090 | const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).external_relocs; | | |
| 1091 | try external_relocs.ensureUnusedCapacity(dwarf.gpa, 2); | | |
| 1092 | try uleb128(diw, @intFromEnum(AbbrevCode.inlined_func)); | 1141 | try uleb128(diw, @intFromEnum(AbbrevCode.inlined_func)); |
| 1093 | try wip_nav.refNav(zcu.funcInfo(func).owner_nav); | 1142 | try wip_nav.refNav(zcu.funcInfo(func).owner_nav); |
| 1094 | try uleb128(diw, zcu.navSrcLine(zcu.funcInfo(wip_nav.func).owner_nav) + line + 1); | 1143 | try uleb128(diw, zcu.navSrcLine(zcu.funcInfo(wip_nav.func).owner_nav) + line + 1); |
| 1095 | try uleb128(diw, column); | 1144 | try uleb128(diw, column + 1); |
| | 1145 | const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| | 1146 | try external_relocs.ensureUnusedCapacity(dwarf.gpa, 2); |
| 1096 | external_relocs.appendAssumeCapacity(.{ | 1147 | external_relocs.appendAssumeCapacity(.{ |
| 1097 | .source_entry = wip_nav.entry, | | |
| 1098 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1148 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1099 | .target_sym = wip_nav.func_sym_index, | 1149 | .target_sym = wip_nav.func_sym_index, |
| 1100 | .target_off = code_off, | 1150 | .target_off = code_off, |
| ... | @@ -1102,7 +1152,6 @@ pub const WipNav = struct { | ... | @@ -1102,7 +1152,6 @@ pub const WipNav = struct { |
| 1102 | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); | 1152 | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 1103 | wip_nav.inlined_funcs_high_reloc.appendAssumeCapacity(@intCast(external_relocs.items.len)); | 1153 | wip_nav.inlined_funcs_high_reloc.appendAssumeCapacity(@intCast(external_relocs.items.len)); |
| 1104 | external_relocs.appendAssumeCapacity(.{ | 1154 | external_relocs.appendAssumeCapacity(.{ |
| 1105 | .source_entry = wip_nav.entry, | | |
| 1106 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1155 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1107 | .target_sym = wip_nav.func_sym_index, | 1156 | .target_sym = wip_nav.func_sym_index, |
| 1108 | .target_off = undefined, | 1157 | .target_off = undefined, |
| ... | @@ -1112,7 +1161,7 @@ pub const WipNav = struct { | ... | @@ -1112,7 +1161,7 @@ pub const WipNav = struct { |
| 1112 | } | 1161 | } |
| 1113 | | 1162 | |
| 1114 | pub fn leaveInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64) UpdateError!void { | 1163 | pub fn leaveInlineFunc(wip_nav: *WipNav, func: InternPool.Index, code_off: u64) UpdateError!void { |
| 1115 | const external_relocs = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).external_relocs; | 1164 | const external_relocs = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| 1116 | external_relocs.items[wip_nav.inlined_funcs_high_reloc.pop()].target_off = code_off; | 1165 | external_relocs.items[wip_nav.inlined_funcs_high_reloc.pop()].target_off = code_off; |
| 1117 | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null)); | 1166 | try uleb128(wip_nav.debug_info.writer(wip_nav.dwarf.gpa), @intFromEnum(AbbrevCode.null)); |
| 1118 | try wip_nav.setInlineFunc(func); | 1167 | try wip_nav.setInlineFunc(func); |
| ... | @@ -1137,8 +1186,7 @@ pub const WipNav = struct { | ... | @@ -1137,8 +1186,7 @@ pub const WipNav = struct { |
| 1137 | try dlw.writeByte(DW.LNS.extended_op); | 1186 | try dlw.writeByte(DW.LNS.extended_op); |
| 1138 | try uleb128(dlw, 1 + dwarf.sectionOffsetBytes()); | 1187 | try uleb128(dlw, 1 + dwarf.sectionOffsetBytes()); |
| 1139 | try dlw.writeByte(DW.LNE.ZIG_set_decl); | 1188 | try dlw.writeByte(DW.LNE.ZIG_set_decl); |
| 1140 | try dwarf.debug_line.section.getUnit(wip_nav.unit).cross_section_relocs.append(dwarf.gpa, .{ | 1189 | try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_section_relocs.append(dwarf.gpa, .{ |
| 1141 | .source_entry = wip_nav.entry.toOptional(), | | |
| 1142 | .source_off = @intCast(wip_nav.debug_line.items.len), | 1190 | .source_off = @intCast(wip_nav.debug_line.items.len), |
| 1143 | .target_sec = .debug_info, | 1191 | .target_sec = .debug_info, |
| 1144 | .target_unit = new_unit, | 1192 | .target_unit = new_unit, |
| ... | @@ -1174,9 +1222,9 @@ pub const WipNav = struct { | ... | @@ -1174,9 +1222,9 @@ pub const WipNav = struct { |
| 1174 | fn infoSectionOffset(wip_nav: *WipNav, sec: Section.Index, unit: Unit.Index, entry: Entry.Index, off: u32) UpdateError!void { | 1222 | fn infoSectionOffset(wip_nav: *WipNav, sec: Section.Index, unit: Unit.Index, entry: Entry.Index, off: u32) UpdateError!void { |
| 1175 | const dwarf = wip_nav.dwarf; | 1223 | const dwarf = wip_nav.dwarf; |
| 1176 | const gpa = dwarf.gpa; | 1224 | const gpa = dwarf.gpa; |
| | 1225 | const entry_ptr = dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry); |
| 1177 | if (sec != .debug_info) { | 1226 | if (sec != .debug_info) { |
| 1178 | try dwarf.debug_info.section.getUnit(wip_nav.unit).cross_section_relocs.append(gpa, .{ | 1227 | try entry_ptr.cross_section_relocs.append(gpa, .{ |
| 1179 | .source_entry = wip_nav.entry.toOptional(), | | |
| 1180 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1228 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1181 | .target_sec = sec, | 1229 | .target_sec = sec, |
| 1182 | .target_unit = unit, | 1230 | .target_unit = unit, |
| ... | @@ -1184,16 +1232,14 @@ pub const WipNav = struct { | ... | @@ -1184,16 +1232,14 @@ pub const WipNav = struct { |
| 1184 | .target_off = off, | 1232 | .target_off = off, |
| 1185 | }); | 1233 | }); |
| 1186 | } else if (unit != wip_nav.unit) { | 1234 | } else if (unit != wip_nav.unit) { |
| 1187 | try dwarf.debug_info.section.getUnit(wip_nav.unit).cross_unit_relocs.append(gpa, .{ | 1235 | try entry_ptr.cross_unit_relocs.append(gpa, .{ |
| 1188 | .source_entry = wip_nav.entry.toOptional(), | | |
| 1189 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1236 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1190 | .target_unit = unit, | 1237 | .target_unit = unit, |
| 1191 | .target_entry = entry.toOptional(), | 1238 | .target_entry = entry.toOptional(), |
| 1192 | .target_off = off, | 1239 | .target_off = off, |
| 1193 | }); | 1240 | }); |
| 1194 | } else { | 1241 | } else { |
| 1195 | try dwarf.debug_info.section.getUnit(wip_nav.unit).cross_entry_relocs.append(gpa, .{ | 1242 | try entry_ptr.cross_entry_relocs.append(gpa, .{ |
| 1196 | .source_entry = wip_nav.entry.toOptional(), | | |
| 1197 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1243 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1198 | .target_entry = entry, | 1244 | .target_entry = entry, |
| 1199 | .target_off = off, | 1245 | .target_off = off, |
| ... | @@ -1208,8 +1254,7 @@ pub const WipNav = struct { | ... | @@ -1208,8 +1254,7 @@ pub const WipNav = struct { |
| 1208 | | 1254 | |
| 1209 | fn addrSym(wip_nav: *WipNav, sym_index: u32) UpdateError!void { | 1255 | fn addrSym(wip_nav: *WipNav, sym_index: u32) UpdateError!void { |
| 1210 | const dwarf = wip_nav.dwarf; | 1256 | const dwarf = wip_nav.dwarf; |
| 1211 | try dwarf.debug_info.section.getUnit(wip_nav.unit).external_relocs.append(dwarf.gpa, .{ | 1257 | try dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.append(dwarf.gpa, .{ |
| 1212 | .source_entry = wip_nav.entry, | | |
| 1213 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1258 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1214 | .target_sym = sym_index, | 1259 | .target_sym = sym_index, |
| 1215 | }); | 1260 | }); |
| ... | @@ -1269,10 +1314,9 @@ pub const WipNav = struct { | ... | @@ -1269,10 +1314,9 @@ pub const WipNav = struct { |
| 1269 | | 1314 | |
| 1270 | fn refForward(wip_nav: *WipNav) std.mem.Allocator.Error!u32 { | 1315 | fn refForward(wip_nav: *WipNav) std.mem.Allocator.Error!u32 { |
| 1271 | const dwarf = wip_nav.dwarf; | 1316 | const dwarf = wip_nav.dwarf; |
| 1272 | const cross_entry_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).cross_entry_relocs; | 1317 | const cross_entry_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_entry_relocs; |
| 1273 | const reloc_index: u32 = @intCast(cross_entry_relocs.items.len); | 1318 | const reloc_index: u32 = @intCast(cross_entry_relocs.items.len); |
| 1274 | try cross_entry_relocs.append(dwarf.gpa, .{ | 1319 | try cross_entry_relocs.append(dwarf.gpa, .{ |
| 1275 | .source_entry = wip_nav.entry.toOptional(), | | |
| 1276 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1320 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1277 | .target_entry = undefined, | 1321 | .target_entry = undefined, |
| 1278 | .target_off = undefined, | 1322 | .target_off = undefined, |
| ... | @@ -1282,7 +1326,7 @@ pub const WipNav = struct { | ... | @@ -1282,7 +1326,7 @@ pub const WipNav = struct { |
| 1282 | } | 1326 | } |
| 1283 | | 1327 | |
| 1284 | fn finishForward(wip_nav: *WipNav, reloc_index: u32) void { | 1328 | fn finishForward(wip_nav: *WipNav, reloc_index: u32) void { |
| 1285 | const reloc = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).cross_entry_relocs.items[reloc_index]; | 1329 | const reloc = &wip_nav.dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_entry_relocs.items[reloc_index]; |
| 1286 | reloc.target_entry = wip_nav.entry; | 1330 | reloc.target_entry = wip_nav.entry; |
| 1287 | reloc.target_off = @intCast(wip_nav.debug_info.items.len); | 1331 | reloc.target_off = @intCast(wip_nav.debug_info.items.len); |
| 1288 | } | 1332 | } |
| ... | @@ -1595,7 +1639,15 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -1595,7 +1639,15 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1595 | const unit = try dwarf.getUnit(file.mod); | 1639 | const unit = try dwarf.getUnit(file.mod); |
| 1596 | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); | 1640 | const nav_gop = try dwarf.navs.getOrPut(dwarf.gpa, nav_index); |
| 1597 | errdefer _ = dwarf.navs.pop(); | 1641 | errdefer _ = dwarf.navs.pop(); |
| 1598 | if (!nav_gop.found_existing) nav_gop.value_ptr.* = try dwarf.addCommonEntry(unit); | 1642 | if (nav_gop.found_existing) { |
| | 1643 | for ([_]*Section{ |
| | 1644 | &dwarf.debug_aranges.section, |
| | 1645 | &dwarf.debug_info.section, |
| | 1646 | &dwarf.debug_line.section, |
| | 1647 | &dwarf.debug_loclists.section, |
| | 1648 | &dwarf.debug_rnglists.section, |
| | 1649 | }) |sec| sec.getUnit(unit).getEntry(nav_gop.value_ptr.*).clear(); |
| | 1650 | } else nav_gop.value_ptr.* = try dwarf.addCommonEntry(unit); |
| 1599 | const nav_val = zcu.navValue(nav_index); | 1651 | const nav_val = zcu.navValue(nav_index); |
| 1600 | var wip_nav: WipNav = .{ | 1652 | var wip_nav: WipNav = .{ |
| 1601 | .dwarf = dwarf, | 1653 | .dwarf = dwarf, |
| ... | @@ -1759,17 +1811,15 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -1759,17 +1811,15 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1759 | try wip_nav.strp(nav.name.toSlice(ip)); | 1811 | try wip_nav.strp(nav.name.toSlice(ip)); |
| 1760 | try wip_nav.strp(nav.fqn.toSlice(ip)); | 1812 | try wip_nav.strp(nav.fqn.toSlice(ip)); |
| 1761 | try wip_nav.refType(Type.fromInterned(func_type.return_type)); | 1813 | try wip_nav.refType(Type.fromInterned(func_type.return_type)); |
| 1762 | const external_relocs = &dwarf.debug_info.section.getUnit(unit).external_relocs; | 1814 | const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| 1763 | try external_relocs.ensureUnusedCapacity(dwarf.gpa, 2); | 1815 | try external_relocs.ensureUnusedCapacity(dwarf.gpa, 2); |
| 1764 | external_relocs.appendAssumeCapacity(.{ | 1816 | external_relocs.appendAssumeCapacity(.{ |
| 1765 | .source_entry = wip_nav.entry, | | |
| 1766 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1817 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1767 | .target_sym = sym_index, | 1818 | .target_sym = sym_index, |
| 1768 | }); | 1819 | }); |
| 1769 | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); | 1820 | try diw.writeByteNTimes(0, @intFromEnum(dwarf.address_size)); |
| 1770 | wip_nav.func_high_reloc = @intCast(external_relocs.items.len); | 1821 | wip_nav.func_high_reloc = @intCast(external_relocs.items.len); |
| 1771 | external_relocs.appendAssumeCapacity(.{ | 1822 | external_relocs.appendAssumeCapacity(.{ |
| 1772 | .source_entry = wip_nav.entry, | | |
| 1773 | .source_off = @intCast(wip_nav.debug_info.items.len), | 1823 | .source_off = @intCast(wip_nav.debug_info.items.len), |
| 1774 | .target_sym = sym_index, | 1824 | .target_sym = sym_index, |
| 1775 | .target_off = undefined, | 1825 | .target_off = undefined, |
| ... | @@ -1785,8 +1835,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -1785,8 +1835,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1785 | if (dwarf.incremental()) { | 1835 | if (dwarf.incremental()) { |
| 1786 | try uleb128(dlw, 1 + dwarf.sectionOffsetBytes()); | 1836 | try uleb128(dlw, 1 + dwarf.sectionOffsetBytes()); |
| 1787 | try dlw.writeByte(DW.LNE.ZIG_set_decl); | 1837 | try dlw.writeByte(DW.LNE.ZIG_set_decl); |
| 1788 | try dwarf.debug_line.section.getUnit(wip_nav.unit).cross_section_relocs.append(dwarf.gpa, .{ | 1838 | try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).cross_section_relocs.append(dwarf.gpa, .{ |
| 1789 | .source_entry = wip_nav.entry.toOptional(), | | |
| 1790 | .source_off = @intCast(wip_nav.debug_line.items.len), | 1839 | .source_off = @intCast(wip_nav.debug_line.items.len), |
| 1791 | .target_sec = .debug_info, | 1840 | .target_sec = .debug_info, |
| 1792 | .target_unit = wip_nav.unit, | 1841 | .target_unit = wip_nav.unit, |
| ... | @@ -1801,8 +1850,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In | ... | @@ -1801,8 +1850,7 @@ pub fn initWipNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.In |
| 1801 | } else { | 1850 | } else { |
| 1802 | try uleb128(dlw, 1 + @intFromEnum(dwarf.address_size)); | 1851 | try uleb128(dlw, 1 + @intFromEnum(dwarf.address_size)); |
| 1803 | try dlw.writeByte(DW.LNE.set_address); | 1852 | try dlw.writeByte(DW.LNE.set_address); |
| 1804 | try dwarf.debug_line.section.getUnit(wip_nav.unit).external_relocs.append(dwarf.gpa, .{ | 1853 | try dwarf.debug_line.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.append(dwarf.gpa, .{ |
| 1805 | .source_entry = wip_nav.entry, | | |
| 1806 | .source_off = @intCast(wip_nav.debug_line.items.len), | 1854 | .source_off = @intCast(wip_nav.debug_line.items.len), |
| 1807 | .target_sym = sym_index, | 1855 | .target_sym = sym_index, |
| 1808 | }); | 1856 | }); |
| ... | @@ -1835,7 +1883,7 @@ pub fn finishWipNav( | ... | @@ -1835,7 +1883,7 @@ pub fn finishWipNav( |
| 1835 | log.debug("finishWipNav({})", .{nav.fqn.fmt(ip)}); | 1883 | log.debug("finishWipNav({})", .{nav.fqn.fmt(ip)}); |
| 1836 | | 1884 | |
| 1837 | if (wip_nav.func != .none) { | 1885 | if (wip_nav.func != .none) { |
| 1838 | const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).external_relocs; | 1886 | const external_relocs = &dwarf.debug_info.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs; |
| 1839 | external_relocs.items[wip_nav.func_high_reloc].target_off = sym.size; | 1887 | external_relocs.items[wip_nav.func_high_reloc].target_off = sym.size; |
| 1840 | if (wip_nav.any_children) { | 1888 | if (wip_nav.any_children) { |
| 1841 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 1889 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| ... | @@ -1847,8 +1895,7 @@ pub fn finishWipNav( | ... | @@ -1847,8 +1895,7 @@ pub fn finishWipNav( |
| 1847 | ); | 1895 | ); |
| 1848 | | 1896 | |
| 1849 | var aranges_entry = [1]u8{0} ** (8 + 8); | 1897 | var aranges_entry = [1]u8{0} ** (8 + 8); |
| 1850 | try dwarf.debug_aranges.section.getUnit(wip_nav.unit).external_relocs.append(dwarf.gpa, .{ | 1898 | try dwarf.debug_aranges.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.append(dwarf.gpa, .{ |
| 1851 | .source_entry = wip_nav.entry, | | |
| 1852 | .target_sym = sym.index, | 1899 | .target_sym = sym.index, |
| 1853 | }); | 1900 | }); |
| 1854 | dwarf.writeInt(aranges_entry[0..@intFromEnum(dwarf.address_size)], 0); | 1901 | dwarf.writeInt(aranges_entry[0..@intFromEnum(dwarf.address_size)], 0); |
| ... | @@ -1862,14 +1909,12 @@ pub fn finishWipNav( | ... | @@ -1862,14 +1909,12 @@ pub fn finishWipNav( |
| 1862 | aranges_entry[0 .. @intFromEnum(dwarf.address_size) * 2], | 1909 | aranges_entry[0 .. @intFromEnum(dwarf.address_size) * 2], |
| 1863 | ); | 1910 | ); |
| 1864 | | 1911 | |
| 1865 | try dwarf.debug_rnglists.section.getUnit(wip_nav.unit).external_relocs.appendSlice(dwarf.gpa, &.{ | 1912 | try dwarf.debug_rnglists.section.getUnit(wip_nav.unit).getEntry(wip_nav.entry).external_relocs.appendSlice(dwarf.gpa, &.{ |
| 1866 | .{ | 1913 | .{ |
| 1867 | .source_entry = wip_nav.entry, | | |
| 1868 | .source_off = 1, | 1914 | .source_off = 1, |
| 1869 | .target_sym = sym.index, | 1915 | .target_sym = sym.index, |
| 1870 | }, | 1916 | }, |
| 1871 | .{ | 1917 | .{ |
| 1872 | .source_entry = wip_nav.entry, | | |
| 1873 | .source_off = 1 + @intFromEnum(dwarf.address_size), | 1918 | .source_off = 1 + @intFromEnum(dwarf.address_size), |
| 1874 | .target_sym = sym.index, | 1919 | .target_sym = sym.index, |
| 1875 | .target_off = sym.size, | 1920 | .target_off = sym.size, |
| ... | @@ -1935,6 +1980,29 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -1935,6 +1980,29 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 1935 | errdefer _ = dwarf.navs.pop(); | 1980 | errdefer _ = dwarf.navs.pop(); |
| 1936 | switch (ip.indexToKey(nav_val.toIntern())) { | 1981 | switch (ip.indexToKey(nav_val.toIntern())) { |
| 1937 | .func => |func| { | 1982 | .func => |func| { |
| | 1983 | if (nav_gop.found_existing) { |
| | 1984 | const unit_ptr = dwarf.debug_info.section.getUnit(unit); |
| | 1985 | const entry_ptr = unit_ptr.getEntry(nav_gop.value_ptr.*); |
| | 1986 | if (entry_ptr.len >= AbbrevCode.decl_bytes) { |
| | 1987 | var abbrev_code_buf: [AbbrevCode.decl_bytes]u8 = undefined; |
| | 1988 | if (try dwarf.getFile().?.preadAll( |
| | 1989 | &abbrev_code_buf, |
| | 1990 | dwarf.debug_info.section.off + unit_ptr.off + unit_ptr.header_len + entry_ptr.off, |
| | 1991 | ) != abbrev_code_buf.len) return error.InputOutput; |
| | 1992 | var abbrev_code_fbs = std.io.fixedBufferStream(&abbrev_code_buf); |
| | 1993 | const abbrev_code: AbbrevCode = @enumFromInt( |
| | 1994 | try std.leb.readUleb128(@typeInfo(AbbrevCode).Enum.tag_type, abbrev_code_fbs.reader()), |
| | 1995 | ); |
| | 1996 | switch (abbrev_code) { |
| | 1997 | else => unreachable, |
| | 1998 | .decl_func, .decl_func_empty => return, |
| | 1999 | .decl_func_generic, .decl_func_generic_empty => {}, |
| | 2000 | } |
| | 2001 | } |
| | 2002 | entry_ptr.clear(); |
| | 2003 | } else nav_gop.value_ptr.* = try dwarf.addCommonEntry(unit); |
| | 2004 | wip_nav.entry = nav_gop.value_ptr.*; |
| | 2005 | |
| 1938 | const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: { | 2006 | const parent_type, const accessibility: u8 = if (nav.analysis_owner.unwrap()) |cau| parent: { |
| 1939 | const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace); | 2007 | const parent_namespace_ptr = ip.namespacePtr(ip.getCau(cau).namespace); |
| 1940 | break :parent .{ | 2008 | break :parent .{ |
| ... | @@ -1948,12 +2016,9 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -1948,12 +2016,9 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 1948 | }; | 2016 | }; |
| 1949 | } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private }; | 2017 | } else .{ zcu.fileRootType(inst_info.file), DW.ACCESS.private }; |
| 1950 | | 2018 | |
| 1951 | if (!nav_gop.found_existing) nav_gop.value_ptr.* = try dwarf.addCommonEntry(unit); | | |
| 1952 | wip_nav.entry = nav_gop.value_ptr.*; | | |
| 1953 | | | |
| 1954 | const func_type = ip.indexToKey(func.ty).func_type; | 2019 | const func_type = ip.indexToKey(func.ty).func_type; |
| 1955 | const diw = wip_nav.debug_info.writer(dwarf.gpa); | 2020 | const diw = wip_nav.debug_info.writer(dwarf.gpa); |
| 1956 | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (func_type.param_types.len > 0 and func_type.is_var_args) .decl_func_generic else .decl_func_generic_empty))); | 2021 | try uleb128(diw, @intFromEnum(@as(AbbrevCode, if (func_type.param_types.len > 0 or func_type.is_var_args) .decl_func_generic else .decl_func_generic_empty))); |
| 1957 | try wip_nav.refType(Type.fromInterned(parent_type)); | 2022 | try wip_nav.refType(Type.fromInterned(parent_type)); |
| 1958 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); | 2023 | assert(wip_nav.debug_info.items.len == DebugInfo.declEntryLineOff(dwarf)); |
| 1959 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); | 2024 | try diw.writeInt(u32, @intCast(loc.line + 1), dwarf.endian); |
| ... | @@ -1961,12 +2026,14 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool | ... | @@ -1961,12 +2026,14 @@ pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool |
| 1961 | try diw.writeByte(accessibility); | 2026 | try diw.writeByte(accessibility); |
| 1962 | try wip_nav.strp(nav.name.toSlice(ip)); | 2027 | try wip_nav.strp(nav.name.toSlice(ip)); |
| 1963 | try wip_nav.refType(Type.fromInterned(func_type.return_type)); | 2028 | try wip_nav.refType(Type.fromInterned(func_type.return_type)); |
| 1964 | for (0..func_type.param_types.len) |param_index| { | 2029 | if (func_type.param_types.len > 0 or func_type.is_var_args) { |
| 1965 | try uleb128(diw, @intFromEnum(AbbrevCode.func_type_param)); | 2030 | for (0..func_type.param_types.len) |param_index| { |
| 1966 | try wip_nav.refType(Type.fromInterned(func_type.param_types.get(ip)[param_index])); | 2031 | try uleb128(diw, @intFromEnum(AbbrevCode.func_type_param)); |
| | 2032 | try wip_nav.refType(Type.fromInterned(func_type.param_types.get(ip)[param_index])); |
| | 2033 | } |
| | 2034 | if (func_type.is_var_args) try uleb128(diw, @intFromEnum(AbbrevCode.is_var_args)); |
| | 2035 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 1967 | } | 2036 | } |
| 1968 | if (func_type.is_var_args) try uleb128(diw, @intFromEnum(AbbrevCode.is_var_args)); | | |
| 1969 | try uleb128(diw, @intFromEnum(AbbrevCode.null)); | | |
| 1970 | }, | 2037 | }, |
| 1971 | .struct_type => done: { | 2038 | .struct_type => done: { |
| 1972 | const loaded_struct = ip.loadStructType(nav_val.toIntern()); | 2039 | const loaded_struct = ip.loadStructType(nav_val.toIntern()); |
| ... | @@ -2535,13 +2602,25 @@ fn updateType( | ... | @@ -2535,13 +2602,25 @@ fn updateType( |
| 2535 | .error_union_type => |error_union_type| { | 2602 | .error_union_type => |error_union_type| { |
| 2536 | const error_union_error_set_type = Type.fromInterned(error_union_type.error_set_type); | 2603 | const error_union_error_set_type = Type.fromInterned(error_union_type.error_set_type); |
| 2537 | const error_union_payload_type = Type.fromInterned(error_union_type.payload_type); | 2604 | const error_union_payload_type = Type.fromInterned(error_union_type.payload_type); |
| 2538 | const error_union_error_set_offset = codegen.errUnionErrorOffset(error_union_payload_type, pt); | 2605 | const error_union_error_set_offset, const error_union_payload_offset = switch (error_union_type.payload_type) { |
| 2539 | const error_union_payload_offset = codegen.errUnionPayloadOffset(error_union_payload_type, pt); | 2606 | .generic_poison_type => .{ 0, 0 }, |
| | 2607 | else => .{ |
| | 2608 | codegen.errUnionErrorOffset(error_union_payload_type, pt), |
| | 2609 | codegen.errUnionPayloadOffset(error_union_payload_type, pt), |
| | 2610 | }, |
| | 2611 | }; |
| 2540 | | 2612 | |
| 2541 | try uleb128(diw, @intFromEnum(AbbrevCode.union_type)); | 2613 | try uleb128(diw, @intFromEnum(AbbrevCode.union_type)); |
| 2542 | try wip_nav.strp(name); | 2614 | try wip_nav.strp(name); |
| 2543 | try uleb128(diw, ty.abiSize(pt)); | 2615 | if (error_union_type.error_set_type != .generic_poison_type and |
| 2544 | try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?); | 2616 | error_union_type.payload_type != .generic_poison_type) |
| | 2617 | { |
| | 2618 | try uleb128(diw, ty.abiSize(pt)); |
| | 2619 | try uleb128(diw, ty.abiAlignment(pt).toByteUnits().?); |
| | 2620 | } else { |
| | 2621 | try uleb128(diw, 0); |
| | 2622 | try uleb128(diw, 1); |
| | 2623 | } |
| 2545 | { | 2624 | { |
| 2546 | try uleb128(diw, @intFromEnum(AbbrevCode.tagged_union)); | 2625 | try uleb128(diw, @intFromEnum(AbbrevCode.tagged_union)); |
| 2547 | try wip_nav.infoSectionOffset( | 2626 | try wip_nav.infoSectionOffset( |
| ... | @@ -2723,10 +2802,16 @@ fn updateType( | ... | @@ -2723,10 +2802,16 @@ fn updateType( |
| 2723 | } | 2802 | } |
| 2724 | if (error_set_type.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); | 2803 | if (error_set_type.names.len > 0) try uleb128(diw, @intFromEnum(AbbrevCode.null)); |
| 2725 | }, | 2804 | }, |
| 2726 | .inferred_error_set_type => |func| { | 2805 | .inferred_error_set_type => |func| switch (ip.funcIesResolvedUnordered(func)) { |
| 2727 | try uleb128(diw, @intFromEnum(AbbrevCode.inferred_error_set_type)); | 2806 | .none => { |
| 2728 | try wip_nav.strp(name); | 2807 | try uleb128(diw, @intFromEnum(AbbrevCode.void_type)); |
| 2729 | try wip_nav.refType(Type.fromInterned(ip.funcIesResolvedUnordered(func))); | 2808 | try wip_nav.strp(name); |
| | 2809 | }, |
| | 2810 | else => |ies| { |
| | 2811 | try uleb128(diw, @intFromEnum(AbbrevCode.inferred_error_set_type)); |
| | 2812 | try wip_nav.strp(name); |
| | 2813 | try wip_nav.refType(Type.fromInterned(ies)); |
| | 2814 | }, |
| 2730 | }, | 2815 | }, |
| 2731 | | 2816 | |
| 2732 | // values, not types | 2817 | // values, not types |
| ... | @@ -3072,7 +3157,8 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -3072,7 +3157,8 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3072 | if (dwarf.debug_aranges.section.dirty) { | 3157 | if (dwarf.debug_aranges.section.dirty) { |
| 3073 | for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| { | 3158 | for (dwarf.debug_aranges.section.units.items, 0..) |*unit_ptr, unit_index| { |
| 3074 | const unit: Unit.Index = @enumFromInt(unit_index); | 3159 | const unit: Unit.Index = @enumFromInt(unit_index); |
| 3075 | try unit_ptr.cross_section_relocs.ensureUnusedCapacity(dwarf.gpa, 1); | 3160 | unit_ptr.clear(); |
| | 3161 | try unit_ptr.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 1); |
| 3076 | header.clearRetainingCapacity(); | 3162 | header.clearRetainingCapacity(); |
| 3077 | try header.ensureTotalCapacity(unit_ptr.header_len); | 3163 | try header.ensureTotalCapacity(unit_ptr.header_len); |
| 3078 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| | 3164 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| |
| ... | @@ -3103,8 +3189,9 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -3103,8 +3189,9 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3103 | if (dwarf.debug_info.section.dirty) { | 3189 | if (dwarf.debug_info.section.dirty) { |
| 3104 | for (dwarf.mods.keys(), dwarf.mods.values(), dwarf.debug_info.section.units.items, 0..) |mod, mod_info, *unit_ptr, unit_index| { | 3190 | for (dwarf.mods.keys(), dwarf.mods.values(), dwarf.debug_info.section.units.items, 0..) |mod, mod_info, *unit_ptr, unit_index| { |
| 3105 | const unit: Unit.Index = @enumFromInt(unit_index); | 3191 | const unit: Unit.Index = @enumFromInt(unit_index); |
| 3106 | try unit_ptr.cross_unit_relocs.ensureUnusedCapacity(dwarf.gpa, 1); | 3192 | unit_ptr.clear(); |
| 3107 | try unit_ptr.cross_section_relocs.ensureUnusedCapacity(dwarf.gpa, 7); | 3193 | try unit_ptr.cross_unit_relocs.ensureTotalCapacity(dwarf.gpa, 1); |
| | 3194 | try unit_ptr.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 7); |
| 3108 | header.clearRetainingCapacity(); | 3195 | header.clearRetainingCapacity(); |
| 3109 | try header.ensureTotalCapacity(unit_ptr.header_len); | 3196 | try header.ensureTotalCapacity(unit_ptr.header_len); |
| 3110 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| | 3197 | const unit_len = (if (unit_ptr.next.unwrap()) |next_unit| |
| ... | @@ -3195,7 +3282,8 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { | ... | @@ -3195,7 +3282,8 @@ pub fn flushModule(dwarf: *Dwarf, pt: Zcu.PerThread) FlushError!void { |
| 3195 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| | 3282 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| |
| 3196 | try unit.resizeHeader(&dwarf.debug_line.section, dwarf, DebugLine.headerBytes(dwarf, @intCast(mod_info.dirs.count()), @intCast(mod_info.files.count()))); | 3283 | try unit.resizeHeader(&dwarf.debug_line.section, dwarf, DebugLine.headerBytes(dwarf, @intCast(mod_info.dirs.count()), @intCast(mod_info.files.count()))); |
| 3197 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| { | 3284 | for (dwarf.mods.values(), dwarf.debug_line.section.units.items) |mod_info, *unit| { |
| 3198 | try unit.cross_section_relocs.ensureUnusedCapacity(dwarf.gpa, 2 * (1 + mod_info.files.count())); | 3285 | unit.clear(); |
| | 3286 | try unit.cross_section_relocs.ensureTotalCapacity(dwarf.gpa, 2 * (1 + mod_info.files.count())); |
| 3199 | header.clearRetainingCapacity(); | 3287 | header.clearRetainingCapacity(); |
| 3200 | try header.ensureTotalCapacity(unit.header_len); | 3288 | try header.ensureTotalCapacity(unit.header_len); |
| 3201 | const unit_len = (if (unit.next.unwrap()) |next_unit| | 3289 | const unit_len = (if (unit.next.unwrap()) |next_unit| |