From 1af0f4cd00f7a6b9150346449d2e7dc14798bada Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Fri, 23 Aug 2024 10:41:21 +0200 Subject: [PATCH] elf: fix setting sh_info and sh_link for manually managed rela sections --- src/link/Elf.zig | 104 +++++++++++++++++++++++------------------------ 1 file changed, 52 insertions(+), 52 deletions(-) diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 41fe3de0e9174bf7c55800aa05822f7cf86cbbab..2d6bade67de7f33a3365d5b23ec07144c805070d 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -3367,58 +3367,6 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { } } - if (self.symtab_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - shdr.sh_link = self.strtab_section_index.?; - } - - if (self.dynamic_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - shdr.sh_link = self.dynstrtab_section_index.?; - } - - if (self.dynsymtab_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - shdr.sh_link = self.dynstrtab_section_index.?; - } - - if (self.hash_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - shdr.sh_link = self.dynsymtab_section_index.?; - } - - if (self.gnu_hash_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - shdr.sh_link = self.dynsymtab_section_index.?; - } - - if (self.versym_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - shdr.sh_link = self.dynsymtab_section_index.?; - } - - if (self.verneed_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - shdr.sh_link = self.dynstrtab_section_index.?; - } - - if (self.rela_dyn_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - shdr.sh_link = self.dynsymtab_section_index orelse 0; - } - - if (self.rela_plt_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - shdr.sh_link = self.dynsymtab_section_index.?; - shdr.sh_info = self.plt_section_index.?; - } - - if (self.eh_frame_rela_section_index) |index| { - const shdr = &self.sections.items(.shdr)[index]; - 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]; } @@ -3440,6 +3388,58 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { 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.?; + } + + if (self.dynamic_section_index) |index| { + const shdr = &self.sections.items(.shdr)[index]; + shdr.sh_link = self.dynstrtab_section_index.?; + } + + if (self.dynsymtab_section_index) |index| { + const shdr = &self.sections.items(.shdr)[index]; + shdr.sh_link = self.dynstrtab_section_index.?; + } + + if (self.hash_section_index) |index| { + const shdr = &self.sections.items(.shdr)[index]; + shdr.sh_link = self.dynsymtab_section_index.?; + } + + if (self.gnu_hash_section_index) |index| { + const shdr = &self.sections.items(.shdr)[index]; + shdr.sh_link = self.dynsymtab_section_index.?; + } + + if (self.versym_section_index) |index| { + const shdr = &self.sections.items(.shdr)[index]; + shdr.sh_link = self.dynsymtab_section_index.?; + } + + if (self.verneed_section_index) |index| { + const shdr = &self.sections.items(.shdr)[index]; + shdr.sh_link = self.dynstrtab_section_index.?; + } + + if (self.rela_dyn_section_index) |index| { + const shdr = &self.sections.items(.shdr)[index]; + shdr.sh_link = self.dynsymtab_section_index orelse 0; + } + + if (self.rela_plt_section_index) |index| { + const shdr = &self.sections.items(.shdr)[index]; + shdr.sh_link = self.dynsymtab_section_index.?; + shdr.sh_info = self.plt_section_index.?; + } + + if (self.eh_frame_rela_section_index) |index| { + const shdr = &self.sections.items(.shdr)[index]; + shdr.sh_link = self.symtab_section_index.?; + shdr.sh_info = self.eh_frame_section_index.?; + } } fn updateSectionSizes(self: *Elf) !void { -- 2.54.0