| ... | @@ -2289,31 +2289,43 @@ fn allocateLocalSymbol(self: *Elf) !u32 { | ... | @@ -2289,31 +2289,43 @@ fn allocateLocalSymbol(self: *Elf) !u32 { |
| 2289 | return index; | 2289 | return index; |
| 2290 | } | 2290 | } |
| 2291 | | 2291 | |
| | 2292 | fn allocateGotOffset(self: *Elf) !u32 { |
| | 2293 | try self.offset_table.ensureUnusedCapacity(self.base.allocator, 1); |
| | 2294 | |
| | 2295 | const index = blk: { |
| | 2296 | if (self.offset_table_free_list.popOrNull()) |index| { |
| | 2297 | log.debug(" (reusing GOT offset at index {d})", .{index}); |
| | 2298 | break :blk index; |
| | 2299 | } else { |
| | 2300 | log.debug(" (allocating GOT offset at index {d})", .{self.offset_table.items.len}); |
| | 2301 | const index = @intCast(u32, self.offset_table.items.len); |
| | 2302 | _ = self.offset_table.addOneAssumeCapacity(); |
| | 2303 | self.offset_table_count_dirty = true; |
| | 2304 | break :blk index; |
| | 2305 | } |
| | 2306 | }; |
| | 2307 | |
| | 2308 | self.offset_table.items[index] = 0; |
| | 2309 | return index; |
| | 2310 | } |
| | 2311 | |
| 2292 | pub fn allocateDeclIndexes(self: *Elf, decl_index: Module.Decl.Index) !void { | 2312 | pub fn allocateDeclIndexes(self: *Elf, decl_index: Module.Decl.Index) !void { |
| 2293 | if (self.llvm_object) |_| return; | 2313 | if (self.llvm_object) |_| return; |
| 2294 | | 2314 | |
| 2295 | const mod = self.base.options.module.?; | 2315 | const mod = self.base.options.module.?; |
| 2296 | const decl = mod.declPtr(decl_index); | 2316 | const decl = mod.declPtr(decl_index); |
| 2297 | if (decl.link.elf.local_sym_index != 0) return; | 2317 | const block = &decl.link.elf; |
| 2298 | | 2318 | if (block.local_sym_index != 0) return; |
| 2299 | try self.offset_table.ensureUnusedCapacity(self.base.allocator, 1); | | |
| 2300 | try self.decls.putNoClobber(self.base.allocator, decl_index, null); | | |
| 2301 | | 2319 | |
| 2302 | const decl_name = try decl.getFullyQualifiedName(mod); | 2320 | const decl_name = try decl.getFullyQualifiedName(mod); |
| 2303 | defer self.base.allocator.free(decl_name); | 2321 | defer self.base.allocator.free(decl_name); |
| 2304 | | 2322 | |
| 2305 | log.debug("allocating symbol indexes for {s}", .{decl_name}); | 2323 | log.debug("allocating symbol indexes for {s}", .{decl_name}); |
| 2306 | decl.link.elf.local_sym_index = try self.allocateLocalSymbol(); | | |
| 2307 | try self.atom_by_index_table.putNoClobber(self.base.allocator, decl.link.elf.local_sym_index, &decl.link.elf); | | |
| 2308 | | 2324 | |
| 2309 | if (self.offset_table_free_list.popOrNull()) |i| { | 2325 | block.local_sym_index = try self.allocateLocalSymbol(); |
| 2310 | decl.link.elf.offset_table_index = i; | 2326 | block.offset_table_index = try self.allocateGotOffset(); |
| 2311 | } else { | 2327 | try self.atom_by_index_table.putNoClobber(self.base.allocator, block.local_sym_index, block); |
| 2312 | decl.link.elf.offset_table_index = @intCast(u32, self.offset_table.items.len); | 2328 | try self.decls.putNoClobber(self.base.allocator, decl_index, null); |
| 2313 | _ = self.offset_table.addOneAssumeCapacity(); | | |
| 2314 | self.offset_table_count_dirty = true; | | |
| 2315 | } | | |
| 2316 | self.offset_table.items[decl.link.elf.offset_table_index] = 0; | | |
| 2317 | } | 2329 | } |
| 2318 | | 2330 | |
| 2319 | fn freeUnnamedConsts(self: *Elf, decl_index: Module.Decl.Index) void { | 2331 | fn freeUnnamedConsts(self: *Elf, decl_index: Module.Decl.Index) void { |