authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-12 17:52:55+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-09-12 17:52:55+02:00
log9db472cff6573fd1d0f50c8ea1b5ecb536aeff1e
tree43efafe94a39021ce5f182b9d0678d8d46b35ec5
parent472d326a8c88570f629d58539b9829c69730a96b

elf: set output section index of a global when resolving


2 files changed, 12 insertions(+), 2 deletions(-)

src/link/Elf/Object.zig+5
......@@ -434,10 +434,15 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) void {
434434 elf.SHN_ABS, elf.SHN_COMMON => 0,
435435 else => self.atoms.items[esym.st_shndx],
436436 };
437 const output_section_index = if (elf_file.atom(atom_index)) |atom|
438 atom.output_section_index
439 else
440 0;
437441 global.value = esym.st_value;
438442 global.atom_index = atom_index;
439443 global.esym_index = esym_index;
440444 global.file_index = self.index;
445 global.output_section_index = output_section_index;
441446 global.version_index = elf_file.default_sym_version;
442447 if (esym.st_bind() == elf.STB_WEAK) global.flags.weak = true;
443448 }
src/link/Elf/ZigModule.zig+7-2
......@@ -81,7 +81,7 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void {
8181 if (esym.st_shndx == elf.SHN_UNDEF) continue;
8282
8383 if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) {
84 const atom_index = self.atoms.keys()[esym.st_shndx];
84 const atom_index = esym.st_shndx;
8585 const atom = elf_file.atom(atom_index) orelse continue;
8686 if (!atom.alive) continue;
8787 }
......@@ -90,12 +90,17 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void {
9090 if (self.asFile().symbolRank(esym, false) < global.symbolRank(elf_file)) {
9191 const atom_index = switch (esym.st_shndx) {
9292 elf.SHN_ABS, elf.SHN_COMMON => 0,
93 else => self.atoms.keys()[esym.st_shndx],
93 else => esym.st_shndx,
9494 };
95 const output_section_index = if (elf_file.atom(atom_index)) |atom|
96 atom.output_section_index
97 else
98 0;
9599 global.value = esym.st_value;
96100 global.atom_index = atom_index;
97101 global.esym_index = esym_index;
98102 global.file_index = self.index;
103 global.output_section_index = output_section_index;
99104 global.version_index = elf_file.default_sym_version;
100105 if (esym.st_bind() == elf.STB_WEAK) global.flags.weak = true;
101106 }