diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-02-21 18:09:23 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-02-21 18:09:23 +0100 |
| commit | 1ca004176f8f76b1d54d878e002ebcc4362f9b92 (patch) | |
| tree | 8c7dcccfcba5af82d6331fb646d764d6cf3901bb /src/link/Elf.zig | |
| parent | 955fd65cb1705d8279eb195bdbc69810df1b1d98 (diff) | |
| download | zig-1ca004176f8f76b1d54d878e002ebcc4362f9b92.tar.gz zig-1ca004176f8f76b1d54d878e002ebcc4362f9b92.zip | |
elf+riscv: resolve synthetic __global_pointer$ symbol
Diffstat (limited to 'src/link/Elf.zig')
| -rw-r--r-- | src/link/Elf.zig | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig index a6625556e6..597b118807 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -189,6 +189,7 @@ gnu_eh_frame_hdr_index: ?Symbol.Index = null, dso_handle_index: ?Symbol.Index = null, rela_iplt_start_index: ?Symbol.Index = null, rela_iplt_end_index: ?Symbol.Index = null, +global_pointer_index: ?Symbol.Index = null, start_stop_indexes: std.ArrayListUnmanaged(u32) = .{}, /// An array of symbols parsed across all input files. @@ -3095,6 +3096,10 @@ fn addLinkerDefinedSymbols(self: *Elf) !void { } } + if (self.getTarget().cpu.arch == .riscv64 and self.base.isDynLib()) { + self.global_pointer_index = try linker_defined.addGlobal("__global_pointer$", self); + } + linker_defined.resolveSymbols(self); } @@ -3222,6 +3227,19 @@ fn allocateLinkerDefinedSymbols(self: *Elf) void { stop.output_section_index = shndx; } } + + // __global_pointer$ + if (self.global_pointer_index) |index| { + const sym = self.symbol(index); + if (self.sectionByName(".sdata")) |shndx| { + const shdr = self.shdrs.items[shndx]; + sym.value = shdr.sh_addr + 0x800; + sym.output_section_index = shndx; + } else { + sym.value = 0; + sym.output_section_index = 0; + } + } } fn checkDuplicates(self: *Elf) !void { |
