authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-10-03 17:04:15+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-09 12:38:53-07:00
log3d315f45d8237dabb9c0a1782177c92265dfc20b
tree7a214034eff953e31564a5af07e02ec3a7eb31b9
parent0e5cd112ef6e50cbebd7a65a048f541023dcb49c

elf: drastically simplify extracting section size logic


1 files changed, 7 insertions(+), 16 deletions(-)

src/link/Elf.zig+7-16
......@@ -3868,22 +3868,7 @@ pub fn allocateAllocSections(self: *Elf) !void {
38683868
38693869 if (shdr.sh_offset > 0) {
38703870 // Get size actually commited to the output file.
3871 const existing_size = if (self.zigObjectPtr()) |zo| for ([_]?Symbol.Index{
3872 zo.text_index,
3873 zo.rodata_index,
3874 zo.data_relro_index,
3875 zo.data_index,
3876 zo.tdata_index,
3877 zo.eh_frame_index,
3878 }) |maybe_sym_index| {
3879 const sect_sym_index = maybe_sym_index orelse continue;
3880 const sect_atom_ptr = zo.symbol(sect_sym_index).atom(self).?;
3881 if (sect_atom_ptr.output_section_index != shndx) continue;
3882 break sect_atom_ptr.size;
3883 } else 0 else 0 + if (!slice.items(.atom_list_2)[shndx].dirty)
3884 slice.items(.atom_list_2)[shndx].size
3885 else
3886 0;
3871 const existing_size = self.sectionSize(shndx);
38873872 const amt = try self.base.file.?.copyRangeAll(
38883873 shdr.sh_offset,
38893874 self.base.file.?,
......@@ -5682,6 +5667,12 @@ const Section = struct {
56825667 free_list: std.ArrayListUnmanaged(Ref) = .empty,
56835668};
56845669
5670pub fn sectionSize(self: *Elf, shndx: u32) u64 {
5671 const last_atom_ref = self.sections.items(.last_atom)[shndx];
5672 const atom_ptr = self.atom(last_atom_ref) orelse return 0;
5673 return @as(u64, @intCast(atom_ptr.value)) + atom_ptr.size;
5674}
5675
56855676fn defaultEntrySymbolName(cpu_arch: std.Target.Cpu.Arch) []const u8 {
56865677 return switch (cpu_arch) {
56875678 .mips, .mipsel, .mips64, .mips64el => "__start",