diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-10-04 12:46:57 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-10-09 12:38:53 -0700 |
| commit | e448fb960137e5aa83a1e7c2e6cbbf688f4fce05 (patch) | |
| tree | 1ffad6ca3fe35659df183971fdc9c2bc85d835ac /src/link/Elf.zig | |
| parent | c92c72d08cfb102206594d723e29dd0616290d31 (diff) | |
| download | zig-e448fb960137e5aa83a1e7c2e6cbbf688f4fce05.tar.gz zig-e448fb960137e5aa83a1e7c2e6cbbf688f4fce05.zip | |
elf: change how we manage debug atoms in Dwarf linker
Diffstat (limited to 'src/link/Elf.zig')
| -rw-r--r-- | src/link/Elf.zig | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig index c4cbb107bc..511ce57b3e 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -573,10 +573,10 @@ pub fn growSection(self: *Elf, shdr_index: u32, needed_size: u64, min_alignment: // Must move the entire section. const new_offset = try self.findFreeSpace(needed_size, min_alignment); - log.debug("new '{s}' file offset 0x{x} to 0x{x}", .{ + log.debug("moving '{s}' from 0x{x} to 0x{x}", .{ self.getShString(shdr.sh_name), + shdr.sh_offset, new_offset, - new_offset + existing_size, }); const amt = try self.base.file.?.copyRangeAll( @@ -691,13 +691,6 @@ pub fn allocateChunk(self: *Elf, args: struct { } }; - log.debug("allocated chunk (size({x}),align({x})) at 0x{x} (file(0x{x}))", .{ - args.size, - args.alignment.toByteUnits().?, - shdr.sh_addr + res.value, - shdr.sh_offset + res.value, - }); - const expand_section = if (self.atom(res.placement)) |placement_atom| placement_atom.nextAtom(self) == null else @@ -707,6 +700,18 @@ pub fn allocateChunk(self: *Elf, args: struct { try self.growSection(args.shndx, needed_size, args.alignment.toByteUnits().?); } + log.debug("allocated chunk (size({x}),align({x})) in {s} at 0x{x} (file(0x{x}))", .{ + args.size, + args.alignment.toByteUnits().?, + self.getShString(shdr.sh_name), + shdr.sh_addr + res.value, + shdr.sh_offset + res.value, + }); + log.debug(" placement {}, {s}", .{ + res.placement, + if (self.atom(res.placement)) |atom_ptr| atom_ptr.name(self) else "", + }); + return res; } @@ -1796,6 +1801,7 @@ pub fn initOutputSection(self: *Elf, args: struct { .type = @"type", .flags = flags, .name = try self.insertShString(name), + .offset = std.math.maxInt(u64), }); return out_shndx; } @@ -3898,27 +3904,14 @@ pub fn allocateNonAllocSections(self: *Elf) !void { shdr.sh_size = 0; const new_offset = try self.findFreeSpace(needed_size, shdr.sh_addralign); - if (self.zigObjectPtr()) |zo| blk: { - const existing_size = for ([_]?Symbol.Index{ - zo.debug_info_index, - zo.debug_abbrev_index, - zo.debug_aranges_index, - zo.debug_str_index, - zo.debug_line_index, - zo.debug_line_str_index, - zo.debug_loclists_index, - zo.debug_rnglists_index, - }) |maybe_sym_index| { - const sym_index = maybe_sym_index orelse continue; - const sym = zo.symbol(sym_index); - const atom_ptr = sym.atom(self).?; - if (atom_ptr.output_section_index == shndx) break atom_ptr.size; - } else break :blk; - log.debug("moving {s} from 0x{x} to 0x{x}", .{ - self.getShString(shdr.sh_name), - shdr.sh_offset, - new_offset, - }); + log.debug("moving {s} from 0x{x} to 0x{x}", .{ + self.getShString(shdr.sh_name), + shdr.sh_offset, + new_offset, + }); + + if (shdr.sh_offset > 0) { + const existing_size = self.sectionSize(@intCast(shndx)); const amt = try self.base.file.?.copyRangeAll( shdr.sh_offset, self.base.file.?, |
