| ... | ... | @@ -803,7 +803,7 @@ pub fn writeAr(self: ZigObject, writer: anytype) !void { |
| 803 | 803 | try writer.writeAll(self.data.items); |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | | pub fn addAtomsToRelaSections(self: *ZigObject, elf_file: *Elf) !void { |
| 806 | pub fn initRelaSections(self: *ZigObject, elf_file: *Elf) !void { |
| 807 | 807 | const gpa = elf_file.base.comp.gpa; |
| 808 | 808 | for (self.atoms_indexes.items) |atom_index| { |
| 809 | 809 | const atom_ptr = self.atom(atom_index) orelse continue; |
| ... | ... | @@ -819,10 +819,28 @@ pub fn addAtomsToRelaSections(self: *ZigObject, elf_file: *Elf) !void { |
| 819 | 819 | elf_file.getShString(out_shdr.sh_name), |
| 820 | 820 | }); |
| 821 | 821 | defer gpa.free(rela_sect_name); |
| 822 | | const out_rela_shndx = if (elf_file.sectionByName(rela_sect_name)) |out_rela_shndx| |
| 823 | | out_rela_shndx |
| 824 | | else |
| 822 | _ = elf_file.sectionByName(rela_sect_name) orelse |
| 825 | 823 | try elf_file.addRelaShdr(try elf_file.insertShString(rela_sect_name), out_shndx); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | pub fn addAtomsToRelaSections(self: *ZigObject, elf_file: *Elf) !void { |
| 828 | const gpa = elf_file.base.comp.gpa; |
| 829 | for (self.atoms_indexes.items) |atom_index| { |
| 830 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 831 | if (!atom_ptr.alive) continue; |
| 832 | if (atom_ptr.output_section_index == elf_file.eh_frame_section_index) continue; |
| 833 | const rela_shndx = atom_ptr.relocsShndx() orelse continue; |
| 834 | // TODO this check will become obsolete when we rework our relocs mechanism at the ZigObject level |
| 835 | if (self.relocs.items[rela_shndx].items.len == 0) continue; |
| 836 | const out_shndx = atom_ptr.output_section_index; |
| 837 | const out_shdr = elf_file.sections.items(.shdr)[out_shndx]; |
| 838 | if (out_shdr.sh_type == elf.SHT_NOBITS) continue; |
| 839 | const rela_sect_name = try std.fmt.allocPrintZ(gpa, ".rela{s}", .{ |
| 840 | elf_file.getShString(out_shdr.sh_name), |
| 841 | }); |
| 842 | defer gpa.free(rela_sect_name); |
| 843 | const out_rela_shndx = elf_file.sectionByName(rela_sect_name).?; |
| 826 | 844 | const out_rela_shdr = &elf_file.sections.items(.shdr)[out_rela_shndx]; |
| 827 | 845 | out_rela_shdr.sh_info = out_shndx; |
| 828 | 846 | out_rela_shdr.sh_link = elf_file.symtab_section_index.?; |