| ... | ... | @@ -224,7 +224,7 @@ dwarf_units: std.ArrayList(struct { |
| 224 | 224 | debug_rnglists_first_target_reloc: NodeReloc.Index, |
| 225 | 225 | debug_rnglists_symbol_relocs: std.array_hash_map.Auto(SymbolReloc.Index, void), |
| 226 | 226 | }), |
| 227 | | dwarf_values: std.ArrayList(struct { |
| 227 | dwarf_consts: std.array_hash_map.Auto(link.ConstPool.Index, struct { |
| 228 | 228 | debug_info_first_target_reloc: NodeReloc.Index, |
| 229 | 229 | debug_info_first_symbol_reloc: SymbolReloc.Index, |
| 230 | 230 | debug_info_first_node_reloc: NodeReloc.Index, |
| ... | ... | @@ -318,7 +318,7 @@ const Node = union(enum) { |
| 318 | 318 | unit_debug_line_header: Dwarf.Unit.Index, |
| 319 | 319 | unit_debug_rnglists: Dwarf.Unit.Index, |
| 320 | 320 | |
| 321 | | value_debug_info: link.ConstPool.Index, |
| 321 | const_debug_info: link.ConstPool.Index, |
| 322 | 322 | global_debug_info: Dwarf.Global.Index, |
| 323 | 323 | func_frame_fde: Dwarf.Func.Index, |
| 324 | 324 | func_debug_info: Dwarf.Func.Index, |
| ... | ... | @@ -1142,7 +1142,8 @@ const SymbolReloc = struct { |
| 1142 | 1142 | /// * An input section |
| 1143 | 1143 | /// * A section |
| 1144 | 1144 | /// * A NAV, UAV, or lazy code/data |
| 1145 | | node: MappedFile.Node.Index, |
| 1145 | /// * `.none`, if this relocation was deleted (in which case it should be ignored) |
| 1146 | node: MappedFile.Node.Index.Optional, |
| 1146 | 1147 | /// The offset of the relocation inside of `node`. |
| 1147 | 1148 | offset: u64, |
| 1148 | 1149 | /// A symbol used to compute the relocated value. Precise meaning depends on `@"type"`. |
| ... | ... | @@ -1182,7 +1183,7 @@ const SymbolReloc = struct { |
| 1182 | 1183 | /// because relocations in the GOTPLT are handled specially, without `SymbolReloc` entries. |
| 1183 | 1184 | fn relaSection(sr: *const SymbolReloc, elf: *Elf) Section.Index { |
| 1184 | 1185 | const shndx = switch (elf.ehdrType()) { |
| 1185 | | .REL => elf.getNodeShndx(sr.node).get(elf).rela.shndx, |
| 1186 | .REL => elf.getNodeShndx(sr.node.unwrap().?).get(elf).rela.shndx, |
| 1186 | 1187 | .EXEC, .DYN => elf.shndx.rela_dyn, |
| 1187 | 1188 | }; |
| 1188 | 1189 | assert(shndx != .UNDEF); |
| ... | ... | @@ -1619,7 +1620,8 @@ const SymbolReloc = struct { |
| 1619 | 1620 | |
| 1620 | 1621 | fn apply(reloc: *SymbolReloc, elf: *Elf) void { |
| 1621 | 1622 | assert(elf.ehdrType() != .REL); |
| 1622 | | if (reloc.node.hasMoved(&elf.mf) or reloc.target.hasMoved(elf)) { |
| 1623 | const node = reloc.node.unwrap() orelse return; // deleted |
| 1624 | if (node.hasMoved(&elf.mf) or reloc.target.hasMoved(elf)) { |
| 1623 | 1625 | // There's no point applying the relocation now, because it will be re-applied by |
| 1624 | 1626 | // `flushMoved` at some point anyway. |
| 1625 | 1627 | return; |
| ... | ... | @@ -1644,8 +1646,9 @@ const SymbolReloc = struct { |
| 1644 | 1646 | } |
| 1645 | 1647 | } |
| 1646 | 1648 | fn applyInner(reloc: *const SymbolReloc, elf: *Elf) error{ RelocationOverflow, RelocationMisaligned }!void { |
| 1647 | | const dest_vaddr = elf.getNodeVAddr(reloc.node) + reloc.offset; |
| 1648 | | const dest_slice = reloc.node.slice(&elf.mf)[@intCast(reloc.offset)..]; |
| 1649 | const node = reloc.node.unwrap().?; |
| 1650 | const dest_vaddr = elf.getNodeVAddr(node) + reloc.offset; |
| 1651 | const dest_slice = node.slice(&elf.mf)[@intCast(reloc.offset)..]; |
| 1649 | 1652 | |
| 1650 | 1653 | const addend: u64 = @bitCast(reloc.addend); |
| 1651 | 1654 | const target_val: u64 = type: switch (reloc.type.target) { |
| ... | ... | @@ -1737,6 +1740,7 @@ const SymbolReloc = struct { |
| 1737 | 1740 | } |
| 1738 | 1741 | |
| 1739 | 1742 | reloc.* = undefined; |
| 1743 | reloc.node = .none; |
| 1740 | 1744 | } |
| 1741 | 1745 | |
| 1742 | 1746 | /// If `reloc.rela_index` is populated, reset it to `.none` and delete the relocation, updating |
| ... | ... | @@ -1746,7 +1750,7 @@ const SymbolReloc = struct { |
| 1746 | 1750 | reloc.relaSection(elf).relaDeleteOne(elf, rela_index); |
| 1747 | 1751 | switch (elf.ehdrType()) { |
| 1748 | 1752 | .REL => {}, |
| 1749 | | .EXEC, .DYN => switch (elf.nodeWantsDsoRelocation(reloc.node)) { |
| 1753 | .EXEC, .DYN => switch (elf.nodeWantsDsoRelocation(reloc.node.unwrap().?)) { |
| 1750 | 1754 | .no => unreachable, // there *was* a dynamic relocation! |
| 1751 | 1755 | .yes => {}, |
| 1752 | 1756 | .yes_textrel => elf.textrel_count -= 1, |
| ... | ... | @@ -1760,7 +1764,7 @@ const SymbolReloc = struct { |
| 1760 | 1764 | /// This represents a symbol reloc against the section symbol containing the node |
| 1761 | 1765 | /// with a variable addend that changes when the target node moves. |
| 1762 | 1766 | const NodeReloc = struct { |
| 1763 | | node: MappedFile.Node.Index, |
| 1767 | node: MappedFile.Node.Index.Optional, |
| 1764 | 1768 | offset: u64, |
| 1765 | 1769 | target: MappedFile.Node.Index, |
| 1766 | 1770 | addend: i64, |
| ... | ... | @@ -1786,7 +1790,7 @@ const NodeReloc = struct { |
| 1786 | 1790 | assert(elf.ehdrType() == .REL); |
| 1787 | 1791 | // The node has moved, so the offset of the relocation within the section might have |
| 1788 | 1792 | // changed, so update the `offset` field of the `ElfN.Rela` entry. |
| 1789 | | elf.getNodeShndx(reloc.node).get(elf).rela.shndx.relaSetOffset(elf, rela_index, node_vaddr + reloc.offset); |
| 1793 | elf.getNodeShndx(reloc.node.unwrap().?).get(elf).rela.shndx.relaSetOffset(elf, rela_index, node_vaddr + reloc.offset); |
| 1790 | 1794 | } else { |
| 1791 | 1795 | assert(elf.ehdrType() != .REL); |
| 1792 | 1796 | reloc.apply(elf); |
| ... | ... | @@ -1797,7 +1801,7 @@ const NodeReloc = struct { |
| 1797 | 1801 | if (reloc.rela_index.unwrap()) |rela_index| { |
| 1798 | 1802 | assert(elf.ehdrType() == .REL); |
| 1799 | 1803 | // The target has moved, so the `addend` field of the `ElfN.Rela` entry needs to be updated. |
| 1800 | | elf.getNodeShndx(reloc.node).get(elf).rela.shndx.relaSetAddend(elf, rela_index, target_section_offset +% @as(u64, @bitCast(reloc.addend))); |
| 1804 | elf.getNodeShndx(reloc.node.unwrap().?).get(elf).rela.shndx.relaSetAddend(elf, rela_index, target_section_offset +% @as(u64, @bitCast(reloc.addend))); |
| 1801 | 1805 | } else { |
| 1802 | 1806 | assert(elf.ehdrType() != .REL); |
| 1803 | 1807 | reloc.apply(elf); |
| ... | ... | @@ -1805,12 +1809,13 @@ const NodeReloc = struct { |
| 1805 | 1809 | } |
| 1806 | 1810 | |
| 1807 | 1811 | fn apply(reloc: *NodeReloc, elf: *Elf) void { |
| 1812 | const node = reloc.node.unwrap() orelse return; // deleted |
| 1808 | 1813 | if (reloc.rela_index.unwrap()) |rela_index| { |
| 1809 | 1814 | assert(elf.ehdrType() == .REL); |
| 1810 | 1815 | _ = rela_index; |
| 1811 | 1816 | } else { |
| 1812 | 1817 | assert(elf.ehdrType() != .REL); |
| 1813 | | if (reloc.node.hasMoved(&elf.mf) or reloc.target.hasMoved(&elf.mf)) { |
| 1818 | if (node.hasMoved(&elf.mf) or reloc.target.hasMoved(&elf.mf)) { |
| 1814 | 1819 | // There's no point applying the relocation now, because it will be re-applied by |
| 1815 | 1820 | // `flushMoved` at some point anyway. |
| 1816 | 1821 | return; |
| ... | ... | @@ -1842,7 +1847,7 @@ const NodeReloc = struct { |
| 1842 | 1847 | }, .cast = .unsigned, .shift = .@"0" }; |
| 1843 | 1848 | const addend: u64 = @bitCast(reloc.addend); |
| 1844 | 1849 | const target_val = elf.getNodeVAddr(reloc.target) +% addend; |
| 1845 | | const dest_slice = reloc.node.slice(&elf.mf)[@intCast(reloc.offset)..]; |
| 1850 | const dest_slice = reloc.node.unwrap().?.slice(&elf.mf)[@intCast(reloc.offset)..]; |
| 1846 | 1851 | try simple.write(target_val, dest_slice, elf.targetEndian()); |
| 1847 | 1852 | } |
| 1848 | 1853 | |
| ... | ... | @@ -1858,7 +1863,7 @@ const NodeReloc = struct { |
| 1858 | 1863 | .unit_debug_info_header => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_info_header_first_target_reloc, |
| 1859 | 1864 | .unit_debug_line_header => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_line_header_first_target_reloc, |
| 1860 | 1865 | .unit_debug_rnglists => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_rnglists_first_target_reloc, |
| 1861 | | .value_debug_info => |vi| &elf.dwarf_values.items[@backingInt(vi)].debug_info_first_target_reloc, |
| 1866 | .const_debug_info => |cpi| &elf.dwarf_consts.getPtr(cpi).?.debug_info_first_target_reloc, |
| 1862 | 1867 | .global_debug_info => |gi| &elf.dwarf_globals.items[@backingInt(gi)].debug_info_first_target_reloc, |
| 1863 | 1868 | .func_debug_info => |fi| &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_target_reloc, |
| 1864 | 1869 | }; |
| ... | ... | @@ -1877,13 +1882,14 @@ const NodeReloc = struct { |
| 1877 | 1882 | } |
| 1878 | 1883 | |
| 1879 | 1884 | reloc.* = undefined; |
| 1885 | reloc.node = .none; |
| 1880 | 1886 | } |
| 1881 | 1887 | |
| 1882 | 1888 | /// If `reloc.rela_index` is populated, reset it to `.none` and delete the relocation. |
| 1883 | 1889 | fn deleteOutputRel(reloc: *NodeReloc, elf: *Elf) void { |
| 1884 | 1890 | const rela_index = reloc.rela_index.unwrap() orelse return; |
| 1885 | 1891 | assert(elf.ehdrType() == .REL); |
| 1886 | | elf.getNodeShndx(reloc.node).get(elf).rela.shndx.relaDeleteOne(elf, rela_index); |
| 1892 | elf.getNodeShndx(reloc.node.unwrap().?).get(elf).rela.shndx.relaDeleteOne(elf, rela_index); |
| 1887 | 1893 | reloc.rela_index = .none; |
| 1888 | 1894 | } |
| 1889 | 1895 | }; |
| ... | ... | @@ -3175,7 +3181,8 @@ const Symbol = struct { |
| 3175 | 3181 | .abs, .pltabs => {}, |
| 3176 | 3182 | } |
| 3177 | 3183 | if (!reloc.type.action.simple.dest.isAddr(elf)) continue; |
| 3178 | | switch (elf.nodeWantsDsoRelocation(reloc.node)) { |
| 3184 | const node = reloc.node.unwrap().?; |
| 3185 | switch (elf.nodeWantsDsoRelocation(node)) { |
| 3179 | 3186 | .no => continue, |
| 3180 | 3187 | .yes_textrel => elf.textrel_count += 1, |
| 3181 | 3188 | .yes => {}, |
| ... | ... | @@ -3183,7 +3190,7 @@ const Symbol = struct { |
| 3183 | 3190 | // There is capacity for a relocation because we just deleted one earlier. |
| 3184 | 3191 | reloc.rela_index = elf.shndx.rela_dyn.relaAddOneAssumeCapacity(elf, .{ |
| 3185 | 3192 | .type = .relative(elf), |
| 3186 | | .offset = elf.getNodeVAddr(reloc.node) + reloc.offset, |
| 3193 | .offset = elf.getNodeVAddr(node) + reloc.offset, |
| 3187 | 3194 | .raw_sym_index = 0, |
| 3188 | 3195 | .addend = 0, |
| 3189 | 3196 | }).toOptional(); |
| ... | ... | @@ -3310,7 +3317,7 @@ pub fn symbolForAtom(elf: *Elf, atom: link.File.AtomId) link.File.SymbolId { |
| 3310 | 3317 | .unit_debug_line, |
| 3311 | 3318 | .unit_debug_line_header, |
| 3312 | 3319 | .unit_debug_rnglists, |
| 3313 | | .value_debug_info, |
| 3320 | .const_debug_info, |
| 3314 | 3321 | .global_debug_info, |
| 3315 | 3322 | .func_frame_fde, |
| 3316 | 3323 | .func_debug_info, |
| ... | ... | @@ -3823,7 +3830,7 @@ fn create( |
| 3823 | 3830 | .first_target_reloc = .none, |
| 3824 | 3831 | }), |
| 3825 | 3832 | .dwarf_units = .empty, |
| 3826 | | .dwarf_values = .empty, |
| 3833 | .dwarf_consts = .empty, |
| 3827 | 3834 | .dwarf_globals = .empty, |
| 3828 | 3835 | .dwarf_funcs = .empty, |
| 3829 | 3836 | |
| ... | ... | @@ -3878,7 +3885,7 @@ pub fn deinit(elf: *Elf) void { |
| 3878 | 3885 | elf.dwarf.deinit(); |
| 3879 | 3886 | for (elf.dwarf_units.items) |*dwarf_unit| dwarf_unit.debug_rnglists_symbol_relocs.deinit(gpa); |
| 3880 | 3887 | elf.dwarf_units.deinit(gpa); |
| 3881 | | elf.dwarf_values.deinit(gpa); |
| 3888 | elf.dwarf_consts.deinit(gpa); |
| 3882 | 3889 | elf.dwarf_globals.deinit(gpa); |
| 3883 | 3890 | elf.dwarf_funcs.deinit(gpa); |
| 3884 | 3891 | |
| ... | ... | @@ -5176,7 +5183,7 @@ fn getNodeShndx(elf: *const Elf, ni: MappedFile.Node.Index) Section.Index { |
| 5176 | 5183 | .unit_frame_cie, |
| 5177 | 5184 | .unit_debug_info_header, |
| 5178 | 5185 | .unit_debug_line_header, |
| 5179 | | .value_debug_info, |
| 5186 | .const_debug_info, |
| 5180 | 5187 | .global_debug_info, |
| 5181 | 5188 | .func_frame_fde, |
| 5182 | 5189 | .func_debug_info, |
| ... | ... | @@ -5213,7 +5220,7 @@ fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 { |
| 5213 | 5220 | .unit_debug_line, |
| 5214 | 5221 | .unit_debug_line_header, |
| 5215 | 5222 | .unit_debug_rnglists, |
| 5216 | | .value_debug_info, |
| 5223 | .const_debug_info, |
| 5217 | 5224 | .global_debug_info, |
| 5218 | 5225 | .func_frame_fde, |
| 5219 | 5226 | .func_debug_info, |
| ... | ... | @@ -5252,7 +5259,7 @@ fn computeNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 { |
| 5252 | 5259 | .unit_debug_info_header, |
| 5253 | 5260 | .unit_debug_line_header, |
| 5254 | 5261 | .unit_debug_rnglists, |
| 5255 | | .value_debug_info, |
| 5262 | .const_debug_info, |
| 5256 | 5263 | .global_debug_info, |
| 5257 | 5264 | .func_frame_fde, |
| 5258 | 5265 | .func_debug_info, |
| ... | ... | @@ -5287,7 +5294,7 @@ fn computeNodeSectionOffset(elf: *Elf, ni: MappedFile.Node.Index) u64 { |
| 5287 | 5294 | .unit_debug_info_header, |
| 5288 | 5295 | .unit_debug_line_header, |
| 5289 | 5296 | .unit_debug_rnglists, |
| 5290 | | .value_debug_info, |
| 5297 | .const_debug_info, |
| 5291 | 5298 | .global_debug_info, |
| 5292 | 5299 | .func_frame_fde, |
| 5293 | 5300 | .func_debug_info, |
| ... | ... | @@ -5356,9 +5363,9 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void { |
| 5356 | 5363 | .first_node_reloc = &elf.dwarf_units.items[@backingInt(ui)].debug_line_header_first_node_reloc, |
| 5357 | 5364 | }, |
| 5358 | 5365 | .unit_debug_rnglists => unreachable, // unsupported |
| 5359 | | .value_debug_info => |vi| .{ |
| 5360 | | .first_symbol_reloc = &elf.dwarf_values.items[@backingInt(vi)].debug_info_first_symbol_reloc, |
| 5361 | | .first_node_reloc = &elf.dwarf_values.items[@backingInt(vi)].debug_info_first_node_reloc, |
| 5366 | .const_debug_info => |cpi| .{ |
| 5367 | .first_symbol_reloc = &elf.dwarf_consts.getPtr(cpi).?.debug_info_first_symbol_reloc, |
| 5368 | .first_node_reloc = &elf.dwarf_consts.getPtr(cpi).?.debug_info_first_node_reloc, |
| 5362 | 5369 | }, |
| 5363 | 5370 | .global_debug_info => |gi| .{ |
| 5364 | 5371 | .first_symbol_reloc = &elf.dwarf_globals.items[@backingInt(gi)].debug_info_first_symbol_reloc, |
| ... | ... | @@ -5387,8 +5394,11 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void { |
| 5387 | 5394 | if (opts.first_symbol_reloc) |ptr| { |
| 5388 | 5395 | if (ptr.* != .none) { |
| 5389 | 5396 | for (elf.symbol_relocs.items[@backingInt(ptr.*)..], @backingInt(ptr.*)..) |*reloc, index| { |
| 5390 | | if (reloc.node.toOptional() == opts.skip_symbol_relocs) continue; |
| 5391 | | if (reloc.node != ni) break; |
| 5397 | if (reloc.node != ni.toOptional()) { |
| 5398 | if (reloc.node == .none) continue; |
| 5399 | if (reloc.node == opts.skip_symbol_relocs) continue; |
| 5400 | break; |
| 5401 | } |
| 5392 | 5402 | reloc.delete(elf, @fromBackingInt(@intCast(index))); |
| 5393 | 5403 | } |
| 5394 | 5404 | } |
| ... | ... | @@ -5398,8 +5408,11 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void { |
| 5398 | 5408 | if (opts.first_node_reloc) |ptr| { |
| 5399 | 5409 | if (ptr.* != .none) { |
| 5400 | 5410 | for (elf.node_relocs.items[@backingInt(ptr.*)..]) |*reloc| { |
| 5401 | | if (reloc.node.toOptional() == opts.skip_node_relocs) continue; |
| 5402 | | if (reloc.node != ni) break; |
| 5411 | if (reloc.node != ni.toOptional()) { |
| 5412 | if (reloc.node == .none) continue; |
| 5413 | if (reloc.node == opts.skip_node_relocs) continue; |
| 5414 | break; |
| 5415 | } |
| 5403 | 5416 | reloc.delete(elf); |
| 5404 | 5417 | } |
| 5405 | 5418 | } |
| ... | ... | @@ -5409,7 +5422,10 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void { |
| 5409 | 5422 | if (opts.first_got_reloc) |ptr| { |
| 5410 | 5423 | if (ptr.* != .none) { |
| 5411 | 5424 | for (elf.got_relocs.items[@backingInt(ptr.*)..]) |*reloc| { |
| 5412 | | if (reloc.node != ni.toOptional()) break; |
| 5425 | if (reloc.node != ni.toOptional()) { |
| 5426 | if (reloc.node == .none) continue; |
| 5427 | break; |
| 5428 | } |
| 5413 | 5429 | reloc.delete(elf); |
| 5414 | 5430 | } |
| 5415 | 5431 | } |
| ... | ... | @@ -5433,23 +5449,32 @@ fn flushMovedNodeRelocs( |
| 5433 | 5449 | ) void { |
| 5434 | 5450 | if (opts.first_symbol_reloc != .none) { |
| 5435 | 5451 | for (elf.symbol_relocs.items[@backingInt(opts.first_symbol_reloc)..]) |*reloc| { |
| 5436 | | if (reloc.node.toOptional() == opts.skip_symbol_relocs) continue; |
| 5437 | | if (reloc.node != node) break; |
| 5452 | if (reloc.node != node.toOptional()) { |
| 5453 | if (reloc.node == .none) continue; |
| 5454 | if (reloc.node == opts.skip_symbol_relocs) continue; |
| 5455 | break; |
| 5456 | } |
| 5438 | 5457 | reloc.flushMovedNode(elf, node_vaddr); |
| 5439 | 5458 | } |
| 5440 | 5459 | } |
| 5441 | 5460 | |
| 5442 | 5461 | if (opts.first_node_reloc != .none) { |
| 5443 | 5462 | for (elf.node_relocs.items[@backingInt(opts.first_node_reloc)..]) |*reloc| { |
| 5444 | | if (reloc.node.toOptional() == opts.skip_node_relocs) continue; |
| 5445 | | if (reloc.node != node) break; |
| 5463 | if (reloc.node != node.toOptional()) { |
| 5464 | if (reloc.node == .none) continue; |
| 5465 | if (reloc.node == opts.skip_node_relocs) continue; |
| 5466 | break; |
| 5467 | } |
| 5446 | 5468 | reloc.flushMovedNode(elf, node_vaddr); |
| 5447 | 5469 | } |
| 5448 | 5470 | } |
| 5449 | 5471 | |
| 5450 | 5472 | if (opts.first_got_reloc != .none) { |
| 5451 | 5473 | for (elf.got_relocs.items[@backingInt(opts.first_got_reloc)..]) |*reloc| { |
| 5452 | | if (reloc.node != node.toOptional()) break; |
| 5474 | if (reloc.node != node.toOptional()) { |
| 5475 | if (reloc.node == .none) continue; |
| 5476 | break; |
| 5477 | } |
| 5453 | 5478 | reloc.apply(elf); |
| 5454 | 5479 | } |
| 5455 | 5480 | } |
| ... | ... | @@ -7277,7 +7302,7 @@ fn zcuFilesReadyInner(elf: *Elf, zcu: *Zcu) Error!void { |
| 7277 | 7302 | |
| 7278 | 7303 | fn flushFiles(elf: *Elf) Error!void { |
| 7279 | 7304 | const gpa = elf.base.comp.gpa; |
| 7280 | | if (elf.shndx.debug_line != .UNDEF) for (elf.dwarf.units.keys(), elf.dwarf.units.values()) |mod, *unit| { |
| 7305 | if (elf.shndx.debug_line != .UNDEF) for (elf.dwarf.units.values()) |*unit| { |
| 7281 | 7306 | if (!unit.cleanDebugLineHeaderChanged()) continue; |
| 7282 | 7307 | const debug_line_header_ni = unit.debug_line_header_ni.unwrap().?; |
| 7283 | 7308 | try debug_line_header_ni.parent(&elf.mf).unwrap().?.nextMoved(gpa, &elf.mf); |
| ... | ... | @@ -7287,7 +7312,7 @@ fn flushFiles(elf: *Elf) Error!void { |
| 7287 | 7312 | debug_line_header_ni.writer(gpa, &elf.mf, &dlh_nw); |
| 7288 | 7313 | defer dlh_nw.deinit(); |
| 7289 | 7314 | elf.resetNodeRelocs(debug_line_header_ni); |
| 7290 | | elf.dwarf.genDebugLineHeader(mod, unit, &dlh_nw, elf.base.comp.zcu.?) catch |err| switch (err) { |
| 7315 | elf.dwarf.genDebugLineHeader(unit, &dlh_nw, elf.base.comp.zcu.?) catch |err| switch (err) { |
| 7291 | 7316 | else => |e| return e, |
| 7292 | 7317 | error.WriteFailed => return dlh_nw.err.?, |
| 7293 | 7318 | }; |
| ... | ... | @@ -7629,7 +7654,7 @@ fn addRelocAssumeCapacity( |
| 7629 | 7654 | first_target_reloc.* = ri; |
| 7630 | 7655 | if (next != .none) next.get(elf).prev = ri; |
| 7631 | 7656 | elf.symbol_relocs.appendAssumeCapacity(.{ |
| 7632 | | .node = node, |
| 7657 | .node = node.toOptional(), |
| 7633 | 7658 | .offset = offset, |
| 7634 | 7659 | .type = undefined, |
| 7635 | 7660 | .target = target, |
| ... | ... | @@ -8067,7 +8092,7 @@ fn addSymbolRelocAssumeCapacity( |
| 8067 | 8092 | first_target_reloc.* = ri; |
| 8068 | 8093 | if (next != .none) next.get(elf).prev = ri; |
| 8069 | 8094 | elf.symbol_relocs.appendAssumeCapacity(.{ |
| 8070 | | .node = node, |
| 8095 | .node = node.toOptional(), |
| 8071 | 8096 | .offset = offset, |
| 8072 | 8097 | .target = target, |
| 8073 | 8098 | .addend = addend, |
| ... | ... | @@ -8101,7 +8126,7 @@ fn addNodeRelocAssumeCapacity( |
| 8101 | 8126 | .unit_debug_info_header => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_info_header_first_target_reloc, |
| 8102 | 8127 | .unit_debug_line_header => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_line_header_first_target_reloc, |
| 8103 | 8128 | .unit_debug_rnglists => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_rnglists_first_target_reloc, |
| 8104 | | .value_debug_info => |vi| &elf.dwarf_values.items[@backingInt(vi)].debug_info_first_target_reloc, |
| 8129 | .const_debug_info => |cpi| &elf.dwarf_consts.getPtr(cpi).?.debug_info_first_target_reloc, |
| 8105 | 8130 | .global_debug_info => |gi| &elf.dwarf_globals.items[@backingInt(gi)].debug_info_first_target_reloc, |
| 8106 | 8131 | .func_debug_info => |fi| &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_target_reloc, |
| 8107 | 8132 | }; |
| ... | ... | @@ -8151,7 +8176,7 @@ fn addNodeRelocAssumeCapacity( |
| 8151 | 8176 | .addend = 0, |
| 8152 | 8177 | }); |
| 8153 | 8178 | elf.node_relocs.appendAssumeCapacity(.{ |
| 8154 | | .node = node, |
| 8179 | .node = node.toOptional(), |
| 8155 | 8180 | .offset = offset, |
| 8156 | 8181 | .type = undefined, |
| 8157 | 8182 | .target = target, |
| ... | ... | @@ -8164,7 +8189,7 @@ fn addNodeRelocAssumeCapacity( |
| 8164 | 8189 | }, |
| 8165 | 8190 | .DYN, .EXEC => { |
| 8166 | 8191 | elf.node_relocs.appendAssumeCapacity(.{ |
| 8167 | | .node = node, |
| 8192 | .node = node.toOptional(), |
| 8168 | 8193 | .offset = offset, |
| 8169 | 8194 | .target = target, |
| 8170 | 8195 | .addend = addend, |
| ... | ... | @@ -8209,7 +8234,7 @@ fn addGotRelocAssumeCapacity( |
| 8209 | 8234 | .unit_debug_line, |
| 8210 | 8235 | .unit_debug_line_header, |
| 8211 | 8236 | .unit_debug_rnglists, |
| 8212 | | .value_debug_info, |
| 8237 | .const_debug_info, |
| 8213 | 8238 | .global_debug_info, |
| 8214 | 8239 | .func_frame_fde, |
| 8215 | 8240 | .func_debug_info, |
| ... | ... | @@ -8502,7 +8527,8 @@ fn updateNavInner(elf: *Elf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) |
| 8502 | 8527 | |
| 8503 | 8528 | const nav = ip.getNav(nav_index); |
| 8504 | 8529 | if (ip.indexToKey(nav.resolved.?.value) == .@"extern") return; |
| 8505 | | if (!Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) return; |
| 8530 | if (!Type.fromInterned(nav.resolved.?.type).hasRuntimeBits(zcu)) |
| 8531 | return elf.dwarf.updateComptimeNav(pt, nav_index); |
| 8506 | 8532 | |
| 8507 | 8533 | const nmi = try elf.navMapIndex(zcu, nav_index); |
| 8508 | 8534 | const ni = nmi.symbol(elf).index().ptr(elf).node.unwrap().?; |
| ... | ... | @@ -8546,11 +8572,11 @@ pub fn updateContainerType( |
| 8546 | 8572 | |
| 8547 | 8573 | pub fn addConst( |
| 8548 | 8574 | elf: *Elf, |
| 8549 | | pt: Zcu.PerThread, |
| 8575 | _: Zcu.PerThread, |
| 8550 | 8576 | index: link.ConstPool.Index, |
| 8551 | 8577 | val: InternPool.Index, |
| 8552 | | ) std.mem.Allocator.Error!void { |
| 8553 | | if (false) try elf.dwarf.addConst(pt, index, val); |
| 8578 | ) link.Error!void { |
| 8579 | try elf.dwarf.addConst(index, val); |
| 8554 | 8580 | } |
| 8555 | 8581 | |
| 8556 | 8582 | pub fn updateConst( |
| ... | ... | @@ -8570,7 +8596,7 @@ fn updateConstInner( |
| 8570 | 8596 | ) link.Error!void { |
| 8571 | 8597 | var lazy_it = elf.lazy.iterator(); |
| 8572 | 8598 | while (lazy_it.next()) |lazy| if (lazy.value.getIndex(cpi)) |li| { |
| 8573 | | const lazy_ty: Type = .fromInterned(cpi.val(&elf.dwarf.const_pool)); |
| 8599 | const lazy_ty: Type = .fromInterned(val); |
| 8574 | 8600 | var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined; |
| 8575 | 8601 | const prog_name: []const u8 = switch (lazy_ty.zigTypeTag(pt.zcu)) { |
| 8576 | 8602 | .@"enum" => std.mem.print(&prog_name_buf, "@tagName({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf, |
| ... | ... | @@ -8590,16 +8616,20 @@ fn updateConstInner( |
| 8590 | 8616 | ), |
| 8591 | 8617 | }; |
| 8592 | 8618 | }; |
| 8593 | | if (false) try elf.dwarf.updateConst(pt, cpi, val); |
| 8619 | elf.dwarf.updateConst(cpi, val); |
| 8594 | 8620 | } |
| 8595 | 8621 | |
| 8596 | 8622 | pub fn updateConstIncomplete( |
| 8597 | 8623 | elf: *Elf, |
| 8598 | | pt: Zcu.PerThread, |
| 8624 | _: Zcu.PerThread, |
| 8599 | 8625 | cpi: link.ConstPool.Index, |
| 8600 | 8626 | val: InternPool.Index, |
| 8601 | 8627 | ) link.Error!void { |
| 8602 | | if (false) try elf.dwarf.updateConstIncomplete(pt, cpi, val); |
| 8628 | const debug_info_ni = Dwarf.Const.get(cpi, &elf.dwarf).debug_info_ni.unwrap().?; |
| 8629 | var di_nw: MappedFile.Node.Writer = undefined; |
| 8630 | debug_info_ni.writer(elf.base.comp.gpa, &elf.mf, &di_nw); |
| 8631 | defer di_nw.deinit(); |
| 8632 | try elf.dwarf.updateConstIncomplete(&di_nw, val); |
| 8603 | 8633 | } |
| 8604 | 8634 | |
| 8605 | 8635 | pub fn updateFunc( |
| ... | ... | @@ -8770,7 +8800,7 @@ fn updateFuncInner( |
| 8770 | 8800 | elf.resetNodeRelocs(dwarf_func.debug_line_ni.unwrap().?); |
| 8771 | 8801 | try debug.startDebugLine(); |
| 8772 | 8802 | elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?); |
| 8773 | | try debug.startDebugInfo(); |
| 8803 | try debug.startFuncDebugInfo(); |
| 8774 | 8804 | }, |
| 8775 | 8805 | .none => {}, |
| 8776 | 8806 | } |
| ... | ... | @@ -9187,7 +9217,7 @@ fn idleProgNode( |
| 9187 | 9217 | }, |
| 9188 | 9218 | ui.mod(&elf.dwarf).fully_qualified_name, |
| 9189 | 9219 | }) catch &name, |
| 9190 | | .value_debug_info => |cpi| std.mem.print(&name, "debug info for {f}", .{ |
| 9220 | .const_debug_info => |cpi| std.mem.print(&name, "debug info for {f}", .{ |
| 9191 | 9221 | Value.fromInterned(cpi.val(&elf.dwarf.const_pool)) |
| 9192 | 9222 | .fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }), |
| 9193 | 9223 | }) catch &name, |
| ... | ... | @@ -9648,14 +9678,14 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void |
| 9648 | 9678 | const node_vaddr = elf.computeNodeVAddr(ni); |
| 9649 | 9679 | for (dwarf_unit.debug_rnglists_symbol_relocs.keys()) |symbol_ri| { |
| 9650 | 9680 | const symbol_reloc = symbol_ri.get(elf); |
| 9651 | | assert(symbol_reloc.node == ni); |
| 9681 | assert(symbol_reloc.node.unwrap().? == ni); |
| 9652 | 9682 | symbol_reloc.flushMovedNode(elf, node_vaddr); |
| 9653 | 9683 | } |
| 9654 | 9684 | }, |
| 9655 | | .value_debug_info => |vi| { |
| 9656 | | const dwarf_value = &elf.dwarf_values.items[@backingInt(vi)]; |
| 9685 | .const_debug_info => |cpi| { |
| 9686 | const dwarf_const = &elf.dwarf_consts.get(cpi).?; |
| 9657 | 9687 | const target_section_offset = elf.computeNodeSectionOffset(ni); |
| 9658 | | var target_ri = dwarf_value.debug_info_first_target_reloc; |
| 9688 | var target_ri = dwarf_const.debug_info_first_target_reloc; |
| 9659 | 9689 | while (target_ri != .none) { |
| 9660 | 9690 | const target_reloc = target_ri.get(elf); |
| 9661 | 9691 | assert(target_reloc.target == ni); |
| ... | ... | @@ -9663,12 +9693,12 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void |
| 9663 | 9693 | target_ri = target_reloc.next; |
| 9664 | 9694 | } |
| 9665 | 9695 | elf.flushMovedNodeRelocs(ni, elf.computeNodeVAddr(ni), .{ |
| 9666 | | .first_symbol_reloc = dwarf_value.debug_info_first_symbol_reloc, |
| 9667 | | .first_node_reloc = dwarf_value.debug_info_first_node_reloc, |
| 9696 | .first_symbol_reloc = dwarf_const.debug_info_first_symbol_reloc, |
| 9697 | .first_node_reloc = dwarf_const.debug_info_first_node_reloc, |
| 9668 | 9698 | }); |
| 9669 | 9699 | }, |
| 9670 | | .global_debug_info => |vi| { |
| 9671 | | const dwarf_global = &elf.dwarf_globals.items[@backingInt(vi)]; |
| 9700 | .global_debug_info => |gi| { |
| 9701 | const dwarf_global = &elf.dwarf_globals.items[@backingInt(gi)]; |
| 9672 | 9702 | const target_section_offset = elf.computeNodeSectionOffset(ni); |
| 9673 | 9703 | var target_ri = dwarf_global.debug_info_first_target_reloc; |
| 9674 | 9704 | while (target_ri != .none) { |
| ... | ... | @@ -9972,7 +10002,7 @@ fn flushResized(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo |
| 9972 | 10002 | .unit_debug_line, |
| 9973 | 10003 | .unit_debug_line_header, |
| 9974 | 10004 | .unit_debug_rnglists, |
| 9975 | | .value_debug_info, |
| 10005 | .const_debug_info, |
| 9976 | 10006 | .global_debug_info, |
| 9977 | 10007 | .func_frame_fde, |
| 9978 | 10008 | .func_debug_info, |
| ... | ... | @@ -10036,7 +10066,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error! |
| 10036 | 10066 | .unit_debug_info_header, |
| 10037 | 10067 | .unit_debug_line_header, |
| 10038 | 10068 | .unit_debug_rnglists, |
| 10039 | | .value_debug_info, |
| 10069 | .const_debug_info, |
| 10040 | 10070 | .global_debug_info, |
| 10041 | 10071 | .func_frame_fde, |
| 10042 | 10072 | .func_debug_info, |
| ... | ... | @@ -10089,7 +10119,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error! |
| 10089 | 10119 | }, |
| 10090 | 10120 | .unit_debug_info_header, |
| 10091 | 10121 | .unit_debug_line_header, |
| 10092 | | .value_debug_info, |
| 10122 | .const_debug_info, |
| 10093 | 10123 | .global_debug_info, |
| 10094 | 10124 | .func_debug_info, |
| 10095 | 10125 | .func_debug_line, |
| ... | ... | @@ -10105,7 +10135,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error! |
| 10105 | 10135 | switch (tag) { |
| 10106 | 10136 | else => unreachable, |
| 10107 | 10137 | .unit_debug_info_header, |
| 10108 | | .value_debug_info, |
| 10138 | .const_debug_info, |
| 10109 | 10139 | .global_debug_info, |
| 10110 | 10140 | .func_debug_info, |
| 10111 | 10141 | => for (0..2) |_| fw.writeUleb128(@backingInt(Dwarf.AbbrevCode.null)) catch unreachable, |
| ... | ... | @@ -10119,7 +10149,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error! |
| 10119 | 10149 | elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len); |
| 10120 | 10150 | switch (tag) { |
| 10121 | 10151 | else => unreachable, |
| 10122 | | .unit_debug_info_header, .value_debug_info, .global_debug_info, .func_debug_info => { |
| 10152 | .unit_debug_info_header, .const_debug_info, .global_debug_info, .func_debug_info => { |
| 10123 | 10153 | comptime assert(Dwarf.uleb128Size(@backingInt(Dwarf.AbbrevCode.null)) == 1); |
| 10124 | 10154 | @memset(fw.unusedCapacitySlice(), @backingInt(Dwarf.AbbrevCode.null)); |
| 10125 | 10155 | }, |
| ... | ... | @@ -10143,7 +10173,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error! |
| 10143 | 10173 | @memset(fw.buffer, std.dwarf.CFA.nop); |
| 10144 | 10174 | }, |
| 10145 | 10175 | .unit_debug_info_header, |
| 10146 | | .value_debug_info, |
| 10176 | .const_debug_info, |
| 10147 | 10177 | .global_debug_info, |
| 10148 | 10178 | .func_debug_info, |
| 10149 | 10179 | => elf.dwarf.genDebugInfoPadding(&fw, fw.buffer.len) catch unreachable, |
| ... | ... | @@ -10693,9 +10723,11 @@ pub fn printNode( |
| 10693 | 10723 | .unit_debug_line_header, |
| 10694 | 10724 | .unit_debug_rnglists, |
| 10695 | 10725 | => |ui| try w.print("({s})", .{ui.mod(&elf.dwarf).fully_qualified_name}), |
| 10696 | | .value_debug_info => |cpi| try w.print("({f})", .{ |
| 10697 | | Value.fromInterned(cpi.val(&elf.dwarf.const_pool)) |
| 10698 | | .fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }), |
| 10726 | .const_debug_info => |cpi| try w.print("({f})", .{ |
| 10727 | Value.fromInterned(cpi.val(&elf.dwarf.const_pool)).fmtValue(.{ |
| 10728 | .zcu = elf.base.comp.zcu.?, |
| 10729 | .tid = tid, |
| 10730 | }), |
| 10699 | 10731 | }), |
| 10700 | 10732 | .global_debug_info => |gi| { |
| 10701 | 10733 | const zcu = elf.base.comp.zcu.?; |