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,...@@ -189,6 +189,7 @@ gnu_eh_frame_hdr_index: ?Symbol.Index = null,
189dso_handle_index: ?Symbol.Index = null,189dso_handle_index: ?Symbol.Index = null,
190rela_iplt_start_index: ?Symbol.Index = null,190rela_iplt_start_index: ?Symbol.Index = null,
191rela_iplt_end_index: ?Symbol.Index = null,191rela_iplt_end_index: ?Symbol.Index = null,
192global_pointer_index: ?Symbol.Index = null,
192start_stop_indexes: std.ArrayListUnmanaged(u32) = .{},193start_stop_indexes: std.ArrayListUnmanaged(u32) = .{},
193194
194/// An array of symbols parsed across all input files.195/// An array of symbols parsed across all input files.
...@@ -3095,6 +3096,10 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {...@@ -3095,6 +3096,10 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {
3095 }3096 }
3096 }3097 }
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
3098 linker_defined.resolveSymbols(self);3103 linker_defined.resolveSymbols(self);
3099}3104}
31003105
...@@ -3222,6 +3227,19 @@ fn allocateLinkerDefinedSymbols(self: *Elf) void {...@@ -3222,6 +3227,19 @@ fn allocateLinkerDefinedSymbols(self: *Elf) void {
3222 stop.output_section_index = shndx;3227 stop.output_section_index = shndx;
3223 }3228 }
3224 }3229 }
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 }
3225}3243}
32263244
3227fn checkDuplicates(self: *Elf) !void {3245fn checkDuplicates(self: *Elf) !void {