authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-07-30 14:59:59+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-08-07 10:21:02+02:00
log518c7908f01cafac9acfbbb708fc49d2c3b5d460
tree1091aff77fc5b0011d72dc257dbdf868b6785261
parentf9f894200891c8af6ce3a3ad222cd0bf1ee15587

elf: always create symbol extra


7 files changed, 31 insertions(+), 44 deletions(-)

src/link/Elf.zig+4-18
...@@ -176,7 +176,6 @@ symtab_section_index: ?u32 = null,...@@ -176,7 +176,6 @@ symtab_section_index: ?u32 = null,
176/// An array of symbols parsed across all input files.176/// An array of symbols parsed across all input files.
177symbols: std.ArrayListUnmanaged(Symbol) = .{},177symbols: std.ArrayListUnmanaged(Symbol) = .{},
178symbols_extra: std.ArrayListUnmanaged(u32) = .{},178symbols_extra: std.ArrayListUnmanaged(u32) = .{},
179symbols_free_list: std.ArrayListUnmanaged(Symbol.Index) = .{},
180179
181resolver: std.AutoArrayHashMapUnmanaged(u32, Symbol.Index) = .{},180resolver: std.AutoArrayHashMapUnmanaged(u32, Symbol.Index) = .{},
182181
...@@ -343,8 +342,6 @@ pub fn createEmpty(...@@ -343,8 +342,6 @@ pub fn createEmpty(
343342
344 // Index 0 is always a null symbol.343 // Index 0 is always a null symbol.
345 try self.symbols.append(gpa, .{});344 try self.symbols.append(gpa, .{});
346 // Index 0 is always a null symbol.
347 try self.symbols_extra.append(gpa, 0);
348 // Append null file at index 0345 // Append null file at index 0
349 try self.files.append(gpa, .null);346 try self.files.append(gpa, .null);
350 // Append null byte to string tables347 // Append null byte to string tables
...@@ -462,7 +459,6 @@ pub fn deinit(self: *Elf) void {...@@ -462,7 +459,6 @@ pub fn deinit(self: *Elf) void {
462 self.strtab.deinit(gpa);459 self.strtab.deinit(gpa);
463 self.symbols.deinit(gpa);460 self.symbols.deinit(gpa);
464 self.symbols_extra.deinit(gpa);461 self.symbols_extra.deinit(gpa);
465 self.symbols_free_list.deinit(gpa);
466 self.resolver.deinit(gpa);462 self.resolver.deinit(gpa);
467463
468 for (self.thunks.items) |*th| {464 for (self.thunks.items) |*th| {
...@@ -5389,17 +5385,8 @@ pub fn symbol(self: *Elf, sym_index: Symbol.Index) *Symbol {...@@ -5389,17 +5385,8 @@ pub fn symbol(self: *Elf, sym_index: Symbol.Index) *Symbol {
5389pub fn addSymbol(self: *Elf) !Symbol.Index {5385pub fn addSymbol(self: *Elf) !Symbol.Index {
5390 const gpa = self.base.comp.gpa;5386 const gpa = self.base.comp.gpa;
5391 try self.symbols.ensureUnusedCapacity(gpa, 1);5387 try self.symbols.ensureUnusedCapacity(gpa, 1);
5392 const index = blk: {5388 const index: Symbol.Index = @intCast(self.symbols.items.len);
5393 if (self.symbols_free_list.popOrNull()) |index| {5389 _ = self.symbols.addOneAssumeCapacity();
5394 log.debug(" (reusing symbol index {d})", .{index});
5395 break :blk index;
5396 } else {
5397 log.debug(" (allocating symbol index {d})", .{self.symbols.items.len});
5398 const index: Symbol.Index = @intCast(self.symbols.items.len);
5399 _ = self.symbols.addOneAssumeCapacity();
5400 break :blk index;
5401 }
5402 };
5403 self.symbols.items[index] = .{};5390 self.symbols.items[index] = .{};
5404 return index;5391 return index;
5405}5392}
...@@ -5423,8 +5410,7 @@ pub fn addSymbolExtraAssumeCapacity(self: *Elf, extra: Symbol.Extra) u32 {...@@ -5423,8 +5410,7 @@ pub fn addSymbolExtraAssumeCapacity(self: *Elf, extra: Symbol.Extra) u32 {
5423 return index;5410 return index;
5424}5411}
54255412
5426pub fn symbolExtra(self: *Elf, index: u32) ?Symbol.Extra {5413pub fn symbolExtra(self: *Elf, index: u32) Symbol.Extra {
5427 if (index == 0) return null;
5428 const fields = @typeInfo(Symbol.Extra).Struct.fields;5414 const fields = @typeInfo(Symbol.Extra).Struct.fields;
5429 var i: usize = index;5415 var i: usize = index;
5430 var result: Symbol.Extra = undefined;5416 var result: Symbol.Extra = undefined;
...@@ -5439,7 +5425,6 @@ pub fn symbolExtra(self: *Elf, index: u32) ?Symbol.Extra {...@@ -5439,7 +5425,6 @@ pub fn symbolExtra(self: *Elf, index: u32) ?Symbol.Extra {
5439}5425}
54405426
5441pub fn setSymbolExtra(self: *Elf, index: u32, extra: Symbol.Extra) void {5427pub fn setSymbolExtra(self: *Elf, index: u32, extra: Symbol.Extra) void {
5442 assert(index > 0);
5443 const fields = @typeInfo(Symbol.Extra).Struct.fields;5428 const fields = @typeInfo(Symbol.Extra).Struct.fields;
5444 inline for (fields, 0..) |field, i| {5429 inline for (fields, 0..) |field, i| {
5445 self.symbols_extra.items[index + i] = switch (field.type) {5430 self.symbols_extra.items[index + i] = switch (field.type) {
...@@ -5464,6 +5449,7 @@ pub fn getOrPutGlobal(self: *Elf, name: []const u8) !GetOrPutGlobalResult {...@@ -5464,6 +5449,7 @@ pub fn getOrPutGlobal(self: *Elf, name: []const u8) !GetOrPutGlobalResult {
5464 const global = self.symbol(index);5449 const global = self.symbol(index);
5465 global.name_offset = name_off;5450 global.name_offset = name_off;
5466 global.flags.global = true;5451 global.flags.global = true;
5452 global.extra_index = try self.addSymbolExtra(.{});
5467 gop.value_ptr.* = index;5453 gop.value_ptr.* = index;
5468 }5454 }
5469 return .{5455 return .{
src/link/Elf/Atom.zig+3-3
...@@ -845,7 +845,7 @@ fn resolveDynAbsReloc(...@@ -845,7 +845,7 @@ fn resolveDynAbsReloc(
845 if (is_writeable or elf_file.z_nocopyreloc) {845 if (is_writeable or elf_file.z_nocopyreloc) {
846 elf_file.addRelaDynAssumeCapacity(.{846 elf_file.addRelaDynAssumeCapacity(.{
847 .offset = P,847 .offset = P,
848 .sym = target.extra(elf_file).?.dynamic,848 .sym = target.extra(elf_file).dynamic,
849 .type = relocation.encode(.abs, cpu_arch),849 .type = relocation.encode(.abs, cpu_arch),
850 .addend = A,850 .addend = A,
851 });851 });
...@@ -859,7 +859,7 @@ fn resolveDynAbsReloc(...@@ -859,7 +859,7 @@ fn resolveDynAbsReloc(
859 if (is_writeable) {859 if (is_writeable) {
860 elf_file.addRelaDynAssumeCapacity(.{860 elf_file.addRelaDynAssumeCapacity(.{
861 .offset = P,861 .offset = P,
862 .sym = target.extra(elf_file).?.dynamic,862 .sym = target.extra(elf_file).dynamic,
863 .type = relocation.encode(.abs, cpu_arch),863 .type = relocation.encode(.abs, cpu_arch),
864 .addend = A,864 .addend = A,
865 });865 });
...@@ -872,7 +872,7 @@ fn resolveDynAbsReloc(...@@ -872,7 +872,7 @@ fn resolveDynAbsReloc(
872 .dynrel => {872 .dynrel => {
873 elf_file.addRelaDynAssumeCapacity(.{873 elf_file.addRelaDynAssumeCapacity(.{
874 .offset = P,874 .offset = P,
875 .sym = target.extra(elf_file).?.dynamic,875 .sym = target.extra(elf_file).dynamic,
876 .type = relocation.encode(.abs, cpu_arch),876 .type = relocation.encode(.abs, cpu_arch),
877 .addend = A,877 .addend = A,
878 });878 });
src/link/Elf/Object.zig+2
...@@ -387,6 +387,7 @@ fn initSymtab(self: *Object, allocator: Allocator, elf_file: *Elf) !void {...@@ -387,6 +387,7 @@ fn initSymtab(self: *Object, allocator: Allocator, elf_file: *Elf) !void {
387 sym_ptr.name_offset = sym.st_name;387 sym_ptr.name_offset = sym.st_name;
388 sym_ptr.esym_index = @as(u32, @intCast(i));388 sym_ptr.esym_index = @as(u32, @intCast(i));
389 sym_ptr.file_index = self.index;389 sym_ptr.file_index = self.index;
390 sym_ptr.extra_index = try elf_file.addSymbolExtra(.{});
390 if (sym.st_shndx != elf.SHN_ABS) {391 if (sym.st_shndx != elf.SHN_ABS) {
391 sym_ptr.ref = .{ .index = self.atoms_indexes.items[sym.st_shndx], .file = self.index };392 sym_ptr.ref = .{ .index = self.atoms_indexes.items[sym.st_shndx], .file = self.index };
392 }393 }
...@@ -865,6 +866,7 @@ pub fn resolveMergeSubsections(self: *Object, elf_file: *Elf) !void {...@@ -865,6 +866,7 @@ pub fn resolveMergeSubsections(self: *Object, elf_file: *Elf) !void {
865 .name_offset = try self.addString(gpa, name),866 .name_offset = try self.addString(gpa, name),
866 .esym_index = rel.r_sym(),867 .esym_index = rel.r_sym(),
867 .file_index = self.index,868 .file_index = self.index,
869 .extra_index = try elf_file.addSymbolExtra(.{}),
868 };870 };
869 sym.ref = .{ .index = res.msub_index, .file = imsec.merge_section_index };871 sym.ref = .{ .index = res.msub_index, .file = imsec.merge_section_index };
870 sym.flags.merge_subsection = true;872 sym.flags.merge_subsection = true;
src/link/Elf/Symbol.zig+12-15
...@@ -159,20 +159,20 @@ pub fn outputSymtabIndex(symbol: Symbol, elf_file: *Elf) ?u32 {...@@ -159,20 +159,20 @@ pub fn outputSymtabIndex(symbol: Symbol, elf_file: *Elf) ?u32 {
159 const symtab_ctx = switch (file_ptr) {159 const symtab_ctx = switch (file_ptr) {
160 inline else => |x| x.output_symtab_ctx,160 inline else => |x| x.output_symtab_ctx,
161 };161 };
162 const idx = symbol.extra(elf_file).?.symtab;162 const idx = symbol.extra(elf_file).symtab;
163 return if (symbol.isLocal(elf_file)) idx + symtab_ctx.ilocal else idx + symtab_ctx.iglobal;163 return if (symbol.isLocal(elf_file)) idx + symtab_ctx.ilocal else idx + symtab_ctx.iglobal;
164}164}
165165
166pub fn gotAddress(symbol: Symbol, elf_file: *Elf) i64 {166pub fn gotAddress(symbol: Symbol, elf_file: *Elf) i64 {
167 if (!symbol.flags.has_got) return 0;167 if (!symbol.flags.has_got) return 0;
168 const extras = symbol.extra(elf_file).?;168 const extras = symbol.extra(elf_file);
169 const entry = elf_file.got.entries.items[extras.got];169 const entry = elf_file.got.entries.items[extras.got];
170 return entry.address(elf_file);170 return entry.address(elf_file);
171}171}
172172
173pub fn pltGotAddress(symbol: Symbol, elf_file: *Elf) i64 {173pub fn pltGotAddress(symbol: Symbol, elf_file: *Elf) i64 {
174 if (!(symbol.flags.has_plt and symbol.flags.has_got)) return 0;174 if (!(symbol.flags.has_plt and symbol.flags.has_got)) return 0;
175 const extras = symbol.extra(elf_file).?;175 const extras = symbol.extra(elf_file);
176 const shdr = elf_file.shdrs.items[elf_file.plt_got_section_index.?];176 const shdr = elf_file.shdrs.items[elf_file.plt_got_section_index.?];
177 const cpu_arch = elf_file.getTarget().cpu.arch;177 const cpu_arch = elf_file.getTarget().cpu.arch;
178 return @intCast(shdr.sh_addr + extras.plt_got * PltGotSection.entrySize(cpu_arch));178 return @intCast(shdr.sh_addr + extras.plt_got * PltGotSection.entrySize(cpu_arch));
...@@ -180,7 +180,7 @@ pub fn pltGotAddress(symbol: Symbol, elf_file: *Elf) i64 {...@@ -180,7 +180,7 @@ pub fn pltGotAddress(symbol: Symbol, elf_file: *Elf) i64 {
180180
181pub fn pltAddress(symbol: Symbol, elf_file: *Elf) i64 {181pub fn pltAddress(symbol: Symbol, elf_file: *Elf) i64 {
182 if (!symbol.flags.has_plt) return 0;182 if (!symbol.flags.has_plt) return 0;
183 const extras = symbol.extra(elf_file).?;183 const extras = symbol.extra(elf_file);
184 const shdr = elf_file.shdrs.items[elf_file.plt_section_index.?];184 const shdr = elf_file.shdrs.items[elf_file.plt_section_index.?];
185 const cpu_arch = elf_file.getTarget().cpu.arch;185 const cpu_arch = elf_file.getTarget().cpu.arch;
186 return @intCast(shdr.sh_addr + extras.plt * PltSection.entrySize(cpu_arch) + PltSection.preambleSize(cpu_arch));186 return @intCast(shdr.sh_addr + extras.plt * PltSection.entrySize(cpu_arch) + PltSection.preambleSize(cpu_arch));
...@@ -188,7 +188,7 @@ pub fn pltAddress(symbol: Symbol, elf_file: *Elf) i64 {...@@ -188,7 +188,7 @@ pub fn pltAddress(symbol: Symbol, elf_file: *Elf) i64 {
188188
189pub fn gotPltAddress(symbol: Symbol, elf_file: *Elf) i64 {189pub fn gotPltAddress(symbol: Symbol, elf_file: *Elf) i64 {
190 if (!symbol.flags.has_plt) return 0;190 if (!symbol.flags.has_plt) return 0;
191 const extras = symbol.extra(elf_file).?;191 const extras = symbol.extra(elf_file);
192 const shdr = elf_file.shdrs.items[elf_file.got_plt_section_index.?];192 const shdr = elf_file.shdrs.items[elf_file.got_plt_section_index.?];
193 return @intCast(shdr.sh_addr + extras.plt * 8 + GotPltSection.preamble_size);193 return @intCast(shdr.sh_addr + extras.plt * 8 + GotPltSection.preamble_size);
194}194}
...@@ -201,21 +201,21 @@ pub fn copyRelAddress(symbol: Symbol, elf_file: *Elf) i64 {...@@ -201,21 +201,21 @@ pub fn copyRelAddress(symbol: Symbol, elf_file: *Elf) i64 {
201201
202pub fn tlsGdAddress(symbol: Symbol, elf_file: *Elf) i64 {202pub fn tlsGdAddress(symbol: Symbol, elf_file: *Elf) i64 {
203 if (!symbol.flags.has_tlsgd) return 0;203 if (!symbol.flags.has_tlsgd) return 0;
204 const extras = symbol.extra(elf_file).?;204 const extras = symbol.extra(elf_file);
205 const entry = elf_file.got.entries.items[extras.tlsgd];205 const entry = elf_file.got.entries.items[extras.tlsgd];
206 return entry.address(elf_file);206 return entry.address(elf_file);
207}207}
208208
209pub fn gotTpAddress(symbol: Symbol, elf_file: *Elf) i64 {209pub fn gotTpAddress(symbol: Symbol, elf_file: *Elf) i64 {
210 if (!symbol.flags.has_gottp) return 0;210 if (!symbol.flags.has_gottp) return 0;
211 const extras = symbol.extra(elf_file).?;211 const extras = symbol.extra(elf_file);
212 const entry = elf_file.got.entries.items[extras.gottp];212 const entry = elf_file.got.entries.items[extras.gottp];
213 return entry.address(elf_file);213 return entry.address(elf_file);
214}214}
215215
216pub fn tlsDescAddress(symbol: Symbol, elf_file: *Elf) i64 {216pub fn tlsDescAddress(symbol: Symbol, elf_file: *Elf) i64 {
217 if (!symbol.flags.has_tlsdesc) return 0;217 if (!symbol.flags.has_tlsdesc) return 0;
218 const extras = symbol.extra(elf_file).?;218 const extras = symbol.extra(elf_file);
219 const entry = elf_file.got.entries.items[extras.tlsdesc];219 const entry = elf_file.got.entries.items[extras.tlsdesc];
220 return entry.address(elf_file);220 return entry.address(elf_file);
221}221}
...@@ -228,14 +228,14 @@ const GetOrCreateZigGotEntryResult = struct {...@@ -228,14 +228,14 @@ const GetOrCreateZigGotEntryResult = struct {
228pub fn getOrCreateZigGotEntry(symbol: *Symbol, symbol_index: Index, elf_file: *Elf) !GetOrCreateZigGotEntryResult {228pub fn getOrCreateZigGotEntry(symbol: *Symbol, symbol_index: Index, elf_file: *Elf) !GetOrCreateZigGotEntryResult {
229 assert(!elf_file.base.isRelocatable());229 assert(!elf_file.base.isRelocatable());
230 assert(symbol.flags.needs_zig_got);230 assert(symbol.flags.needs_zig_got);
231 if (symbol.flags.has_zig_got) return .{ .found_existing = true, .index = symbol.extra(elf_file).?.zig_got };231 if (symbol.flags.has_zig_got) return .{ .found_existing = true, .index = symbol.extra(elf_file).zig_got };
232 const index = try elf_file.zig_got.addSymbol(symbol_index, elf_file);232 const index = try elf_file.zig_got.addSymbol(symbol_index, elf_file);
233 return .{ .found_existing = false, .index = index };233 return .{ .found_existing = false, .index = index };
234}234}
235235
236pub fn zigGotAddress(symbol: Symbol, elf_file: *Elf) i64 {236pub fn zigGotAddress(symbol: Symbol, elf_file: *Elf) i64 {
237 if (!symbol.flags.has_zig_got) return 0;237 if (!symbol.flags.has_zig_got) return 0;
238 const extras = symbol.extra(elf_file).?;238 const extras = symbol.extra(elf_file);
239 return elf_file.zig_got.entryAddress(extras.zig_got, elf_file);239 return elf_file.zig_got.entryAddress(extras.zig_got, elf_file);
240}240}
241241
...@@ -266,10 +266,7 @@ const AddExtraOpts = struct {...@@ -266,10 +266,7 @@ const AddExtraOpts = struct {
266};266};
267267
268pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) !void {268pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) !void {
269 if (symbol.extra(elf_file) == null) {269 var extras = symbol.extra(elf_file);
270 symbol.extra_index = try elf_file.addSymbolExtra(.{});
271 }
272 var extras = symbol.extra(elf_file).?;
273 inline for (@typeInfo(@TypeOf(opts)).Struct.fields) |field| {270 inline for (@typeInfo(@TypeOf(opts)).Struct.fields) |field| {
274 if (@field(opts, field.name)) |x| {271 if (@field(opts, field.name)) |x| {
275 @field(extras, field.name) = x;272 @field(extras, field.name) = x;
...@@ -278,7 +275,7 @@ pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) !void {...@@ -278,7 +275,7 @@ pub fn addExtra(symbol: *Symbol, opts: AddExtraOpts, elf_file: *Elf) !void {
278 symbol.setExtra(extras, elf_file);275 symbol.setExtra(extras, elf_file);
279}276}
280277
281pub fn extra(symbol: Symbol, elf_file: *Elf) ?Extra {278pub fn extra(symbol: Symbol, elf_file: *Elf) Extra {
282 return elf_file.symbolExtra(symbol.extra_index);279 return elf_file.symbolExtra(symbol.extra_index);
283}280}
284281
src/link/Elf/ZigObject.zig+3-3
...@@ -92,6 +92,7 @@ pub fn init(self: *ZigObject, elf_file: *Elf) !void {...@@ -92,6 +92,7 @@ pub fn init(self: *ZigObject, elf_file: *Elf) !void {
92 const symbol_ptr = elf_file.symbol(symbol_index);92 const symbol_ptr = elf_file.symbol(symbol_index);
93 symbol_ptr.file_index = self.index;93 symbol_ptr.file_index = self.index;
94 symbol_ptr.name_offset = name_off;94 symbol_ptr.name_offset = name_off;
95 symbol_ptr.extra_index = try elf_file.addSymbolExtra(.{});
9596
96 const esym_index = try self.addLocalEsym(gpa);97 const esym_index = try self.addLocalEsym(gpa);
97 const esym = &self.local_esyms.items(.elf_sym)[esym_index];98 const esym = &self.local_esyms.items(.elf_sym)[esym_index];
...@@ -292,6 +293,7 @@ pub fn newAtom(self: *ZigObject, elf_file: *Elf) !Symbol.Index {...@@ -292,6 +293,7 @@ pub fn newAtom(self: *ZigObject, elf_file: *Elf) !Symbol.Index {
292 const symbol_ptr = elf_file.symbol(symbol_index);293 const symbol_ptr = elf_file.symbol(symbol_index);
293 symbol_ptr.file_index = self.index;294 symbol_ptr.file_index = self.index;
294 symbol_ptr.ref = .{ .index = atom_index, .file = self.index };295 symbol_ptr.ref = .{ .index = atom_index, .file = self.index };
296 symbol_ptr.extra_index = try elf_file.addSymbolExtra(.{});
295297
296 self.local_esyms.items(.shndx)[esym_index] = atom_index;298 self.local_esyms.items(.shndx)[esym_index] = atom_index;
297 self.local_esyms.items(.elf_sym)[esym_index].st_shndx = SHN_ATOM;299 self.local_esyms.items(.elf_sym)[esym_index].st_shndx = SHN_ATOM;
...@@ -779,11 +781,9 @@ fn freeUnnamedConsts(self: *ZigObject, elf_file: *Elf, decl_index: InternPool.De...@@ -779,11 +781,9 @@ fn freeUnnamedConsts(self: *ZigObject, elf_file: *Elf, decl_index: InternPool.De
779781
780fn freeDeclMetadata(self: *ZigObject, elf_file: *Elf, sym_index: Symbol.Index) void {782fn freeDeclMetadata(self: *ZigObject, elf_file: *Elf, sym_index: Symbol.Index) void {
781 _ = self;783 _ = self;
782 const gpa = elf_file.base.comp.gpa;
783 const sym = elf_file.symbol(sym_index);784 const sym = elf_file.symbol(sym_index);
784 sym.atom(elf_file).?.free(elf_file);785 sym.atom(elf_file).?.free(elf_file);
785 log.debug("adding %{d} to local symbols free list", .{sym_index});786 log.debug("adding %{d} to local symbols free list", .{sym_index});
786 elf_file.symbols_free_list.append(gpa, sym_index) catch {};
787 elf_file.symbols.items[sym_index] = .{};787 elf_file.symbols.items[sym_index] = .{};
788 // TODO free GOT entry here788 // TODO free GOT entry here
789}789}
...@@ -940,7 +940,7 @@ fn updateDeclCode(...@@ -940,7 +940,7 @@ fn updateDeclCode(
940 if (!elf_file.base.isRelocatable()) {940 if (!elf_file.base.isRelocatable()) {
941 log.debug(" (writing new offset table entry)", .{});941 log.debug(" (writing new offset table entry)", .{});
942 assert(sym.flags.has_zig_got);942 assert(sym.flags.has_zig_got);
943 const extra = sym.extra(elf_file).?;943 const extra = sym.extra(elf_file);
944 try elf_file.zig_got.writeOne(elf_file, extra.zig_got);944 try elf_file.zig_got.writeOne(elf_file, extra.zig_got);
945 }945 }
946 }946 }
src/link/Elf/file.zig+2
...@@ -71,9 +71,11 @@ pub const File = union(enum) {...@@ -71,9 +71,11 @@ pub const File = union(enum) {
71 for (file.globals()) |global_index| {71 for (file.globals()) |global_index| {
72 const global = elf_file.symbol(global_index);72 const global = elf_file.symbol(global_index);
73 const name_offset = global.name_offset;73 const name_offset = global.name_offset;
74 const extra_index = global.extra_index;
74 global.* = .{};75 global.* = .{};
75 global.name_offset = name_offset;76 global.name_offset = name_offset;
76 global.flags.global = true;77 global.flags.global = true;
78 global.extra_index = extra_index;
77 }79 }
78 }80 }
7981
src/link/Elf/synthetic_sections.zig+5-5
...@@ -641,7 +641,7 @@ pub const GotSection = struct {...@@ -641,7 +641,7 @@ pub const GotSection = struct {
641 .tlsld => null,641 .tlsld => null,
642 inline else => elf_file.symbol(entry.symbol_index),642 inline else => elf_file.symbol(entry.symbol_index),
643 };643 };
644 const extra = if (symbol) |s| s.extra(elf_file).? else null;644 const extra = if (symbol) |s| s.extra(elf_file) else null;
645645
646 switch (entry.tag) {646 switch (entry.tag) {
647 .got => {647 .got => {
...@@ -898,7 +898,7 @@ pub const PltSection = struct {...@@ -898,7 +898,7 @@ pub const PltSection = struct {
898 for (plt.symbols.items) |sym_index| {898 for (plt.symbols.items) |sym_index| {
899 const sym = elf_file.symbol(sym_index);899 const sym = elf_file.symbol(sym_index);
900 assert(sym.flags.import);900 assert(sym.flags.import);
901 const extra = sym.extra(elf_file).?;901 const extra = sym.extra(elf_file);
902 const r_offset: u64 = @intCast(sym.gotPltAddress(elf_file));902 const r_offset: u64 = @intCast(sym.gotPltAddress(elf_file));
903 const r_sym: u64 = extra.dynamic;903 const r_sym: u64 = extra.dynamic;
904 const r_type = relocation.encode(.jump_slot, cpu_arch);904 const r_type = relocation.encode(.jump_slot, cpu_arch);
...@@ -1267,7 +1267,7 @@ pub const CopyRelSection = struct {...@@ -1267,7 +1267,7 @@ pub const CopyRelSection = struct {
1267 for (copy_rel.symbols.items) |sym_index| {1267 for (copy_rel.symbols.items) |sym_index| {
1268 const sym = elf_file.symbol(sym_index);1268 const sym = elf_file.symbol(sym_index);
1269 assert(sym.flags.import and sym.flags.has_copy_rel);1269 assert(sym.flags.import and sym.flags.has_copy_rel);
1270 const extra = sym.extra(elf_file).?;1270 const extra = sym.extra(elf_file);
1271 elf_file.addRelaDynAssumeCapacity(.{1271 elf_file.addRelaDynAssumeCapacity(.{
1272 .offset = @intCast(sym.address(.{}, elf_file)),1272 .offset = @intCast(sym.address(.{}, elf_file)),
1273 .sym = extra.dynamic,1273 .sym = extra.dynamic,
...@@ -1322,7 +1322,7 @@ pub const DynsymSection = struct {...@@ -1322,7 +1322,7 @@ pub const DynsymSection = struct {
1322 const rhs_hash = GnuHashSection.hasher(rhs_sym.name(ctx)) % nbuckets;1322 const rhs_hash = GnuHashSection.hasher(rhs_sym.name(ctx)) % nbuckets;
13231323
1324 if (lhs_hash == rhs_hash)1324 if (lhs_hash == rhs_hash)
1325 return lhs_sym.extra(ctx).?.dynamic < rhs_sym.extra(ctx).?.dynamic;1325 return lhs_sym.extra(ctx).dynamic < rhs_sym.extra(ctx).dynamic;
1326 return lhs_hash < rhs_hash;1326 return lhs_hash < rhs_hash;
1327 }1327 }
1328 };1328 };
...@@ -1339,7 +1339,7 @@ pub const DynsymSection = struct {...@@ -1339,7 +1339,7 @@ pub const DynsymSection = struct {
13391339
1340 for (dynsym.entries.items, 1..) |entry, index| {1340 for (dynsym.entries.items, 1..) |entry, index| {
1341 const sym = elf_file.symbol(entry.symbol_index);1341 const sym = elf_file.symbol(entry.symbol_index);
1342 var extra = sym.extra(elf_file).?;1342 var extra = sym.extra(elf_file);
1343 extra.dynamic = @as(u32, @intCast(index));1343 extra.dynamic = @as(u32, @intCast(index));
1344 sym.setExtra(extra, elf_file);1344 sym.setExtra(extra, elf_file);
1345 }1345 }