zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 9db472cff6573fd1d0f50c8ea1b5ecb536aeff1e (tree)
parent 472d326a8c88570f629d58539b9829c69730a96b
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Tue, 12 Sep 2023 17:52:55 +0200

elf: set output section index of a global when resolving

Diffstat:
Msrc/link/Elf/Object.zig | 5+++++
Msrc/link/Elf/ZigModule.zig | 9+++++++--
2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig @@ -434,10 +434,15 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) void { elf.SHN_ABS, elf.SHN_COMMON => 0, else => self.atoms.items[esym.st_shndx], }; + const output_section_index = if (elf_file.atom(atom_index)) |atom| + atom.output_section_index + else + 0; global.value = esym.st_value; global.atom_index = atom_index; global.esym_index = esym_index; global.file_index = self.index; + global.output_section_index = output_section_index; global.version_index = elf_file.default_sym_version; if (esym.st_bind() == elf.STB_WEAK) global.flags.weak = true; } diff --git a/src/link/Elf/ZigModule.zig b/src/link/Elf/ZigModule.zig @@ -81,7 +81,7 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void { if (esym.st_shndx == elf.SHN_UNDEF) continue; if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) { - const atom_index = self.atoms.keys()[esym.st_shndx]; + const atom_index = esym.st_shndx; const atom = elf_file.atom(atom_index) orelse continue; if (!atom.alive) continue; } @@ -90,12 +90,17 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void { if (self.asFile().symbolRank(esym, false) < global.symbolRank(elf_file)) { const atom_index = switch (esym.st_shndx) { elf.SHN_ABS, elf.SHN_COMMON => 0, - else => self.atoms.keys()[esym.st_shndx], + else => esym.st_shndx, }; + const output_section_index = if (elf_file.atom(atom_index)) |atom| + atom.output_section_index + else + 0; global.value = esym.st_value; global.atom_index = atom_index; global.esym_index = esym_index; global.file_index = self.index; + global.output_section_index = output_section_index; global.version_index = elf_file.default_sym_version; if (esym.st_bind() == elf.STB_WEAK) global.flags.weak = true; }