link/elf: keep track of sh_entsize per MergeSubsection

This commit is contained in:
Jakub Konka
2024-04-20 22:58:54 +02:00
parent 457d84f45a
commit 4931a291f8
4 changed files with 19 additions and 0 deletions

View File

@@ -3337,6 +3337,7 @@ pub fn addCommentString(self: *Elf) !void {
msub.string_index = res.key.pos;
msub.alignment = .@"1";
msub.size = res.key.len;
msub.entsize = 1;
msub.alive = true;
res.sub.* = msub_index;
}
@@ -3428,6 +3429,14 @@ fn initOutputSections(self: *Elf) !void {
.flags = msec.flags,
});
msec.output_section_index = shndx;
var entsize = self.mergeSubsection(msec.subsections.items[0]).entsize;
for (msec.subsections.items) |index| {
const msub = self.mergeSubsection(index);
entsize = @min(entsize, msub.entsize);
}
const shdr = &self.shdrs.items[shndx];
shdr.sh_entsize = entsize;
}
}

View File

@@ -759,6 +759,7 @@ pub fn resolveMergeSubsections(self: *Object, elf_file: *Elf) !void {
msub.string_index = res.key.pos;
msub.alignment = atom_ptr.alignment;
msub.size = res.key.len;
msub.entsize = math.cast(u32, isec.sh_entsize) orelse return error.Overflow;
msub.alive = !elf_file.base.gc_sections or isec.sh_flags & elf.SHF_ALLOC == 0;
res.sub.* = msub_index;
}

View File

@@ -168,6 +168,7 @@ pub const MergeSubsection = struct {
string_index: u32 = 0,
size: u32 = 0,
alignment: Atom.Alignment = .@"1",
entsize: u32 = 0,
alive: bool = false,
pub fn address(msub: MergeSubsection, elf_file: *Elf) i64 {

View File

@@ -289,6 +289,14 @@ fn initSections(elf_file: *Elf) !void {
.flags = msec.flags,
});
msec.output_section_index = shndx;
var entsize = elf_file.mergeSubsection(msec.subsections.items[0]).entsize;
for (msec.subsections.items) |index| {
const msub = elf_file.mergeSubsection(index);
entsize = @min(entsize, msub.entsize);
}
const shdr = &elf_file.shdrs.items[shndx];
shdr.sh_entsize = entsize;
}
const needs_eh_frame = for (elf_file.objects.items) |index| {