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