| author | |
| committer | |
| log | e79ac14ef34d8ceea945de972b7f395b8f53621f |
| tree | 1dcda4337dc446f1d1c5e3bb478ea4b9678c383c |
| parent | db48a789632ed901cedfa9af480bb987c23fcdbf |
3 files changed, 46 insertions(+), 96 deletions(-)
src/link/Elf.zig+30-38| ... | ... | @@ -4184,26 +4184,21 @@ pub fn allocateNonAllocSections(self: *Elf) !void { |
| 4184 | 4184 | shdr.sh_offset, |
| 4185 | 4185 | new_offset, |
| 4186 | 4186 | }); |
| 4187 | const zig_object = self.zigObjectPtr().?; | |
| 4188 | const existing_size = blk: { | |
| 4189 | if (shndx == self.debug_info_section_index.?) | |
| 4190 | break :blk zig_object.debug_info_section_zig_size; | |
| 4191 | if (shndx == self.debug_abbrev_section_index.?) | |
| 4192 | break :blk zig_object.debug_abbrev_section_zig_size; | |
| 4193 | if (shndx == self.debug_str_section_index.?) | |
| 4194 | break :blk zig_object.debug_str_section_zig_size; | |
| 4195 | if (shndx == self.debug_aranges_section_index.?) | |
| 4196 | break :blk zig_object.debug_aranges_section_zig_size; | |
| 4197 | if (shndx == self.debug_line_section_index.?) | |
| 4198 | break :blk zig_object.debug_line_section_zig_size; | |
| 4199 | if (shndx == self.debug_line_str_section_index.?) | |
| 4200 | break :blk zig_object.debug_line_str_section_zig_size; | |
| 4201 | if (shndx == self.debug_loclists_section_index.?) | |
| 4202 | break :blk zig_object.debug_loclists_section_zig_size; | |
| 4203 | if (shndx == self.debug_rnglists_section_index.?) | |
| 4204 | break :blk zig_object.debug_rnglists_section_zig_size; | |
| 4205 | unreachable; | |
| 4206 | }; | |
| 4187 | const zo = self.zigObjectPtr().?; | |
| 4188 | const existing_size = for ([_]Symbol.Index{ | |
| 4189 | zo.debug_info_index.?, | |
| 4190 | zo.debug_abbrev_index.?, | |
| 4191 | zo.debug_aranges_index.?, | |
| 4192 | zo.debug_str_index.?, | |
| 4193 | zo.debug_line_index.?, | |
| 4194 | zo.debug_line_str_index.?, | |
| 4195 | zo.debug_loclists_index.?, | |
| 4196 | zo.debug_rnglists_index.?, | |
| 4197 | }) |sym_index| { | |
| 4198 | const sym = zo.symbol(sym_index); | |
| 4199 | const atom_ptr = sym.atom(self).?; | |
| 4200 | if (atom_ptr.output_section_index == shndx) break atom_ptr.size; | |
| 4201 | } else 0; | |
| 4207 | 4202 | const amt = try self.base.file.?.copyRangeAll( |
| 4208 | 4203 | shdr.sh_offset, |
| 4209 | 4204 | self.base.file.?, |
| ... | ... | @@ -4299,24 +4294,21 @@ fn writeAtoms(self: *Elf) !void { |
| 4299 | 4294 | |
| 4300 | 4295 | // TODO really, really handle debug section separately |
| 4301 | 4296 | const base_offset = if (self.isDebugSection(@intCast(shndx))) blk: { |
| 4302 | const zig_object = self.zigObjectPtr().?; | |
| 4303 | if (shndx == self.debug_info_section_index.?) | |
| 4304 | break :blk zig_object.debug_info_section_zig_size; | |
| 4305 | if (shndx == self.debug_abbrev_section_index.?) | |
| 4306 | break :blk zig_object.debug_abbrev_section_zig_size; | |
| 4307 | if (shndx == self.debug_str_section_index.?) | |
| 4308 | break :blk zig_object.debug_str_section_zig_size; | |
| 4309 | if (shndx == self.debug_aranges_section_index.?) | |
| 4310 | break :blk zig_object.debug_aranges_section_zig_size; | |
| 4311 | if (shndx == self.debug_line_section_index.?) | |
| 4312 | break :blk zig_object.debug_line_section_zig_size; | |
| 4313 | if (shndx == self.debug_line_str_section_index.?) | |
| 4314 | break :blk zig_object.debug_line_str_section_zig_size; | |
| 4315 | if (shndx == self.debug_loclists_section_index.?) | |
| 4316 | break :blk zig_object.debug_loclists_section_zig_size; | |
| 4317 | if (shndx == self.debug_rnglists_section_index.?) | |
| 4318 | break :blk zig_object.debug_rnglists_section_zig_size; | |
| 4319 | unreachable; | |
| 4297 | const zo = self.zigObjectPtr().?; | |
| 4298 | break :blk for ([_]Symbol.Index{ | |
| 4299 | zo.debug_info_index.?, | |
| 4300 | zo.debug_abbrev_index.?, | |
| 4301 | zo.debug_aranges_index.?, | |
| 4302 | zo.debug_str_index.?, | |
| 4303 | zo.debug_line_index.?, | |
| 4304 | zo.debug_line_str_index.?, | |
| 4305 | zo.debug_loclists_index.?, | |
| 4306 | zo.debug_rnglists_index.?, | |
| 4307 | }) |sym_index| { | |
| 4308 | const sym = zo.symbol(sym_index); | |
| 4309 | const atom_ptr = sym.atom(self).?; | |
| 4310 | if (atom_ptr.output_section_index == shndx) break atom_ptr.size; | |
| 4311 | } else 0; | |
| 4320 | 4312 | } else 0; |
| 4321 | 4313 | const sh_offset = shdr.sh_offset + base_offset; |
| 4322 | 4314 | const sh_size = math.cast(usize, shdr.sh_size - base_offset) orelse return error.Overflow; |
src/link/Elf/ZigObject.zig-40| ... | ... | @@ -59,17 +59,6 @@ debug_line_str_index: ?Symbol.Index = null, |
| 59 | 59 | debug_loclists_index: ?Symbol.Index = null, |
| 60 | 60 | debug_rnglists_index: ?Symbol.Index = null, |
| 61 | 61 | |
| 62 | /// Size contribution of Zig's metadata to each debug section. | |
| 63 | /// Used to track start of metadata from input object files. | |
| 64 | debug_info_section_zig_size: u64 = 0, | |
| 65 | debug_abbrev_section_zig_size: u64 = 0, | |
| 66 | debug_str_section_zig_size: u64 = 0, | |
| 67 | debug_aranges_section_zig_size: u64 = 0, | |
| 68 | debug_line_section_zig_size: u64 = 0, | |
| 69 | debug_line_str_section_zig_size: u64 = 0, | |
| 70 | debug_loclists_section_zig_size: u64 = 0, | |
| 71 | debug_rnglists_section_zig_size: u64 = 0, | |
| 72 | ||
| 73 | 62 | pub const global_symbol_bit: u32 = 0x80000000; |
| 74 | 63 | pub const symbol_mask: u32 = 0x7fffffff; |
| 75 | 64 | pub const SHN_ATOM: u16 = 0x100; |
| ... | ... | @@ -328,8 +317,6 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 328 | 317 | self.debug_aranges_section_dirty = false; |
| 329 | 318 | self.debug_rnglists_section_dirty = false; |
| 330 | 319 | self.debug_str_section_dirty = false; |
| 331 | ||
| 332 | self.saveDebugSectionsSizes(elf_file); | |
| 333 | 320 | } |
| 334 | 321 | |
| 335 | 322 | // The point of flushModule() is to commit changes, so in theory, nothing should |
| ... | ... | @@ -342,33 +329,6 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 342 | 329 | assert(!self.debug_str_section_dirty); |
| 343 | 330 | } |
| 344 | 331 | |
| 345 | fn saveDebugSectionsSizes(self: *ZigObject, elf_file: *Elf) void { | |
| 346 | if (elf_file.debug_info_section_index) |shndx| { | |
| 347 | self.debug_info_section_zig_size = elf_file.shdrs.items[shndx].sh_size; | |
| 348 | } | |
| 349 | if (elf_file.debug_abbrev_section_index) |shndx| { | |
| 350 | self.debug_abbrev_section_zig_size = elf_file.shdrs.items[shndx].sh_size; | |
| 351 | } | |
| 352 | if (elf_file.debug_str_section_index) |shndx| { | |
| 353 | self.debug_str_section_zig_size = elf_file.shdrs.items[shndx].sh_size; | |
| 354 | } | |
| 355 | if (elf_file.debug_aranges_section_index) |shndx| { | |
| 356 | self.debug_aranges_section_zig_size = elf_file.shdrs.items[shndx].sh_size; | |
| 357 | } | |
| 358 | if (elf_file.debug_line_section_index) |shndx| { | |
| 359 | self.debug_line_section_zig_size = elf_file.shdrs.items[shndx].sh_size; | |
| 360 | } | |
| 361 | if (elf_file.debug_line_str_section_index) |shndx| { | |
| 362 | self.debug_line_str_section_zig_size = elf_file.shdrs.items[shndx].sh_size; | |
| 363 | } | |
| 364 | if (elf_file.debug_loclists_section_index) |shndx| { | |
| 365 | self.debug_loclists_section_zig_size = elf_file.shdrs.items[shndx].sh_size; | |
| 366 | } | |
| 367 | if (elf_file.debug_rnglists_section_index) |shndx| { | |
| 368 | self.debug_rnglists_section_zig_size = elf_file.shdrs.items[shndx].sh_size; | |
| 369 | } | |
| 370 | } | |
| 371 | ||
| 372 | 332 | fn newSymbol(self: *ZigObject, allocator: Allocator, name_off: u32, st_bind: u4) !Symbol.Index { |
| 373 | 333 | try self.symtab.ensureUnusedCapacity(allocator, 1); |
| 374 | 334 | try self.symbols.ensureUnusedCapacity(allocator, 1); |
src/link/Elf/relocatable.zig+16-18| ... | ... | @@ -431,24 +431,21 @@ fn writeAtoms(elf_file: *Elf) !void { |
| 431 | 431 | |
| 432 | 432 | // TODO really, really handle debug section separately |
| 433 | 433 | const base_offset = if (elf_file.isDebugSection(@intCast(shndx))) blk: { |
| 434 | const zig_object = elf_file.zigObjectPtr().?; | |
| 435 | if (shndx == elf_file.debug_info_section_index.?) | |
| 436 | break :blk zig_object.debug_info_section_zig_size; | |
| 437 | if (shndx == elf_file.debug_abbrev_section_index.?) | |
| 438 | break :blk zig_object.debug_abbrev_section_zig_size; | |
| 439 | if (shndx == elf_file.debug_str_section_index.?) | |
| 440 | break :blk zig_object.debug_str_section_zig_size; | |
| 441 | if (shndx == elf_file.debug_aranges_section_index.?) | |
| 442 | break :blk zig_object.debug_aranges_section_zig_size; | |
| 443 | if (shndx == elf_file.debug_line_section_index.?) | |
| 444 | break :blk zig_object.debug_line_section_zig_size; | |
| 445 | if (shndx == elf_file.debug_line_str_section_index.?) | |
| 446 | break :blk zig_object.debug_line_str_section_zig_size; | |
| 447 | if (shndx == elf_file.debug_loclists_section_index.?) | |
| 448 | break :blk zig_object.debug_loclists_section_zig_size; | |
| 449 | if (shndx == elf_file.debug_rnglists_section_index.?) | |
| 450 | break :blk zig_object.debug_rnglists_section_zig_size; | |
| 451 | unreachable; | |
| 434 | const zo = elf_file.zigObjectPtr().?; | |
| 435 | break :blk for ([_]Symbol.Index{ | |
| 436 | zo.debug_info_index.?, | |
| 437 | zo.debug_abbrev_index.?, | |
| 438 | zo.debug_aranges_index.?, | |
| 439 | zo.debug_str_index.?, | |
| 440 | zo.debug_line_index.?, | |
| 441 | zo.debug_line_str_index.?, | |
| 442 | zo.debug_loclists_index.?, | |
| 443 | zo.debug_rnglists_index.?, | |
| 444 | }) |sym_index| { | |
| 445 | const sym = zo.symbol(sym_index); | |
| 446 | const atom_ptr = sym.atom(elf_file).?; | |
| 447 | if (atom_ptr.output_section_index == shndx) break atom_ptr.size; | |
| 448 | } else 0; | |
| 452 | 449 | } else 0; |
| 453 | 450 | const sh_offset = shdr.sh_offset + base_offset; |
| 454 | 451 | const sh_size = math.cast(usize, shdr.sh_size - base_offset) orelse return error.Overflow; |
| ... | ... | @@ -594,3 +591,4 @@ const Compilation = @import("../../Compilation.zig"); |
| 594 | 591 | const Elf = @import("../Elf.zig"); |
| 595 | 592 | const File = @import("file.zig").File; |
| 596 | 593 | const Object = @import("Object.zig"); |
| 594 | const Symbol = @import("Symbol.zig"); |