Skip to content

Commit

Permalink
elf: fix setting sh_info and sh_link for manually managed rela sections
Browse files Browse the repository at this point in the history
  • Loading branch information
kubkon committed Aug 25, 2024
1 parent 7173ea1 commit 1af0f4c
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/link/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,28 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void {
}
}

for (self.merge_sections.items) |*msec| {
msec.output_section_index = backlinks[msec.output_section_index];
}

for (self.sections.items(.shdr)) |*shdr| {
if (shdr.sh_type != elf.SHT_RELA) continue;
shdr.sh_link = backlinks[shdr.sh_link];
shdr.sh_info = backlinks[shdr.sh_info];
}

if (self.zigObjectPtr()) |zo| {
for (zo.atoms_indexes.items) |atom_index| {
const atom_ptr = zo.atom(atom_index) orelse continue;
atom_ptr.output_section_index = backlinks[atom_ptr.output_section_index];
}
if (zo.dwarf) |*dwarf| dwarf.reloadSectionMetadata();
}

for (self.comdat_group_sections.items) |*cg| {
cg.shndx = backlinks[cg.shndx];
}

if (self.symtab_section_index) |index| {
const shdr = &self.sections.items(.shdr)[index];
shdr.sh_link = self.strtab_section_index.?;
Expand Down Expand Up @@ -3418,28 +3440,6 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void {
shdr.sh_link = self.symtab_section_index.?;
shdr.sh_info = self.eh_frame_section_index.?;
}

for (self.merge_sections.items) |*msec| {
msec.output_section_index = backlinks[msec.output_section_index];
}

for (self.sections.items(.shdr)) |*shdr| {
if (shdr.sh_type != elf.SHT_RELA) continue;
shdr.sh_link = backlinks[shdr.sh_link];
shdr.sh_info = backlinks[shdr.sh_info];
}

if (self.zigObjectPtr()) |zo| {
for (zo.atoms_indexes.items) |atom_index| {
const atom_ptr = zo.atom(atom_index) orelse continue;
atom_ptr.output_section_index = backlinks[atom_ptr.output_section_index];
}
if (zo.dwarf) |*dwarf| dwarf.reloadSectionMetadata();
}

for (self.comdat_group_sections.items) |*cg| {
cg.shndx = backlinks[cg.shndx];
}
}

fn updateSectionSizes(self: *Elf) !void {
Expand Down

0 comments on commit 1af0f4c

Please sign in to comment.