| ... | ... | @@ -42,11 +42,15 @@ shndx: struct { |
| 42 | 42 | tdata: Section.Index, |
| 43 | 43 | rela_dyn: Section.Index, |
| 44 | 44 | rela_plt: Section.Index, |
| 45 | debug_abbrev: Section.Index, |
| 45 | 46 | eh_frame_hdr: Section.Index, |
| 46 | 47 | eh_frame: Section.Index, |
| 47 | 48 | debug_frame: Section.Index, |
| 48 | 49 | debug_info: Section.Index, |
| 49 | 50 | debug_line: Section.Index, |
| 51 | debug_line_str: Section.Index, |
| 52 | debug_str: Section.Index, |
| 53 | debug_str_offsets: Section.Index, |
| 50 | 54 | // These sections are created only as needed, and are initially `.UNDEF`. |
| 51 | 55 | init_array: Section.Index, |
| 52 | 56 | fini_array: Section.Index, |
| ... | ... | @@ -199,14 +203,34 @@ changed_symtab_index: std.array_hash_map.Auto(String(.strtab), void), |
| 199 | 203 | textrel_count: u32, |
| 200 | 204 | |
| 201 | 205 | dwarf: Dwarf, |
| 206 | dwarf_shared: std.enums.EnumArray(Dwarf.SharedSection, struct { |
| 207 | first_target_reloc: NodeReloc.Index, |
| 208 | }), |
| 202 | 209 | dwarf_units: std.ArrayList(struct { |
| 203 | | unit_frame_cie_first_target_reloc: NodeReloc.Index, |
| 210 | frame_cie_first_target_reloc: NodeReloc.Index, |
| 211 | debug_info_header_first_target_reloc: NodeReloc.Index, |
| 212 | debug_info_header_first_node_reloc: NodeReloc.Index, |
| 213 | debug_line_header_first_target_reloc: NodeReloc.Index, |
| 214 | debug_line_header_first_node_reloc: NodeReloc.Index, |
| 215 | }), |
| 216 | dwarf_values: std.ArrayList(struct { |
| 217 | debug_info_first_target_reloc: NodeReloc.Index, |
| 218 | debug_info_first_symbol_reloc: SymbolReloc.Index, |
| 219 | debug_info_first_node_reloc: NodeReloc.Index, |
| 220 | }), |
| 221 | dwarf_globals: std.ArrayList(struct { |
| 222 | debug_info_first_target_reloc: NodeReloc.Index, |
| 223 | debug_info_first_symbol_reloc: SymbolReloc.Index, |
| 224 | debug_info_first_node_reloc: NodeReloc.Index, |
| 204 | 225 | }), |
| 205 | | dwarf_values: std.ArrayList(struct {}), |
| 206 | | dwarf_globals: std.ArrayList(struct {}), |
| 207 | 226 | dwarf_funcs: std.ArrayList(struct { |
| 208 | | func_frame_fde_first_symbol_reloc: SymbolReloc.Index, |
| 209 | | func_frame_fde_first_node_reloc: NodeReloc.Index, |
| 227 | frame_fde_first_symbol_reloc: SymbolReloc.Index, |
| 228 | frame_fde_first_node_reloc: NodeReloc.Index, |
| 229 | debug_info_first_target_reloc: NodeReloc.Index, |
| 230 | debug_info_first_symbol_reloc: SymbolReloc.Index, |
| 231 | debug_info_first_node_reloc: NodeReloc.Index, |
| 232 | debug_line_first_symbol_reloc: SymbolReloc.Index, |
| 233 | debug_line_first_node_reloc: NodeReloc.Index, |
| 210 | 234 | }), |
| 211 | 235 | |
| 212 | 236 | overflowed_reloc_count: u32, |
| ... | ... | @@ -272,11 +296,17 @@ const Node = union(enum) { |
| 272 | 296 | /// May contain relocations. |
| 273 | 297 | lazy_const_data: LazyMapRef.Index(.const_data), |
| 274 | 298 | |
| 275 | | value_debug_info: link.ConstPool.Index, |
| 276 | | global_debug_info: Dwarf.Global.Index, |
| 277 | | frame_padding, |
| 299 | debug_shared: Dwarf.SharedSection, |
| 300 | unit_padding, |
| 278 | 301 | unit_frame: Dwarf.Unit.Index, |
| 279 | 302 | unit_frame_cie: Dwarf.Unit.Index, |
| 303 | unit_debug_info: Dwarf.Unit.Index, |
| 304 | unit_debug_info_header: Dwarf.Unit.Index, |
| 305 | unit_debug_line: Dwarf.Unit.Index, |
| 306 | unit_debug_line_header: Dwarf.Unit.Index, |
| 307 | |
| 308 | value_debug_info: link.ConstPool.Index, |
| 309 | global_debug_info: Dwarf.Global.Index, |
| 280 | 310 | func_frame_fde: Dwarf.Func.Index, |
| 281 | 311 | func_debug_info: Dwarf.Func.Index, |
| 282 | 312 | func_debug_line: Dwarf.Func.Index, |
| ... | ... | @@ -1778,7 +1808,9 @@ const NodeReloc = struct { |
| 1778 | 1808 | .none => { |
| 1779 | 1809 | const first_target_reloc = switch (elf.getNode(reloc.target)) { |
| 1780 | 1810 | else => unreachable, |
| 1781 | | .unit_frame_cie => |ui| &elf.dwarf_units.items[@backingInt(ui)].unit_frame_cie_first_target_reloc, |
| 1811 | .unit_frame_cie => |ui| &elf.dwarf_units.items[@backingInt(ui)].frame_cie_first_target_reloc, |
| 1812 | .unit_debug_info_header => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_info_header_first_target_reloc, |
| 1813 | .unit_debug_line_header => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_line_header_first_target_reloc, |
| 1782 | 1814 | }; |
| 1783 | 1815 | first_target_reloc.* = reloc.next; |
| 1784 | 1816 | }, |
| ... | ... | @@ -3218,11 +3250,16 @@ pub fn symbolForAtom(elf: *Elf, atom: link.File.AtomId) link.File.SymbolId { |
| 3218 | 3250 | .section_manual_size, |
| 3219 | 3251 | .input_section, |
| 3220 | 3252 | .copied_global, |
| 3221 | | .value_debug_info, |
| 3222 | | .global_debug_info, |
| 3223 | | .frame_padding, |
| 3253 | .debug_shared, |
| 3254 | .unit_padding, |
| 3224 | 3255 | .unit_frame, |
| 3225 | 3256 | .unit_frame_cie, |
| 3257 | .unit_debug_info, |
| 3258 | .unit_debug_info_header, |
| 3259 | .unit_debug_line, |
| 3260 | .unit_debug_line_header, |
| 3261 | .value_debug_info, |
| 3262 | .global_debug_info, |
| 3226 | 3263 | .func_frame_fde, |
| 3227 | 3264 | .func_debug_info, |
| 3228 | 3265 | .func_debug_line, |
| ... | ... | @@ -3661,11 +3698,15 @@ fn create( |
| 3661 | 3698 | .tdata = .UNDEF, |
| 3662 | 3699 | .rela_dyn = .UNDEF, |
| 3663 | 3700 | .rela_plt = .UNDEF, |
| 3701 | .debug_abbrev = .UNDEF, |
| 3664 | 3702 | .eh_frame_hdr = .UNDEF, |
| 3665 | 3703 | .eh_frame = .UNDEF, |
| 3666 | 3704 | .debug_frame = .UNDEF, |
| 3667 | 3705 | .debug_info = .UNDEF, |
| 3668 | 3706 | .debug_line = .UNDEF, |
| 3707 | .debug_line_str = .UNDEF, |
| 3708 | .debug_str = .UNDEF, |
| 3709 | .debug_str_offsets = .UNDEF, |
| 3669 | 3710 | .init_array = .UNDEF, |
| 3670 | 3711 | .fini_array = .UNDEF, |
| 3671 | 3712 | .preinit_array = .UNDEF, |
| ... | ... | @@ -3720,6 +3761,9 @@ fn create( |
| 3720 | 3761 | .dwarf => |v| v, |
| 3721 | 3762 | .code_view => unreachable, |
| 3722 | 3763 | }), |
| 3764 | .dwarf_shared = .initFill(.{ |
| 3765 | .first_target_reloc = .none, |
| 3766 | }), |
| 3723 | 3767 | .dwarf_units = .empty, |
| 3724 | 3768 | .dwarf_values = .empty, |
| 3725 | 3769 | .dwarf_globals = .empty, |
| ... | ... | @@ -3774,7 +3818,7 @@ pub fn deinit(elf: *Elf) void { |
| 3774 | 3818 | elf.section_by_name.deinit(gpa); |
| 3775 | 3819 | elf.changed_symtab_index.deinit(gpa); |
| 3776 | 3820 | |
| 3777 | | elf.dwarf.deinit(gpa); |
| 3821 | elf.dwarf.deinit(); |
| 3778 | 3822 | elf.dwarf_units.deinit(gpa); |
| 3779 | 3823 | elf.dwarf_values.deinit(gpa); |
| 3780 | 3824 | elf.dwarf_globals.deinit(gpa); |
| ... | ... | @@ -3851,9 +3895,13 @@ fn initHeaders( |
| 3851 | 3895 | switch (comp.config.debug_format) { |
| 3852 | 3896 | .strip => {}, |
| 3853 | 3897 | .dwarf => { |
| 3898 | shnum += 1; // .debug_abbrev |
| 3854 | 3899 | shnum += @intFromBool(have_debug_frame); // .debug_frame |
| 3855 | 3900 | shnum += 1; // .debug_info |
| 3856 | 3901 | shnum += 1; // .debug_line |
| 3902 | shnum += 1; // .debug_line_str |
| 3903 | shnum += 1; // .debug_str |
| 3904 | shnum += 1; // .debug_str_offsets |
| 3857 | 3905 | }, |
| 3858 | 3906 | .code_view => unreachable, |
| 3859 | 3907 | } |
| ... | ... | @@ -4942,6 +4990,7 @@ fn initHeaders( |
| 4942 | 4990 | switch (comp.config.debug_format) { |
| 4943 | 4991 | .strip => {}, |
| 4944 | 4992 | .dwarf => { |
| 4993 | elf.shndx.debug_abbrev = try elf.addSection(elf.ni.elf, .{ .name = ".debug_abbrev" }); |
| 4945 | 4994 | if (have_debug_frame) elf.shndx.debug_frame = try elf.addSection(elf.ni.elf, .{ |
| 4946 | 4995 | .name = ".debug_frame", |
| 4947 | 4996 | .addralign = addr_align, |
| ... | ... | @@ -4955,6 +5004,17 @@ fn initHeaders( |
| 4955 | 5004 | .name = ".debug_line", |
| 4956 | 5005 | .node_align = elf.mf.flags.block_size, |
| 4957 | 5006 | }); |
| 5007 | elf.shndx.debug_line_str = try elf.addSection(elf.ni.elf, .{ |
| 5008 | .name = ".debug_line_str", |
| 5009 | .flags = .{ .MERGE = true, .STRINGS = true }, |
| 5010 | }); |
| 5011 | elf.shndx.debug_str = try elf.addSection(elf.ni.elf, .{ |
| 5012 | .name = ".debug_str", |
| 5013 | .flags = .{ .MERGE = true, .STRINGS = true }, |
| 5014 | }); |
| 5015 | elf.shndx.debug_str_offsets = try elf.addSection(elf.ni.elf, .{ |
| 5016 | .name = ".debug_str_offsets", |
| 5017 | }); |
| 4958 | 5018 | }, |
| 4959 | 5019 | .code_view => unreachable, |
| 4960 | 5020 | } |
| ... | ... | @@ -5045,11 +5105,6 @@ fn getNodeShndx(elf: *const Elf, ni: MappedFile.Node.Index) Section.Index { |
| 5045 | 5105 | .ehdr, |
| 5046 | 5106 | .shdr, |
| 5047 | 5107 | .segment, |
| 5048 | | .value_debug_info, |
| 5049 | | .global_debug_info, |
| 5050 | | .frame_padding, |
| 5051 | | .func_debug_info, |
| 5052 | | .func_debug_line, |
| 5053 | 5108 | => unreachable, |
| 5054 | 5109 | .section, .section_manual_size => |shndx| shndx, |
| 5055 | 5110 | .input_section, |
| ... | ... | @@ -5058,13 +5113,21 @@ fn getNodeShndx(elf: *const Elf, ni: MappedFile.Node.Index) Section.Index { |
| 5058 | 5113 | .uav, |
| 5059 | 5114 | .lazy_code, |
| 5060 | 5115 | .lazy_const_data, |
| 5116 | .debug_shared, |
| 5117 | .unit_padding, |
| 5061 | 5118 | .unit_frame, |
| 5119 | .unit_debug_info, |
| 5120 | .unit_debug_line, |
| 5062 | 5121 | => elf.getNode(ni.parent(&elf.mf).unwrap().?).section, |
| 5063 | | .unit_frame_cie, .func_frame_fde => { |
| 5064 | | const unit_frame_ni = ni.parent(&elf.mf).unwrap().?; |
| 5065 | | assert(elf.getNode(unit_frame_ni) == .unit_frame); |
| 5066 | | return elf.getNode(unit_frame_ni.parent(&elf.mf).unwrap().?).section; |
| 5067 | | }, |
| 5122 | .unit_frame_cie, |
| 5123 | .unit_debug_info_header, |
| 5124 | .unit_debug_line_header, |
| 5125 | .value_debug_info, |
| 5126 | .global_debug_info, |
| 5127 | .func_frame_fde, |
| 5128 | .func_debug_info, |
| 5129 | .func_debug_line, |
| 5130 | => elf.getNode(ni.parent(&elf.mf).unwrap().?.parent(&elf.mf).unwrap().?).section, |
| 5068 | 5131 | }; |
| 5069 | 5132 | } |
| 5070 | 5133 | fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 { |
| ... | ... | @@ -5078,11 +5141,6 @@ fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 { |
| 5078 | 5141 | .shdr, |
| 5079 | 5142 | .segment, |
| 5080 | 5143 | .copied_global, |
| 5081 | | .value_debug_info, |
| 5082 | | .global_debug_info, |
| 5083 | | .frame_padding, |
| 5084 | | .func_debug_info, |
| 5085 | | .func_debug_line, |
| 5086 | 5144 | => unreachable, |
| 5087 | 5145 | .section, .section_manual_size => |shndx| shndx.vaddr(elf), |
| 5088 | 5146 | .input_section => |isi| isi.ptrConst(elf).vaddr, |
| ... | ... | @@ -5091,7 +5149,20 @@ fn getNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 { |
| 5091 | 5149 | .lazy_code, |
| 5092 | 5150 | .lazy_const_data, |
| 5093 | 5151 | => |i| Symbol.Id.local(i.symbol(elf)).value(elf), |
| 5094 | | .unit_frame, .unit_frame_cie, .func_frame_fde => elf.computeNodeVAddr(ni), |
| 5152 | .debug_shared, |
| 5153 | .unit_padding, |
| 5154 | .unit_frame, |
| 5155 | .unit_frame_cie, |
| 5156 | .unit_debug_info, |
| 5157 | .unit_debug_info_header, |
| 5158 | .unit_debug_line, |
| 5159 | .unit_debug_line_header, |
| 5160 | .value_debug_info, |
| 5161 | .global_debug_info, |
| 5162 | .func_frame_fde, |
| 5163 | .func_debug_info, |
| 5164 | .func_debug_line, |
| 5165 | => elf.computeNodeVAddr(ni), |
| 5095 | 5166 | }; |
| 5096 | 5167 | } |
| 5097 | 5168 | fn computeNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 { |
| ... | ... | @@ -5110,16 +5181,17 @@ fn computeNodeVAddr(elf: *Elf, ni: MappedFile.Node.Index) u64 { |
| 5110 | 5181 | .lazy_code, |
| 5111 | 5182 | .lazy_const_data, |
| 5112 | 5183 | => |i| Symbol.Id.local(i.symbol(elf)).value(elf), |
| 5113 | | .value_debug_info, |
| 5114 | | .global_debug_info, |
| 5115 | | .frame_padding, |
| 5116 | | => unreachable, |
| 5117 | | .unit_frame => { |
| 5184 | .debug_shared, .unit_padding => unreachable, |
| 5185 | .unit_frame, .unit_debug_info, .unit_debug_line => { |
| 5118 | 5186 | const section_ni = parent_ni.parent(&elf.mf).unwrap().?; |
| 5119 | 5187 | const section_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf); |
| 5120 | 5188 | break :parent_vaddr elf.getNode(section_ni).section.vaddr(elf) + section_offset; |
| 5121 | 5189 | }, |
| 5122 | 5190 | .unit_frame_cie, |
| 5191 | .unit_debug_info_header, |
| 5192 | .unit_debug_line_header, |
| 5193 | .value_debug_info, |
| 5194 | .global_debug_info, |
| 5123 | 5195 | .func_frame_fde, |
| 5124 | 5196 | .func_debug_info, |
| 5125 | 5197 | .func_debug_line, |
| ... | ... | @@ -5138,7 +5210,7 @@ fn getNodeElfOffset(elf: *Elf, ni: MappedFile.Node.Index) u64 { |
| 5138 | 5210 | /// Asserts that `ni` must be a node which supports relocations (see `Elf.Node`). Does not support |
| 5139 | 5211 | /// the special-case sections '.plt', '.dynamic', and '.eh_frame_hdr'. |
| 5140 | 5212 | fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void { |
| 5141 | | const symbol_relocs: *SymbolReloc.Index, const node_relocs: ?*NodeReloc.Index, const got_relocs: ?*GotReloc.Index = switch (elf.getNode(ni)) { |
| 5213 | const symbol_relocs: ?*SymbolReloc.Index, const node_relocs: ?*NodeReloc.Index, const got_relocs: ?*GotReloc.Index = switch (elf.getNode(ni)) { |
| 5142 | 5214 | .archive, |
| 5143 | 5215 | .archive_header, |
| 5144 | 5216 | .archive_input_member, |
| ... | ... | @@ -5148,13 +5220,12 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void { |
| 5148 | 5220 | .shdr, |
| 5149 | 5221 | .segment, |
| 5150 | 5222 | .copied_global, |
| 5151 | | .value_debug_info, |
| 5152 | | .global_debug_info, |
| 5153 | | .frame_padding, |
| 5223 | .debug_shared, |
| 5224 | .unit_padding, |
| 5154 | 5225 | .unit_frame, |
| 5155 | 5226 | .unit_frame_cie, |
| 5156 | | .func_debug_info, |
| 5157 | | .func_debug_line, |
| 5227 | .unit_debug_info, |
| 5228 | .unit_debug_line, |
| 5158 | 5229 | => unreachable, // cannot contain relocs |
| 5159 | 5230 | .section, |
| 5160 | 5231 | .section_manual_size, |
| ... | ... | @@ -5179,23 +5250,52 @@ fn resetNodeRelocs(elf: *Elf, ni: MappedFile.Node.Index) void { |
| 5179 | 5250 | null, |
| 5180 | 5251 | &elf.lazy.getPtr(lmi.ref().kind).map.values()[lmi.ref().index].first_got_reloc, |
| 5181 | 5252 | }, |
| 5253 | .unit_debug_info_header => |ui| .{ |
| 5254 | null, |
| 5255 | &elf.dwarf_units.items[@backingInt(ui)].debug_info_header_first_node_reloc, |
| 5256 | null, |
| 5257 | }, |
| 5258 | .unit_debug_line_header => |ui| .{ |
| 5259 | null, |
| 5260 | &elf.dwarf_units.items[@backingInt(ui)].debug_line_header_first_node_reloc, |
| 5261 | null, |
| 5262 | }, |
| 5263 | .value_debug_info => |vi| .{ |
| 5264 | &elf.dwarf_values.items[@backingInt(vi)].debug_info_first_symbol_reloc, |
| 5265 | &elf.dwarf_values.items[@backingInt(vi)].debug_info_first_node_reloc, |
| 5266 | null, |
| 5267 | }, |
| 5268 | .global_debug_info => |gi| .{ |
| 5269 | &elf.dwarf_globals.items[@backingInt(gi)].debug_info_first_symbol_reloc, |
| 5270 | &elf.dwarf_globals.items[@backingInt(gi)].debug_info_first_node_reloc, |
| 5271 | null, |
| 5272 | }, |
| 5182 | 5273 | .func_frame_fde => |fi| .{ |
| 5183 | | &elf.dwarf_funcs.items[@backingInt(fi)].func_frame_fde_first_symbol_reloc, |
| 5184 | | &elf.dwarf_funcs.items[@backingInt(fi)].func_frame_fde_first_node_reloc, |
| 5274 | &elf.dwarf_funcs.items[@backingInt(fi)].frame_fde_first_symbol_reloc, |
| 5275 | &elf.dwarf_funcs.items[@backingInt(fi)].frame_fde_first_node_reloc, |
| 5276 | null, |
| 5277 | }, |
| 5278 | .func_debug_info => |fi| .{ |
| 5279 | &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_symbol_reloc, |
| 5280 | &elf.dwarf_funcs.items[@backingInt(fi)].debug_info_first_node_reloc, |
| 5281 | null, |
| 5282 | }, |
| 5283 | .func_debug_line => |fi| .{ |
| 5284 | &elf.dwarf_funcs.items[@backingInt(fi)].debug_line_first_symbol_reloc, |
| 5285 | &elf.dwarf_funcs.items[@backingInt(fi)].debug_line_first_node_reloc, |
| 5185 | 5286 | null, |
| 5186 | 5287 | }, |
| 5187 | 5288 | }; |
| 5188 | 5289 | |
| 5189 | | if (symbol_relocs.* != .none) { |
| 5190 | | for ( |
| 5191 | | elf.symbol_relocs.items[@backingInt(symbol_relocs.*)..], |
| 5192 | | @backingInt(symbol_relocs.*).., |
| 5193 | | ) |*reloc, index| { |
| 5194 | | if (reloc.node != ni) break; |
| 5195 | | reloc.delete(elf, @fromBackingInt(@intCast(index))); |
| 5290 | if (symbol_relocs) |ptr| { |
| 5291 | if (ptr.* != .none) { |
| 5292 | for (elf.symbol_relocs.items[@backingInt(ptr.*)..], @backingInt(ptr.*)..) |*reloc, index| { |
| 5293 | if (reloc.node != ni) break; |
| 5294 | reloc.delete(elf, @fromBackingInt(@intCast(index))); |
| 5295 | } |
| 5196 | 5296 | } |
| 5297 | ptr.* = @fromBackingInt(@intCast(elf.symbol_relocs.items.len)); |
| 5197 | 5298 | } |
| 5198 | | symbol_relocs.* = @fromBackingInt(@intCast(elf.symbol_relocs.items.len)); |
| 5199 | 5299 | |
| 5200 | 5300 | if (node_relocs) |ptr| { |
| 5201 | 5301 | if (ptr.* != .none) { |
| ... | ... | @@ -5962,7 +6062,7 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load |
| 5962 | 6062 | return error.BadMagic; |
| 5963 | 6063 | } |
| 5964 | 6064 | } |
| 5965 | | var strtab: std.Io.Writer.Allocating = .init(gpa); |
| 6065 | var strtab: Io.Writer.Allocating = .init(gpa); |
| 5966 | 6066 | defer strtab.deinit(); |
| 5967 | 6067 | while (r.takeStruct(std.elf.ar_hdr, .native)) |header| { |
| 5968 | 6068 | if (!std.mem.eql(u8, &header.ar_fmag, std.elf.ARFMAG)) |
| ... | ... | @@ -6013,7 +6113,7 @@ fn loadArchive(elf: *Elf, path: std.Build.Cache.Path, fr: *Io.File.Reader) (Load |
| 6013 | 6113 | fn fmtMemberString(member: ?[]const u8) std.fmt.Alt(?[]const u8, memberStringEscape) { |
| 6014 | 6114 | return .{ .data = member }; |
| 6015 | 6115 | } |
| 6016 | | fn memberStringEscape(member: ?[]const u8, w: *std.Io.Writer) std.Io.Writer.Error!void { |
| 6116 | fn memberStringEscape(member: ?[]const u8, w: *Io.Writer) Io.Writer.Error!void { |
| 6017 | 6117 | try w.print("({f})", .{std.zig.fmtString(member orelse return)}); |
| 6018 | 6118 | } |
| 6019 | 6119 | fn loadObject( |
| ... | ... | @@ -6897,7 +6997,6 @@ pub fn prelink(elf: *Elf, prog_node: std.Progress.Node) link.Error!void { |
| 6897 | 6997 | fn prelinkInner(elf: *Elf) Error!void { |
| 6898 | 6998 | const comp = elf.base.comp; |
| 6899 | 6999 | const gpa = comp.gpa; |
| 6900 | | |
| 6901 | 7000 | if (comp.zcu) |zcu| self_hosted_codegen: { |
| 6902 | 7001 | if (comp.config.use_llvm) break :self_hosted_codegen; |
| 6903 | 7002 | |
| ... | ... | @@ -6922,35 +7021,130 @@ fn prelinkInner(elf: *Elf) Error!void { |
| 6922 | 7021 | elf.input_pending_index += 1; |
| 6923 | 7022 | |
| 6924 | 7023 | try elf.dwarf.initUnits(zcu); |
| 7024 | try elf.nodes.ensureUnusedCapacity(gpa, 4 + 4 + (4 + 4) * elf.dwarf.units.count()); |
| 6925 | 7025 | try elf.dwarf_units.appendNTimes(gpa, .{ |
| 6926 | | .unit_frame_cie_first_target_reloc = .none, |
| 7026 | .frame_cie_first_target_reloc = .none, |
| 7027 | .debug_info_header_first_target_reloc = .none, |
| 7028 | .debug_info_header_first_node_reloc = .none, |
| 7029 | .debug_line_header_first_target_reloc = .none, |
| 7030 | .debug_line_header_first_node_reloc = .none, |
| 6927 | 7031 | }, elf.dwarf.units.count()); |
| 6928 | 7032 | |
| 6929 | | try elf.nodes.ensureUnusedCapacity(gpa, 2); |
| 6930 | | for ( |
| 6931 | | [2]Dwarf.Frame.Format{ .eh_frame, .debug_frame }, |
| 6932 | | [2]Section.Index{ elf.shndx.eh_frame, elf.shndx.debug_frame }, |
| 6933 | | ) |format, frame_shndx| { |
| 6934 | | if (frame_shndx == .UNDEF) continue; |
| 6935 | | const frame_ni = frame_shndx.get(elf).ni; |
| 6936 | | _ = frame_ni.last(&elf.mf).unwrap() orelse continue; |
| 6937 | | const frame_padding_ni = try frame_ni.addFloatingChild(&elf.mf, gpa, .{ |
| 6938 | | .alignment = switch (elf.identClass()) { |
| 7033 | elf.dwarf.debug_abbrev.ni = |
| 7034 | .wrap(try elf.shndx.debug_abbrev.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{})); |
| 7035 | elf.nodes.appendAssumeCapacity(.{ .debug_shared = .debug_abbrev }); |
| 7036 | |
| 7037 | elf.dwarf.debug_line_str.ni = |
| 7038 | .wrap(try elf.shndx.debug_line_str.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{})); |
| 7039 | elf.nodes.appendAssumeCapacity(.{ .debug_shared = .debug_line_str }); |
| 7040 | |
| 7041 | elf.dwarf.debug_str.ni = |
| 7042 | .wrap(try elf.shndx.debug_str.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{})); |
| 7043 | elf.nodes.appendAssumeCapacity(.{ .debug_shared = .debug_str }); |
| 7044 | |
| 7045 | elf.dwarf.debug_str_offsets.ni = |
| 7046 | .wrap(try elf.shndx.debug_str_offsets.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{})); |
| 7047 | elf.nodes.appendAssumeCapacity(.{ .debug_shared = .debug_str_offsets }); |
| 7048 | |
| 7049 | for ([4]Section.Index{ |
| 7050 | elf.shndx.eh_frame, |
| 7051 | elf.shndx.debug_frame, |
| 7052 | elf.shndx.debug_info, |
| 7053 | elf.shndx.debug_line, |
| 7054 | }) |debug_shndx| { |
| 7055 | if (debug_shndx == .UNDEF) continue; |
| 7056 | const debug_ni = debug_shndx.get(elf).ni; |
| 7057 | _ = debug_ni.last(&elf.mf).unwrap() orelse continue; |
| 7058 | const frame_format = debug_shndx.debugFrameFormat(elf); |
| 7059 | const unit_padding_ni = try debug_ni.addFloatingChild(&elf.mf, gpa, .{ |
| 7060 | .alignment = if (frame_format) |_| switch (elf.identClass()) { |
| 6939 | 7061 | .NONE, _ => unreachable, |
| 6940 | 7062 | .@"32" => .@"4", |
| 6941 | 7063 | .@"64" => .@"8", |
| 6942 | | }, |
| 7064 | } else .@"1", |
| 6943 | 7065 | .next_moved = true, |
| 6944 | 7066 | .enable_next_moved = true, |
| 6945 | 7067 | }); |
| 6946 | | elf.nodes.appendAssumeCapacity(.frame_padding); |
| 6947 | | var cie_writer: MappedFile.Node.Writer = undefined; |
| 6948 | | frame_padding_ni.writer(&elf.mf, gpa, &cie_writer); |
| 6949 | | defer cie_writer.deinit(); |
| 6950 | | elf.dwarf.genDebugFrameCie(&cie_writer.interface, null, format) catch |err| switch (err) { |
| 6951 | | error.WriteFailed => return cie_writer.err.?, |
| 7068 | elf.nodes.appendAssumeCapacity(.unit_padding); |
| 7069 | var debug_nw: MappedFile.Node.Writer = undefined; |
| 7070 | unit_padding_ni.writer(&elf.mf, gpa, &debug_nw); |
| 7071 | defer debug_nw.deinit(); |
| 7072 | (if (frame_format) |format| |
| 7073 | elf.dwarf.genDebugFrameCie(&debug_nw.interface, null, format) |
| 7074 | else |
| 7075 | elf.dwarf.genUnitPadding(&debug_nw.interface)) catch |err| switch (err) { |
| 7076 | error.WriteFailed => return debug_nw.err.?, |
| 6952 | 7077 | }; |
| 6953 | 7078 | } |
| 7079 | |
| 7080 | for (0.., elf.dwarf.units.values()) |unit_index, *unit| { |
| 7081 | const ui: Dwarf.Unit.Index = @fromBackingInt(@intCast(unit_index)); |
| 7082 | switch (elf.shndx.debug_info) { |
| 7083 | .UNDEF => {}, |
| 7084 | else => |debug_info_shndx| { |
| 7085 | const debug_info_ni = |
| 7086 | try debug_info_shndx.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{ |
| 7087 | .alignment = elf.mf.flags.block_size, |
| 7088 | .next_moved = true, |
| 7089 | .enable_next_moved = true, |
| 7090 | }); |
| 7091 | unit.debug_info_ni = .wrap(debug_info_ni); |
| 7092 | elf.nodes.appendAssumeCapacity(.{ .unit_debug_info = ui }); |
| 7093 | |
| 7094 | unit.debug_info_header_ni = |
| 7095 | .wrap(try debug_info_ni.addOnlyHeaderChild(&elf.mf, gpa, .{ |
| 7096 | .next_moved = true, |
| 7097 | .enable_next_moved = true, |
| 7098 | })); |
| 7099 | elf.nodes.appendAssumeCapacity(.{ .unit_debug_info_header = ui }); |
| 7100 | }, |
| 7101 | } |
| 7102 | switch (elf.shndx.debug_line) { |
| 7103 | .UNDEF => {}, |
| 7104 | else => |debug_line_shndx| { |
| 7105 | const debug_line_ni = |
| 7106 | try debug_line_shndx.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{ |
| 7107 | .alignment = elf.mf.flags.block_size, |
| 7108 | .next_moved = true, |
| 7109 | .enable_next_moved = true, |
| 7110 | }); |
| 7111 | unit.debug_line_ni = .wrap(debug_line_ni); |
| 7112 | elf.nodes.appendAssumeCapacity(.{ .unit_debug_line = ui }); |
| 7113 | |
| 7114 | unit.debug_line_header_ni = |
| 7115 | .wrap(try debug_line_ni.addOnlyHeaderChild(&elf.mf, gpa, .{ |
| 7116 | .next_moved = true, |
| 7117 | .enable_next_moved = true, |
| 7118 | })); |
| 7119 | elf.nodes.appendAssumeCapacity(.{ .unit_debug_line_header = ui }); |
| 7120 | }, |
| 7121 | } |
| 7122 | } |
| 7123 | |
| 7124 | for (0.., elf.dwarf.units.values()) |unit_index, *unit| { |
| 7125 | const ui: Dwarf.Unit.Index = @fromBackingInt(@intCast(unit_index)); |
| 7126 | if (elf.shndx.debug_info != .UNDEF) { |
| 7127 | var header_nw: MappedFile.Node.Writer = undefined; |
| 7128 | const debug_info_header_ni = unit.debug_info_header_ni.unwrap().?; |
| 7129 | debug_info_header_ni.writer(&elf.mf, gpa, &header_nw); |
| 7130 | defer header_nw.deinit(); |
| 7131 | elf.resetNodeRelocs(debug_info_header_ni); |
| 7132 | elf.dwarf.genDebugInfoHeader(&header_nw, ui, zcu) catch |err| switch (err) { |
| 7133 | error.WriteFailed => return header_nw.err.?, |
| 7134 | else => |e| return e, |
| 7135 | }; |
| 7136 | } |
| 7137 | if (elf.shndx.debug_line != .UNDEF) { |
| 7138 | var header_nw: MappedFile.Node.Writer = undefined; |
| 7139 | const debug_line_header_ni = unit.debug_line_header_ni.unwrap().?; |
| 7140 | debug_line_header_ni.writer(&elf.mf, gpa, &header_nw); |
| 7141 | defer header_nw.deinit(); |
| 7142 | elf.resetNodeRelocs(debug_line_header_ni); |
| 7143 | elf.dwarf.genDebugLineHeader(&header_nw.interface) catch |err| switch (err) { |
| 7144 | error.WriteFailed => return header_nw.err.?, |
| 7145 | }; |
| 7146 | } |
| 7147 | } |
| 6954 | 7148 | } |
| 6955 | 7149 | } |
| 6956 | 7150 | |
| ... | ... | @@ -7750,7 +7944,10 @@ fn addNodeRelocAssumeCapacity( |
| 7750 | 7944 | assert(!shndx.flags(elf).ALLOC); // not yet needed so not implemented |
| 7751 | 7945 | const first_target_reloc = switch (elf.getNode(target)) { |
| 7752 | 7946 | else => unreachable, |
| 7753 | | .unit_frame_cie => |ui| &elf.dwarf_units.items[@backingInt(ui)].unit_frame_cie_first_target_reloc, |
| 7947 | .debug_shared => |ss| &elf.dwarf_shared.getPtr(ss).first_target_reloc, |
| 7948 | .unit_frame_cie => |ui| &elf.dwarf_units.items[@backingInt(ui)].frame_cie_first_target_reloc, |
| 7949 | .unit_debug_info_header => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_info_header_first_target_reloc, |
| 7950 | .unit_debug_line_header => |ui| &elf.dwarf_units.items[@backingInt(ui)].debug_line_header_first_target_reloc, |
| 7754 | 7951 | }; |
| 7755 | 7952 | const next = first_target_reloc.*; |
| 7756 | 7953 | const ri: NodeReloc.Index = @fromBackingInt(@intCast(elf.node_relocs.items.len)); |
| ... | ... | @@ -7843,11 +8040,16 @@ fn addGotRelocAssumeCapacity( |
| 7843 | 8040 | .shdr, |
| 7844 | 8041 | .segment, |
| 7845 | 8042 | .copied_global, |
| 7846 | | .value_debug_info, |
| 7847 | | .global_debug_info, |
| 7848 | | .frame_padding, |
| 8043 | .debug_shared, |
| 8044 | .unit_padding, |
| 7849 | 8045 | .unit_frame, |
| 7850 | 8046 | .unit_frame_cie, |
| 8047 | .unit_debug_info, |
| 8048 | .unit_debug_info_header, |
| 8049 | .unit_debug_line, |
| 8050 | .unit_debug_line_header, |
| 8051 | .value_debug_info, |
| 8052 | .global_debug_info, |
| 7851 | 8053 | .func_frame_fde, |
| 7852 | 8054 | .func_debug_info, |
| 7853 | 8055 | .func_debug_line, |
| ... | ... | @@ -8207,21 +8409,27 @@ fn updateFuncInner( |
| 8207 | 8409 | var nw: MappedFile.Node.Writer = undefined; |
| 8208 | 8410 | ni.writer(&elf.mf, gpa, &nw); |
| 8209 | 8411 | defer nw.deinit(); |
| 8210 | | var debug: Dwarf.WipNav.Debug = undefined; |
| 8211 | | const debug_output: link.File.DebugInfoOutput = debug_output: { |
| 8212 | | if (elf.ehdrMachine() != .X86_64) break :debug_output .none; |
| 8412 | var debug_output_buf: Dwarf.WipNav.Debug = undefined; |
| 8413 | const debug_output: link.File.DebugInfoOutput, const dwarf_func = debug_output: { |
| 8414 | if (elf.ehdrMachine() != .X86_64) break :debug_output .{ .none, undefined }; |
| 8213 | 8415 | const dwarf = &elf.dwarf; |
| 8214 | 8416 | const mod = zcu.navFileScope(func.owner_nav).mod.?; |
| 8215 | | if (mod.strip and mod.unwind_tables == .none) break :debug_output .none; |
| 8417 | if (mod.strip and mod.unwind_tables == .none) break :debug_output .{ .none, undefined }; |
| 8216 | 8418 | |
| 8217 | 8419 | try elf.nodes.ensureUnusedCapacity(gpa, 5); |
| 8218 | 8420 | const dwarf_func_index = try dwarf.getFunc(func.owner_nav); |
| 8219 | 8421 | try elf.dwarf_funcs.appendNTimes(gpa, .{ |
| 8220 | | .func_frame_fde_first_symbol_reloc = .none, |
| 8221 | | .func_frame_fde_first_node_reloc = .none, |
| 8422 | .frame_fde_first_symbol_reloc = .none, |
| 8423 | .frame_fde_first_node_reloc = .none, |
| 8424 | .debug_info_first_target_reloc = .none, |
| 8425 | .debug_info_first_symbol_reloc = .none, |
| 8426 | .debug_info_first_node_reloc = .none, |
| 8427 | .debug_line_first_symbol_reloc = .none, |
| 8428 | .debug_line_first_node_reloc = .none, |
| 8222 | 8429 | }, @backingInt(dwarf_func_index) + 1 -| elf.dwarf_funcs.items.len); |
| 8223 | 8430 | |
| 8224 | | debug.wip_nav = .{ |
| 8431 | const wip_nav = &debug_output_buf.wip_nav; |
| 8432 | wip_nav.* = .{ |
| 8225 | 8433 | .dwarf = dwarf, |
| 8226 | 8434 | .unit = dwarf.getUnit(mod), |
| 8227 | 8435 | .func = dwarf_func_index, |
| ... | ... | @@ -8235,16 +8443,17 @@ fn updateFuncInner( |
| 8235 | 8443 | .sync, .async => .eh_frame, |
| 8236 | 8444 | }, |
| 8237 | 8445 | .fde_writer = undefined, |
| 8238 | | .frame_func_length_offset = std.math.maxInt(usize), |
| 8446 | .frame_func_length = undefined, |
| 8239 | 8447 | }; |
| 8240 | | const unit = debug.wip_nav.unit.get(dwarf); |
| 8448 | const unit = wip_nav.unit.get(dwarf); |
| 8449 | |
| 8241 | 8450 | const frame_align: Alignment = switch (elf.identClass()) { |
| 8242 | 8451 | .NONE, _ => unreachable, |
| 8243 | 8452 | .@"32" => .@"4", |
| 8244 | 8453 | .@"64" => .@"8", |
| 8245 | 8454 | }; |
| 8246 | 8455 | const frame_ni = unit.frame_ni.unwrap() orelse frame_ni: { |
| 8247 | | const frame_ni = try switch (debug.wip_nav.frame_format) { |
| 8456 | const frame_ni = try switch (wip_nav.frame_format) { |
| 8248 | 8457 | .debug_frame => elf.shndx.debug_frame, |
| 8249 | 8458 | .eh_frame => elf.shndx.eh_frame, |
| 8250 | 8459 | }.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{ |
| ... | ... | @@ -8253,7 +8462,7 @@ fn updateFuncInner( |
| 8253 | 8462 | .enable_next_moved = true, |
| 8254 | 8463 | }); |
| 8255 | 8464 | unit.frame_ni = .wrap(frame_ni); |
| 8256 | | elf.nodes.appendAssumeCapacity(.{ .unit_frame = debug.wip_nav.unit }); |
| 8465 | elf.nodes.appendAssumeCapacity(.{ .unit_frame = wip_nav.unit }); |
| 8257 | 8466 | break :frame_ni frame_ni; |
| 8258 | 8467 | }; |
| 8259 | 8468 | _ = unit.cie_ni.unwrap() orelse { |
| ... | ... | @@ -8263,17 +8472,16 @@ fn updateFuncInner( |
| 8263 | 8472 | .enable_next_moved = true, |
| 8264 | 8473 | }); |
| 8265 | 8474 | unit.cie_ni = .wrap(cie_ni); |
| 8266 | | elf.nodes.appendAssumeCapacity(.{ .unit_frame_cie = debug.wip_nav.unit }); |
| 8267 | | var cie_writer: MappedFile.Node.Writer = undefined; |
| 8268 | | cie_ni.writer(&elf.mf, gpa, &cie_writer); |
| 8269 | | defer cie_writer.deinit(); |
| 8270 | | dwarf.genDebugFrameCie(&cie_writer.interface, switch (elf.ehdrMachine()) { |
| 8475 | elf.nodes.appendAssumeCapacity(.{ .unit_frame_cie = wip_nav.unit }); |
| 8476 | var cie_nw: MappedFile.Node.Writer = undefined; |
| 8477 | cie_ni.writer(&elf.mf, gpa, &cie_nw); |
| 8478 | defer cie_nw.deinit(); |
| 8479 | dwarf.genDebugFrameCie(&cie_nw.interface, switch (elf.ehdrMachine()) { |
| 8271 | 8480 | else => unreachable, |
| 8272 | 8481 | .X86_64 => .x86_64, |
| 8273 | | }, debug.wip_nav.frame_format) catch |err| switch (err) { |
| 8274 | | error.WriteFailed => return cie_writer.err.?, |
| 8482 | }, wip_nav.frame_format) catch |err| switch (err) { |
| 8483 | error.WriteFailed => return cie_nw.err.?, |
| 8275 | 8484 | }; |
| 8276 | | @memset(cie_writer.interface.unusedCapacitySlice(), std.dwarf.CFA.nop); |
| 8277 | 8485 | }; |
| 8278 | 8486 | const dwarf_func = dwarf_func_index.get(dwarf); |
| 8279 | 8487 | const fde_ni = if (dwarf_func.fde_ni.unwrap()) |fde_ni| fde_ni: { |
| ... | ... | @@ -8290,15 +8498,17 @@ fn updateFuncInner( |
| 8290 | 8498 | dwarf_func.fde_ni = .wrap(fde_ni); |
| 8291 | 8499 | break :fde_ni fde_ni; |
| 8292 | 8500 | }; |
| 8293 | | fde_ni.writer(&elf.mf, gpa, &debug.wip_nav.fde_writer); |
| 8294 | | if (mod.strip) break :debug_output .{ .eh_frame = &debug.wip_nav }; |
| 8501 | fde_ni.writer(&elf.mf, gpa, &wip_nav.fde_writer); |
| 8502 | |
| 8503 | if (mod.strip) break :debug_output .{ .{ .eh_frame = wip_nav }, dwarf_func }; |
| 8295 | 8504 | |
| 8505 | const debug = &debug_output_buf; |
| 8296 | 8506 | debug.pt = pt; |
| 8297 | 8507 | debug.any_children = false; |
| 8298 | 8508 | debug.blocks = .empty; |
| 8299 | 8509 | const debug_info_ni = dwarf_func.debug_info_ni.unwrap() orelse debug_info_ni: { |
| 8300 | 8510 | const debug_info_ni = |
| 8301 | | try elf.shndx.debug_info.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{ |
| 8511 | try unit.debug_info_ni.unwrap().?.addFloatingChild(&elf.mf, gpa, .{ |
| 8302 | 8512 | .next_moved = true, |
| 8303 | 8513 | .enable_next_moved = true, |
| 8304 | 8514 | }); |
| ... | ... | @@ -8309,7 +8519,7 @@ fn updateFuncInner( |
| 8309 | 8519 | debug_info_ni.writer(&elf.mf, gpa, &debug.info_writer); |
| 8310 | 8520 | const debug_line_ni = dwarf_func.debug_line_ni.unwrap() orelse debug_line_ni: { |
| 8311 | 8521 | const debug_line_ni = |
| 8312 | | try elf.shndx.debug_line.get(elf).ni.addFloatingChild(&elf.mf, gpa, .{ |
| 8522 | try unit.debug_line_ni.unwrap().?.addFloatingChild(&elf.mf, gpa, .{ |
| 8313 | 8523 | .next_moved = true, |
| 8314 | 8524 | .enable_next_moved = true, |
| 8315 | 8525 | }); |
| ... | ... | @@ -8317,18 +8527,25 @@ fn updateFuncInner( |
| 8317 | 8527 | break :debug_line_ni debug_line_ni; |
| 8318 | 8528 | }; |
| 8319 | 8529 | debug_line_ni.writer(&elf.mf, gpa, &debug.line_writer); |
| 8320 | | break :debug_output .{ .dwarf2 = &debug }; |
| 8530 | |
| 8531 | break :debug_output .{ .{ .dwarf2 = debug }, dwarf_func }; |
| 8321 | 8532 | }; |
| 8322 | 8533 | defer switch (debug_output) { |
| 8323 | 8534 | .dwarf => unreachable, |
| 8324 | | inline .eh_frame, .dwarf2 => |dwarf| dwarf.deinit(gpa), |
| 8535 | inline .eh_frame, .dwarf2 => |dwarf| dwarf.deinit(), |
| 8325 | 8536 | .none => {}, |
| 8326 | 8537 | }; |
| 8327 | 8538 | switch (debug_output) { |
| 8328 | 8539 | .dwarf => unreachable, |
| 8329 | | inline .eh_frame, .dwarf2 => |dwarf| { |
| 8330 | | elf.resetNodeRelocs(debug.wip_nav.func.?.get(&elf.dwarf).fde_ni.unwrap().?); |
| 8331 | | try dwarf.genFuncHeaders(); |
| 8540 | .eh_frame => |wip_nav| { |
| 8541 | elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?); |
| 8542 | try wip_nav.genDebugFrameHeader(); |
| 8543 | }, |
| 8544 | .dwarf2 => |debug| { |
| 8545 | elf.resetNodeRelocs(dwarf_func.fde_ni.unwrap().?); |
| 8546 | try debug.wip_nav.genDebugFrameHeader(); |
| 8547 | elf.resetNodeRelocs(dwarf_func.debug_info_ni.unwrap().?); |
| 8548 | try debug.startDebugInfo(); |
| 8332 | 8549 | }, |
| 8333 | 8550 | .none => {}, |
| 8334 | 8551 | } |
| ... | ... | @@ -8348,30 +8565,45 @@ fn updateFuncInner( |
| 8348 | 8565 | else => |e| return e, |
| 8349 | 8566 | }; |
| 8350 | 8567 | const func_length = nw.interface.end; |
| 8351 | | switch (debug_output) { |
| 8568 | switch (elf.symPtr(nmi.symbol(elf).index())) { |
| 8569 | inline else => |sym| elf.targetStore(&sym.size, @intCast(func_length)), |
| 8570 | } |
| 8571 | debug_output: switch (debug_output) { |
| 8352 | 8572 | .dwarf => unreachable, |
| 8353 | | .eh_frame, .dwarf2 => { |
| 8354 | | debug.wip_nav.finishDebugFrameFde(func_length); |
| 8355 | | const frame_ni = switch (debug.wip_nav.frame_format) { |
| 8573 | .eh_frame => |wip_nav| { |
| 8574 | wip_nav.finishDebugFrameFde(func_length); |
| 8575 | const frame_ni = switch (wip_nav.frame_format) { |
| 8356 | 8576 | .debug_frame => elf.shndx.debug_frame, |
| 8357 | 8577 | .eh_frame => elf.shndx.eh_frame, |
| 8358 | 8578 | }.get(elf).ni; |
| 8359 | | try frame_ni.trimStart(&elf.mf, elf.base.comp.gpa); |
| 8360 | | switch (debug.wip_nav.frame_format) { |
| 8579 | try frame_ni.trimStart(&elf.mf, gpa); |
| 8580 | switch (wip_nav.frame_format) { |
| 8361 | 8581 | .debug_frame => {}, |
| 8362 | 8582 | .eh_frame => { |
| 8363 | 8583 | const last_offset, const last_size = |
| 8364 | 8584 | frame_ni.last(&elf.mf).unwrap().?.location(&elf.mf).resolve(&elf.mf); |
| 8365 | | const last_end = last_offset + last_size; |
| 8366 | | try frame_ni.ensureMinimumSize(&elf.mf, elf.base.comp.gpa, last_end + 4); |
| 8585 | try frame_ni.ensureMinimumSize(&elf.mf, gpa, last_offset + last_size + 4); |
| 8367 | 8586 | }, |
| 8368 | 8587 | } |
| 8369 | 8588 | }, |
| 8589 | .dwarf2 => |debug| { |
| 8590 | try debug.finishFunc(); |
| 8591 | for ([2]Section.Index{ |
| 8592 | elf.shndx.debug_info, |
| 8593 | elf.shndx.debug_line, |
| 8594 | }) |debug_shndx| try debug_shndx.get(elf).ni.trimStart(&elf.mf, gpa); |
| 8595 | { |
| 8596 | const debug_info_ni = |
| 8597 | debug.wip_nav.unit.get(debug.wip_nav.dwarf).debug_info_ni.unwrap().?; |
| 8598 | const last_offset, const last_size = |
| 8599 | debug_info_ni.last(&elf.mf).unwrap().?.location(&elf.mf).resolve(&elf.mf); |
| 8600 | try debug_info_ni.ensureMinimumSize(&elf.mf, gpa, last_offset + last_size + |
| 8601 | comptime Dwarf.uleb128Bytes(@backingInt(Dwarf.AbbrevCode.null)) * 2); |
| 8602 | } |
| 8603 | continue :debug_output .{ .eh_frame = &debug.wip_nav }; |
| 8604 | }, |
| 8370 | 8605 | .none => {}, |
| 8371 | 8606 | } |
| 8372 | | switch (elf.symPtr(nmi.symbol(elf).index())) { |
| 8373 | | inline else => |sym| elf.targetStore(&sym.size, @intCast(func_length)), |
| 8374 | | } |
| 8375 | 8607 | } |
| 8376 | 8608 | |
| 8377 | 8609 | // The NAV's node is done---now generate any UAVs or lazy code/data which the NAV needs. |
| ... | ... | @@ -8427,8 +8659,14 @@ fn flushInner( |
| 8427 | 8659 | |
| 8428 | 8660 | while (try elf.idle(tid)) {} |
| 8429 | 8661 | |
| 8662 | assert(elf.pending_uavs.items.len == 0); |
| 8663 | var lazy_it = elf.lazy.iterator(); |
| 8664 | while (lazy_it.next()) |lazy| assert(lazy.value.pending_index == lazy.value.map.count()); |
| 8665 | |
| 8430 | 8666 | // We've done the final `idle` loop, so everything is at its final place in the file. We have a |
| 8431 | 8667 | // few more things to check and write now that addresses and offsets are finalized. |
| 8668 | elf.mf.nodes_lock.lock(); |
| 8669 | defer elf.mf.nodes_lock.unlock(); |
| 8432 | 8670 | |
| 8433 | 8671 | if (elf.overflowed_reloc_count > 0) { |
| 8434 | 8672 | diags.addError("failed to apply {d} relocations: overflow", .{elf.overflowed_reloc_count}); |
| ... | ... | @@ -8476,12 +8714,13 @@ fn flushInner( |
| 8476 | 8714 | } |
| 8477 | 8715 | |
| 8478 | 8716 | pub fn idle(elf: *Elf, tid: Zcu.PerThread.Id) link.Error!bool { |
| 8479 | | const comp = elf.base.comp; |
| 8480 | | const diags = &comp.link_diags; |
| 8481 | | |
| 8717 | // This function is called non-deterministically, and so must not affect the layout of any nodes. |
| 8482 | 8718 | elf.mf.nodes_lock.lock(); |
| 8483 | 8719 | defer elf.mf.nodes_lock.unlock(); |
| 8484 | 8720 | |
| 8721 | const comp = elf.base.comp; |
| 8722 | const diags = &comp.link_diags; |
| 8723 | |
| 8485 | 8724 | assert(elf.pending_uavs.items.len == 0); |
| 8486 | 8725 | for (&elf.lazy.values) |*lazy| { |
| 8487 | 8726 | assert(lazy.pending_index == lazy.map.count()); |
| ... | ... | @@ -8654,6 +8893,25 @@ fn idleProgNode( |
| 8654 | 8893 | .uav => |umi| std.mem.print(&name, "{f}", .{ |
| 8655 | 8894 | Value.fromInterned(umi.uavValue(elf)).fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }), |
| 8656 | 8895 | }) catch &name, |
| 8896 | .debug_shared => |ss| switch (ss) { |
| 8897 | .debug_abbrev, .debug_str, .debug_str_offsets => "debug info", |
| 8898 | .debug_line_str => "line info", |
| 8899 | }, |
| 8900 | .unit_frame, |
| 8901 | .unit_frame_cie, |
| 8902 | .unit_debug_info, |
| 8903 | .unit_debug_info_header, |
| 8904 | .unit_debug_line, |
| 8905 | .unit_debug_line_header, |
| 8906 | => |ui, tag| std.mem.print(&name, "{s} info for {s}", .{ |
| 8907 | switch (tag) { |
| 8908 | else => unreachable, |
| 8909 | .unit_frame, .unit_frame_cie => "unwind", |
| 8910 | .unit_debug_info, .unit_debug_info_header => "debug", |
| 8911 | .unit_debug_line, .unit_debug_line_header => "line", |
| 8912 | }, |
| 8913 | ui.mod(&elf.dwarf).fully_qualified_name, |
| 8914 | }) catch &name, |
| 8657 | 8915 | .value_debug_info => |cpi| std.mem.print(&name, "debug info for {f}", .{ |
| 8658 | 8916 | Value.fromInterned(cpi.val(&elf.dwarf.const_pool)) |
| 8659 | 8917 | .fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }), |
| ... | ... | @@ -8664,9 +8922,6 @@ fn idleProgNode( |
| 8664 | 8922 | ip.getNav(gi.nav(&elf.dwarf)).fqn.fmt(ip), |
| 8665 | 8923 | }) catch &name; |
| 8666 | 8924 | }, |
| 8667 | | .unit_frame, .unit_frame_cie => |ui| std.mem.print(&name, "unwind info for {s}", .{ |
| 8668 | | ui.mod(&elf.dwarf).fully_qualified_name, |
| 8669 | | }) catch &name, |
| 8670 | 8925 | .func_frame_fde, .func_debug_info, .func_debug_line => |fi, tag| { |
| 8671 | 8926 | const ip = &elf.base.comp.zcu.?.intern_pool; |
| 8672 | 8927 | break :name std.mem.print(&name, "{s} info for {f}", .{ |
| ... | ... | @@ -8684,38 +8939,35 @@ fn idleProgNode( |
| 8684 | 8939 | |
| 8685 | 8940 | fn genPending(elf: *Elf, pt: Zcu.PerThread) Error!void { |
| 8686 | 8941 | const zcu = elf.base.comp.zcu.?; |
| 8687 | | pending: while (true) { |
| 8688 | | if (elf.pending_uavs.pop()) |umi| { |
| 8689 | | var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined; |
| 8690 | | const prog_name = std.mem.print(&prog_name_buf, "{f}", .{ |
| 8691 | | Value.fromInterned(umi.uavValue(elf)).fmtValue(pt), |
| 8692 | | }) catch &prog_name_buf; |
| 8693 | | const prog_node = elf.const_prog_node.start(prog_name, 0); |
| 8694 | | defer prog_node.end(); |
| 8695 | | try elf.genUav(pt, umi); |
| 8696 | | continue :pending; |
| 8697 | | } |
| 8698 | | var lazy_it = elf.lazy.iterator(); |
| 8699 | | while (lazy_it.next()) |lazy| if (lazy.value.pending_index < lazy.value.map.count()) { |
| 8700 | | const lmr: Node.LazyMapRef = .{ .kind = lazy.key, .index = lazy.value.pending_index }; |
| 8701 | | lazy.value.pending_index += 1; |
| 8702 | | const lazy_ty: Type = .fromInterned(lmr.lazySymbol(elf).ty); |
| 8703 | | var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined; |
| 8704 | | const prog_name: []const u8 = switch (lazy_ty.zigTypeTag(zcu)) { |
| 8705 | | .@"enum" => std.mem.print(&prog_name_buf, "@tagName({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf, |
| 8706 | | .error_set => switch (lmr.kind) { |
| 8707 | | .code => std.mem.print(&prog_name_buf, "@errorCast({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf, |
| 8708 | | .const_data => "@errorName", |
| 8709 | | }, |
| 8710 | | else => unreachable, |
| 8711 | | }; |
| 8712 | | const prog_node = elf.synth_prog_node.start(prog_name, 0); |
| 8713 | | defer prog_node.end(); |
| 8714 | | try elf.genLazy(pt, lmr); |
| 8715 | | continue :pending; |
| 8942 | |
| 8943 | while (elf.pending_uavs.pop()) |umi| { |
| 8944 | var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined; |
| 8945 | const prog_name = std.mem.print(&prog_name_buf, "{f}", .{ |
| 8946 | Value.fromInterned(umi.uavValue(elf)).fmtValue(pt), |
| 8947 | }) catch &prog_name_buf; |
| 8948 | const prog_node = elf.const_prog_node.start(prog_name, 0); |
| 8949 | defer prog_node.end(); |
| 8950 | try elf.genUav(pt, umi); |
| 8951 | } |
| 8952 | |
| 8953 | var lazy_it = elf.lazy.iterator(); |
| 8954 | while (lazy_it.next()) |lazy| while (lazy.value.pending_index < lazy.value.map.count()) { |
| 8955 | const lmr: Node.LazyMapRef = .{ .kind = lazy.key, .index = lazy.value.pending_index }; |
| 8956 | lazy.value.pending_index += 1; |
| 8957 | const lazy_ty: Type = .fromInterned(lmr.lazySymbol(elf).ty); |
| 8958 | var prog_name_buf: [std.Progress.Node.max_name_len]u8 = undefined; |
| 8959 | const prog_name: []const u8 = switch (lazy_ty.zigTypeTag(zcu)) { |
| 8960 | .@"enum" => std.mem.print(&prog_name_buf, "@tagName({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf, |
| 8961 | .error_set => switch (lmr.kind) { |
| 8962 | .code => std.mem.print(&prog_name_buf, "@errorCast({f})", .{lazy_ty.fmt(pt)}) catch &prog_name_buf, |
| 8963 | .const_data => "@errorName", |
| 8964 | }, |
| 8965 | else => unreachable, |
| 8716 | 8966 | }; |
| 8717 | | break; |
| 8718 | | } |
| 8967 | const prog_node = elf.synth_prog_node.start(prog_name, 0); |
| 8968 | defer prog_node.end(); |
| 8969 | try elf.genLazy(pt, lmr); |
| 8970 | }; |
| 8719 | 8971 | } |
| 8720 | 8972 | |
| 8721 | 8973 | fn genUav( |
| ... | ... | @@ -9071,25 +9323,103 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void |
| 9071 | 9323 | name = elf.globalByName(name).?.next_in_node; |
| 9072 | 9324 | } |
| 9073 | 9325 | } |
| 9074 | | elf.flushMovedNodeRelocs(ni, new_addr, mi.firstSymbolReloc(elf), .none, mi.firstGotReloc(elf)); |
| 9326 | elf.flushMovedNodeRelocs( |
| 9327 | ni, |
| 9328 | new_addr, |
| 9329 | mi.firstSymbolReloc(elf), |
| 9330 | .none, |
| 9331 | mi.firstGotReloc(elf), |
| 9332 | ); |
| 9075 | 9333 | }, |
| 9076 | | .value_debug_info, |
| 9077 | | .global_debug_info, |
| 9078 | | .frame_padding, |
| 9079 | | .unit_frame, |
| 9080 | | => {}, |
| 9334 | .debug_shared => |ss| { |
| 9335 | var target_ri = elf.dwarf_shared.getPtr(ss).first_target_reloc; |
| 9336 | while (target_ri != .none) { |
| 9337 | const target_reloc = target_ri.get(elf); |
| 9338 | assert(target_reloc.target == ni); |
| 9339 | target_reloc.apply(elf); |
| 9340 | target_ri = target_reloc.next; |
| 9341 | } |
| 9342 | }, |
| 9343 | .unit_padding, .unit_frame, .unit_debug_info, .unit_debug_line => {}, |
| 9081 | 9344 | .unit_frame_cie => |ui| { |
| 9082 | 9345 | const dwarf_unit = &elf.dwarf_units.items[@backingInt(ui)]; |
| 9083 | | var target_ri = dwarf_unit.unit_frame_cie_first_target_reloc; |
| 9346 | var target_ri = dwarf_unit.frame_cie_first_target_reloc; |
| 9347 | while (target_ri != .none) { |
| 9348 | const target_reloc = target_ri.get(elf); |
| 9349 | assert(target_reloc.target == ni); |
| 9350 | target_reloc.apply(elf); |
| 9351 | target_ri = target_reloc.next; |
| 9352 | } |
| 9353 | }, |
| 9354 | .unit_debug_info_header => |ui| { |
| 9355 | const dwarf_unit = &elf.dwarf_units.items[@backingInt(ui)]; |
| 9356 | var target_ri = dwarf_unit.debug_info_header_first_target_reloc; |
| 9357 | while (target_ri != .none) { |
| 9358 | const target_reloc = target_ri.get(elf); |
| 9359 | assert(target_reloc.target == ni); |
| 9360 | target_reloc.apply(elf); |
| 9361 | target_ri = target_reloc.next; |
| 9362 | } |
| 9363 | elf.flushMovedNodeRelocs( |
| 9364 | ni, |
| 9365 | elf.computeNodeVAddr(ni), |
| 9366 | .none, |
| 9367 | dwarf_unit.debug_info_header_first_node_reloc, |
| 9368 | .none, |
| 9369 | ); |
| 9370 | }, |
| 9371 | .unit_debug_line_header => |ui| { |
| 9372 | const dwarf_unit = &elf.dwarf_units.items[@backingInt(ui)]; |
| 9373 | var target_ri = dwarf_unit.debug_line_header_first_target_reloc; |
| 9374 | while (target_ri != .none) { |
| 9375 | const target_reloc = target_ri.get(elf); |
| 9376 | assert(target_reloc.target == ni); |
| 9377 | target_reloc.apply(elf); |
| 9378 | target_ri = target_reloc.next; |
| 9379 | } |
| 9380 | elf.flushMovedNodeRelocs( |
| 9381 | ni, |
| 9382 | elf.computeNodeVAddr(ni), |
| 9383 | .none, |
| 9384 | dwarf_unit.debug_line_header_first_node_reloc, |
| 9385 | .none, |
| 9386 | ); |
| 9387 | }, |
| 9388 | .value_debug_info => |vi| { |
| 9389 | const dwarf_value = &elf.dwarf_values.items[@backingInt(vi)]; |
| 9390 | var target_ri = dwarf_value.debug_info_first_target_reloc; |
| 9391 | while (target_ri != .none) { |
| 9392 | const target_reloc = target_ri.get(elf); |
| 9393 | assert(target_reloc.target == ni); |
| 9394 | target_reloc.apply(elf); |
| 9395 | target_ri = target_reloc.next; |
| 9396 | } |
| 9397 | elf.flushMovedNodeRelocs( |
| 9398 | ni, |
| 9399 | elf.computeNodeVAddr(ni), |
| 9400 | dwarf_value.debug_info_first_symbol_reloc, |
| 9401 | dwarf_value.debug_info_first_node_reloc, |
| 9402 | .none, |
| 9403 | ); |
| 9404 | }, |
| 9405 | .global_debug_info => |vi| { |
| 9406 | const dwarf_global = &elf.dwarf_globals.items[@backingInt(vi)]; |
| 9407 | var target_ri = dwarf_global.debug_info_first_target_reloc; |
| 9084 | 9408 | while (target_ri != .none) { |
| 9085 | 9409 | const target_reloc = target_ri.get(elf); |
| 9086 | 9410 | assert(target_reloc.target == ni); |
| 9087 | 9411 | target_reloc.apply(elf); |
| 9088 | 9412 | target_ri = target_reloc.next; |
| 9089 | 9413 | } |
| 9414 | elf.flushMovedNodeRelocs( |
| 9415 | ni, |
| 9416 | elf.computeNodeVAddr(ni), |
| 9417 | dwarf_global.debug_info_first_symbol_reloc, |
| 9418 | dwarf_global.debug_info_first_node_reloc, |
| 9419 | .none, |
| 9420 | ); |
| 9090 | 9421 | }, |
| 9091 | 9422 | .func_frame_fde => |fi| { |
| 9092 | | const new_addr = elf.computeNodeVAddr(ni); |
| 9093 | 9423 | const dwarf_func = &elf.dwarf_funcs.items[@backingInt(fi)]; |
| 9094 | 9424 | const mod = elf.base.comp.zcu.?.navFileScope(fi.nav(&elf.dwarf)).mod.?; |
| 9095 | 9425 | switch (mod.unwind_tables) { |
| ... | ... | @@ -9101,15 +9431,39 @@ fn flushMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!void |
| 9101 | 9431 | } |
| 9102 | 9432 | elf.flushMovedNodeRelocs( |
| 9103 | 9433 | ni, |
| 9104 | | new_addr, |
| 9105 | | dwarf_func.func_frame_fde_first_symbol_reloc, |
| 9106 | | dwarf_func.func_frame_fde_first_node_reloc, |
| 9434 | elf.computeNodeVAddr(ni), |
| 9435 | dwarf_func.frame_fde_first_symbol_reloc, |
| 9436 | dwarf_func.frame_fde_first_node_reloc, |
| 9437 | .none, |
| 9438 | ); |
| 9439 | }, |
| 9440 | .func_debug_info => |fi| { |
| 9441 | const dwarf_func = &elf.dwarf_funcs.items[@backingInt(fi)]; |
| 9442 | var target_ri = dwarf_func.debug_info_first_target_reloc; |
| 9443 | while (target_ri != .none) { |
| 9444 | const target_reloc = target_ri.get(elf); |
| 9445 | assert(target_reloc.target == ni); |
| 9446 | target_reloc.apply(elf); |
| 9447 | target_ri = target_reloc.next; |
| 9448 | } |
| 9449 | elf.flushMovedNodeRelocs( |
| 9450 | ni, |
| 9451 | elf.computeNodeVAddr(ni), |
| 9452 | dwarf_func.debug_info_first_symbol_reloc, |
| 9453 | dwarf_func.debug_info_first_node_reloc, |
| 9454 | .none, |
| 9455 | ); |
| 9456 | }, |
| 9457 | .func_debug_line => |fi| { |
| 9458 | const dwarf_func = &elf.dwarf_funcs.items[@backingInt(fi)]; |
| 9459 | elf.flushMovedNodeRelocs( |
| 9460 | ni, |
| 9461 | elf.computeNodeVAddr(ni), |
| 9462 | dwarf_func.debug_line_first_symbol_reloc, |
| 9463 | dwarf_func.debug_line_first_node_reloc, |
| 9107 | 9464 | .none, |
| 9108 | 9465 | ); |
| 9109 | 9466 | }, |
| 9110 | | .func_debug_info, |
| 9111 | | .func_debug_line, |
| 9112 | | => {}, |
| 9113 | 9467 | } |
| 9114 | 9468 | try ni.childrenMoved(elf.base.comp.gpa, &elf.mf); |
| 9115 | 9469 | } |
| ... | ... | @@ -9346,11 +9700,16 @@ fn flushResized(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error!vo |
| 9346 | 9700 | .uav, |
| 9347 | 9701 | .lazy_code, |
| 9348 | 9702 | .lazy_const_data, |
| 9349 | | .value_debug_info, |
| 9350 | | .global_debug_info, |
| 9351 | | .frame_padding, |
| 9703 | .debug_shared, |
| 9704 | .unit_padding, |
| 9352 | 9705 | .unit_frame, |
| 9353 | 9706 | .unit_frame_cie, |
| 9707 | .unit_debug_info, |
| 9708 | .unit_debug_info_header, |
| 9709 | .unit_debug_line, |
| 9710 | .unit_debug_line_header, |
| 9711 | .value_debug_info, |
| 9712 | .global_debug_info, |
| 9354 | 9713 | .func_frame_fde, |
| 9355 | 9714 | .func_debug_info, |
| 9356 | 9715 | .func_debug_line, |
| ... | ... | @@ -9378,6 +9737,7 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error! |
| 9378 | 9737 | .uav, |
| 9379 | 9738 | .lazy_code, |
| 9380 | 9739 | .lazy_const_data, |
| 9740 | .debug_shared, |
| 9381 | 9741 | => unreachable, |
| 9382 | 9742 | |
| 9383 | 9743 | .archive_header => { |
| ... | ... | @@ -9406,66 +9766,111 @@ fn flushNextMoved(elf: *Elf, ni: MappedFile.Node.Index) std.mem.Allocator.Error! |
| 9406 | 9766 | error.NoSpaceLeft => archive.strtab_member_too_big = true, |
| 9407 | 9767 | } |
| 9408 | 9768 | }, |
| 9769 | .unit_padding, |
| 9770 | .unit_frame_cie, |
| 9771 | .unit_debug_info_header, |
| 9772 | .unit_debug_line_header, |
| 9409 | 9773 | .value_debug_info, |
| 9410 | 9774 | .global_debug_info, |
| 9411 | | => {}, |
| 9412 | | .frame_padding, .unit_frame_cie, .func_frame_fde => |_, tag| { |
| 9775 | .func_frame_fde, |
| 9776 | .func_debug_info, |
| 9777 | .func_debug_line, |
| 9778 | => |_, tag| { |
| 9413 | 9779 | const offset, const size = ni.location(&elf.mf).resolve(&elf.mf); |
| 9414 | | const slice = slice: { |
| 9415 | | const parent_ni = ni.parent(&elf.mf).unwrap().?; |
| 9416 | | if (ni.next(&elf.mf).unwrap()) |next_ni| { |
| 9417 | | const parent_slice = parent_ni.slicePadding(&elf.mf); |
| 9418 | | const next_offset, _ = next_ni.location(&elf.mf).resolve(&elf.mf); |
| 9419 | | break :slice parent_slice[@intCast(offset)..@intCast(next_offset)]; |
| 9420 | | } else switch (tag) { |
| 9421 | | else => unreachable, |
| 9422 | | .frame_padding => { |
| 9423 | | const frame_slice = parent_ni.slicePadding(&elf.mf); |
| 9424 | | switch (elf.getNode(parent_ni).section.debugFrameFormat(elf).?) { |
| 9425 | | .eh_frame => { |
| 9426 | | const end = frame_slice.len - 4; |
| 9427 | | std.mem.writeInt(u32, frame_slice[end..][0..4], 0, elf.dwarf.endian); |
| 9428 | | break :slice frame_slice[@intCast(offset)..end]; |
| 9429 | | }, |
| 9430 | | .debug_frame => break :slice frame_slice[@intCast(offset)..], |
| 9431 | | } |
| 9432 | | }, |
| 9433 | | .unit_frame_cie, .func_frame_fde => { |
| 9434 | | const parent_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf); |
| 9435 | | const frame_ni = parent_ni.parent(&elf.mf).unwrap().?; |
| 9436 | | const frame_slice = frame_ni.slicePadding(&elf.mf); |
| 9437 | | const format = elf.getNode(frame_ni).section.debugFrameFormat(elf).?; |
| 9438 | | const slice = frame_slice[@intCast(parent_offset + offset)..if (parent_ni.next(&elf.mf).unwrap()) |parent_next_ni| frame_end: { |
| 9439 | | const parent_next_offset, _ = parent_next_ni.location(&elf.mf).resolve(&elf.mf); |
| 9440 | | break :frame_end @intCast(parent_next_offset); |
| 9441 | | } else frame_end: switch (format) { |
| 9442 | | .eh_frame => { |
| 9443 | | const frame_end = frame_slice.len - 4; |
| 9444 | | std.mem.writeInt(u32, frame_slice[frame_end..][0..4], 0, elf.dwarf.endian); |
| 9445 | | break :frame_end frame_end; |
| 9446 | | }, |
| 9447 | | .debug_frame => frame_slice.len, |
| 9448 | | }]; |
| 9449 | | var fw: std.Io.Writer = .fixed(slice[@intCast(size)..]); |
| 9450 | | elf.dwarf.genDebugFrameCie(&fw, null, format) catch |err| switch (err) { |
| 9451 | | error.WriteFailed => break :slice slice, |
| 9452 | | }; |
| 9453 | | elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len); |
| 9454 | | break :slice slice[0..@intCast(size)]; |
| 9455 | | }, |
| 9456 | | } |
| 9780 | const parent_ni = ni.parent(&elf.mf).unwrap().?; |
| 9781 | const slice = if (ni.next(&elf.mf).unwrap()) |next_ni| slice: { |
| 9782 | const parent_slice = parent_ni.slicePadding(&elf.mf); |
| 9783 | const next_offset, _ = next_ni.location(&elf.mf).resolve(&elf.mf); |
| 9784 | break :slice parent_slice[@intCast(offset)..@intCast(next_offset)]; |
| 9785 | } else slice: switch (tag) { |
| 9786 | else => unreachable, |
| 9787 | .unit_padding => { |
| 9788 | const frame_slice = parent_ni.slicePadding(&elf.mf); |
| 9789 | switch (elf.getNode(parent_ni).section.debugFrameFormat(elf) orelse .debug_frame) { |
| 9790 | .eh_frame => { |
| 9791 | const end = frame_slice.len - 4; |
| 9792 | std.mem.writeInt(u32, frame_slice[end..][0..4], 0, elf.dwarf.endian); |
| 9793 | break :slice frame_slice[@intCast(offset)..end]; |
| 9794 | }, |
| 9795 | .debug_frame => break :slice frame_slice[@intCast(offset)..], |
| 9796 | } |
| 9797 | }, |
| 9798 | .unit_frame_cie, .func_frame_fde => { |
| 9799 | const parent_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf); |
| 9800 | const frame_ni = parent_ni.parent(&elf.mf).unwrap().?; |
| 9801 | const frame_slice = frame_ni.slicePadding(&elf.mf); |
| 9802 | const frame_format = elf.getNode(frame_ni).section.debugFrameFormat(elf); |
| 9803 | const slice = frame_slice[@intCast(parent_offset + offset)..if (parent_ni.next(&elf.mf).unwrap()) |parent_next_ni| frame_end: { |
| 9804 | const parent_next_offset, _ = parent_next_ni.location(&elf.mf).resolve(&elf.mf); |
| 9805 | break :frame_end @intCast(parent_next_offset); |
| 9806 | } else frame_end: switch (frame_format orelse .debug_frame) { |
| 9807 | .eh_frame => { |
| 9808 | const frame_end = frame_slice.len - 4; |
| 9809 | std.mem.writeInt(u32, frame_slice[frame_end..][0..4], 0, elf.dwarf.endian); |
| 9810 | break :frame_end frame_end; |
| 9811 | }, |
| 9812 | .debug_frame => frame_slice.len, |
| 9813 | }]; |
| 9814 | var fw: Io.Writer = .fixed(slice[@intCast(size)..]); |
| 9815 | (if (frame_format) |format| |
| 9816 | elf.dwarf.genDebugFrameCie(&fw, null, format) |
| 9817 | else |
| 9818 | elf.dwarf.genUnitPadding(&fw)) catch |err| switch (err) { |
| 9819 | error.WriteFailed => break :slice slice, |
| 9820 | }; |
| 9821 | elf.dwarf.updateUnitLength(fw.buffer, fw.buffer.len); |
| 9822 | break :slice slice[0..@intCast(size)]; |
| 9823 | }, |
| 9824 | .unit_debug_info_header, |
| 9825 | .unit_debug_line_header, |
| 9826 | .value_debug_info, |
| 9827 | .global_debug_info, |
| 9828 | .func_debug_info, |
| 9829 | .func_debug_line, |
| 9830 | => { |
| 9831 | const parent_offset, _ = parent_ni.location(&elf.mf).resolve(&elf.mf); |
| 9832 | const debug_ni = parent_ni.parent(&elf.mf).unwrap().?; |
| 9833 | const debug_slice = debug_ni.slicePadding(&elf.mf); |
| 9834 | var fw: Io.Writer = .fixed(debug_slice[@intCast(parent_offset)..if (parent_ni.next(&elf.mf).unwrap()) |parent_next_ni| debug_end: { |
| 9835 | const parent_next_offset, _ = parent_next_ni.location(&elf.mf).resolve(&elf.mf); |
| 9836 | break :debug_end @intCast(parent_next_offset); |
| 9837 | } else debug_slice.len]); |
| 9838 | fw.end = @intCast(offset + size); |
| 9839 | for (0..2) |_| fw.writeUleb128(@backingInt(Dwarf.AbbrevCode.null)) catch |
| 9840 | unreachable; // ensured by `updateFunc` |
| 9841 | elf.dwarf.updateUnitLength(fw.buffer, fw.end); |
| 9842 | const unit_padding = fw.unusedCapacitySlice(); |
| 9843 | elf.dwarf.genUnitPadding(&fw) catch |err| switch (err) { |
| 9844 | error.WriteFailed => { |
| 9845 | comptime assert(Dwarf.uleb128Bytes(@backingInt(Dwarf.AbbrevCode.null)) == 1); |
| 9846 | @memset(fw.buffer, @backingInt(Dwarf.AbbrevCode.null)); |
| 9847 | }, |
| 9848 | }; |
| 9849 | elf.dwarf.updateUnitLength(unit_padding, unit_padding.len); |
| 9850 | return; |
| 9851 | }, |
| 9457 | 9852 | }; |
| 9458 | | elf.dwarf.updateUnitLength(slice, slice.len); |
| 9459 | 9853 | switch (tag) { |
| 9460 | 9854 | else => unreachable, |
| 9461 | | .frame_padding => {}, |
| 9462 | | .unit_frame_cie, .func_frame_fde => @memset(slice[@intCast(size)..], std.dwarf.CFA.nop), |
| 9855 | .unit_padding => elf.dwarf.updateUnitLength(slice, slice.len), |
| 9856 | .unit_frame_cie, .func_frame_fde => { |
| 9857 | elf.dwarf.updateUnitLength(slice, slice.len); |
| 9858 | @memset(slice[@intCast(size)..], std.dwarf.CFA.nop); |
| 9859 | }, |
| 9860 | .unit_debug_info_header, |
| 9861 | .unit_debug_line_header, |
| 9862 | .value_debug_info, |
| 9863 | .global_debug_info, |
| 9864 | .func_debug_info, |
| 9865 | .func_debug_line, |
| 9866 | => { |
| 9867 | var fw: Io.Writer = .fixed(slice[@intCast(size)..]); |
| 9868 | elf.dwarf.genDebugInfoPadding(&fw, fw.unusedCapacityLen()) catch unreachable; |
| 9869 | }, |
| 9463 | 9870 | } |
| 9464 | 9871 | }, |
| 9465 | | .unit_frame, |
| 9466 | | .func_debug_info, |
| 9467 | | .func_debug_line, |
| 9468 | | => {}, |
| 9872 | .unit_frame, .unit_debug_info, .unit_debug_line => if (ni.last(&elf.mf).unwrap()) |last_ni| |
| 9873 | try last_ni.nextMoved(elf.base.comp.gpa, &elf.mf), |
| 9469 | 9874 | } |
| 9470 | 9875 | } |
| 9471 | 9876 | |
| ... | ... | @@ -9986,6 +10391,16 @@ pub fn printNode( |
| 9986 | 10391 | .tid = tid, |
| 9987 | 10392 | }), |
| 9988 | 10393 | }), |
| 10394 | .debug_shared => |ss| try w.print("({})", .{ss}), |
| 10395 | .unit_frame, |
| 10396 | .unit_frame_cie, |
| 10397 | .unit_debug_info, |
| 10398 | .unit_debug_info_header, |
| 10399 | .unit_debug_line, |
| 10400 | .unit_debug_line_header, |
| 10401 | => |ui| try w.print("({s})", .{ |
| 10402 | ui.mod(&elf.dwarf).fully_qualified_name, |
| 10403 | }), |
| 9989 | 10404 | .value_debug_info => |cpi| try w.print("({f})", .{ |
| 9990 | 10405 | Value.fromInterned(cpi.val(&elf.dwarf.const_pool)) |
| 9991 | 10406 | .fmtValue(.{ .zcu = elf.base.comp.zcu.?, .tid = tid }), |
| ... | ... | @@ -9999,9 +10414,6 @@ pub fn printNode( |
| 9999 | 10414 | nav.fqn.fmt(ip), |
| 10000 | 10415 | }); |
| 10001 | 10416 | }, |
| 10002 | | .unit_frame, .unit_frame_cie => |ui| try w.print("({s})", .{ |
| 10003 | | ui.mod(&elf.dwarf).fully_qualified_name, |
| 10004 | | }), |
| 10005 | 10417 | .func_frame_fde, .func_debug_info, .func_debug_line => |fi| { |
| 10006 | 10418 | const zcu = elf.base.comp.zcu.?; |
| 10007 | 10419 | const ip = &zcu.intern_pool; |