authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 18:09:23+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 18:09:23+01:00
log1ca004176f8f76b1d54d878e002ebcc4362f9b92
tree8c7dcccfcba5af82d6331fb646d764d6cf3901bb
parent955fd65cb1705d8279eb195bdbc69810df1b1d98

elf+riscv: resolve synthetic __global_pointer$ symbol


1 files changed, 18 insertions(+), 0 deletions(-)

src/link/Elf.zig+18
......@@ -189,6 +189,7 @@ gnu_eh_frame_hdr_index: ?Symbol.Index = null,
189189dso_handle_index: ?Symbol.Index = null,
190190rela_iplt_start_index: ?Symbol.Index = null,
191191rela_iplt_end_index: ?Symbol.Index = null,
192global_pointer_index: ?Symbol.Index = null,
192193start_stop_indexes: std.ArrayListUnmanaged(u32) = .{},
193194
194195/// An array of symbols parsed across all input files.
......@@ -3095,6 +3096,10 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {
30953096 }
30963097 }
30973098
3099 if (self.getTarget().cpu.arch == .riscv64 and self.base.isDynLib()) {
3100 self.global_pointer_index = try linker_defined.addGlobal("__global_pointer$", self);
3101 }
3102
30983103 linker_defined.resolveSymbols(self);
30993104}
31003105
......@@ -3222,6 +3227,19 @@ fn allocateLinkerDefinedSymbols(self: *Elf) void {
32223227 stop.output_section_index = shndx;
32233228 }
32243229 }
3230
3231 // __global_pointer$
3232 if (self.global_pointer_index) |index| {
3233 const sym = self.symbol(index);
3234 if (self.sectionByName(".sdata")) |shndx| {
3235 const shdr = self.shdrs.items[shndx];
3236 sym.value = shdr.sh_addr + 0x800;
3237 sym.output_section_index = shndx;
3238 } else {
3239 sym.value = 0;
3240 sym.output_section_index = 0;
3241 }
3242 }
32253243}
32263244
32273245fn checkDuplicates(self: *Elf) !void {