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 {...@@ -434,10 +434,15 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) void {
434 elf.SHN_ABS, elf.SHN_COMMON => 0,434 elf.SHN_ABS, elf.SHN_COMMON => 0,
435 else => self.atoms.items[esym.st_shndx],435 else => self.atoms.items[esym.st_shndx],
436 };436 };
437 const output_section_index = if (elf_file.atom(atom_index)) |atom|
438 atom.output_section_index
439 else
440 0;
437 global.value = esym.st_value;441 global.value = esym.st_value;
438 global.atom_index = atom_index;442 global.atom_index = atom_index;
439 global.esym_index = esym_index;443 global.esym_index = esym_index;
440 global.file_index = self.index;444 global.file_index = self.index;
445 global.output_section_index = output_section_index;
441 global.version_index = elf_file.default_sym_version;446 global.version_index = elf_file.default_sym_version;
442 if (esym.st_bind() == elf.STB_WEAK) global.flags.weak = true;447 if (esym.st_bind() == elf.STB_WEAK) global.flags.weak = true;
443 }448 }
src/link/Elf/ZigModule.zig+7-2
...@@ -81,7 +81,7 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void {...@@ -81,7 +81,7 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void {
81 if (esym.st_shndx == elf.SHN_UNDEF) continue;81 if (esym.st_shndx == elf.SHN_UNDEF) continue;
8282
83 if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) {83 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;
85 const atom = elf_file.atom(atom_index) orelse continue;85 const atom = elf_file.atom(atom_index) orelse continue;
86 if (!atom.alive) continue;86 if (!atom.alive) continue;
87 }87 }
...@@ -90,12 +90,17 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void {...@@ -90,12 +90,17 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void {
90 if (self.asFile().symbolRank(esym, false) < global.symbolRank(elf_file)) {90 if (self.asFile().symbolRank(esym, false) < global.symbolRank(elf_file)) {
91 const atom_index = switch (esym.st_shndx) {91 const atom_index = switch (esym.st_shndx) {
92 elf.SHN_ABS, elf.SHN_COMMON => 0,92 elf.SHN_ABS, elf.SHN_COMMON => 0,
93 else => self.atoms.keys()[esym.st_shndx],93 else => esym.st_shndx,
94 };94 };
95 const output_section_index = if (elf_file.atom(atom_index)) |atom|
96 atom.output_section_index
97 else
98 0;
95 global.value = esym.st_value;99 global.value = esym.st_value;
96 global.atom_index = atom_index;100 global.atom_index = atom_index;
97 global.esym_index = esym_index;101 global.esym_index = esym_index;
98 global.file_index = self.index;102 global.file_index = self.index;
103 global.output_section_index = output_section_index;
99 global.version_index = elf_file.default_sym_version;104 global.version_index = elf_file.default_sym_version;
100 if (esym.st_bind() == elf.STB_WEAK) global.flags.weak = true;105 if (esym.st_bind() == elf.STB_WEAK) global.flags.weak = true;
101 }106 }