| author | |
| committer | |
| log | 359842f8d5a0ee2641c07c1e659d06553d6269fc |
| tree | 5041d6b759152e2021cd4bedeaa1af4a123d4dfa |
| parent | 0c6cb8d8c80f0a316a77eddfebaa42cb77c8bf7d |
| parent | 6e4d7362cedd9570bb32868d868877d6ba39c156 |
| signature |
elf: actually write synthetic globals to output symtab and other misc fixes7 files changed, 222 insertions(+), 103 deletions(-)
src/link/Elf.zig+40-43| ... | ... | @@ -1208,14 +1208,15 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1208 | 1208 | } |
| 1209 | 1209 | } |
| 1210 | 1210 | |
| 1211 | try self.initOutputSections(); | |
| 1211 | 1212 | try self.addLinkerDefinedSymbols(); |
| 1212 | 1213 | self.claimUnresolved(); |
| 1213 | 1214 | |
| 1214 | 1215 | // Scan and create missing synthetic entries such as GOT indirection. |
| 1215 | 1216 | try self.scanRelocs(); |
| 1216 | 1217 | |
| 1217 | // Generate and emit non-incremental sections. | |
| 1218 | try self.initSections(); | |
| 1218 | // Generate and emit synthetic sections. | |
| 1219 | try self.initSyntheticSections(); | |
| 1219 | 1220 | try self.initSpecialPhdrs(); |
| 1220 | 1221 | try self.sortShdrs(); |
| 1221 | 1222 | for (self.objects.items) |index| { |
| ... | ... | @@ -3210,21 +3211,18 @@ fn addLinkerDefinedSymbols(self: *Elf) !void { |
| 3210 | 3211 | self.rela_iplt_start_index = try linker_defined.addGlobal("__rela_iplt_start", self); |
| 3211 | 3212 | self.rela_iplt_end_index = try linker_defined.addGlobal("__rela_iplt_end", self); |
| 3212 | 3213 | |
| 3213 | for (self.objects.items) |index| { | |
| 3214 | const object = self.file(index).?.object; | |
| 3215 | for (object.atoms.items) |atom_index| { | |
| 3216 | if (self.getStartStopBasename(atom_index)) |name| { | |
| 3217 | const gpa = self.base.allocator; | |
| 3218 | try self.start_stop_indexes.ensureUnusedCapacity(gpa, 2); | |
| 3219 | ||
| 3220 | const start = try std.fmt.allocPrintZ(gpa, "__start_{s}", .{name}); | |
| 3221 | defer gpa.free(start); | |
| 3222 | const stop = try std.fmt.allocPrintZ(gpa, "__stop_{s}", .{name}); | |
| 3223 | defer gpa.free(stop); | |
| 3224 | ||
| 3225 | self.start_stop_indexes.appendAssumeCapacity(try linker_defined.addGlobal(start, self)); | |
| 3226 | self.start_stop_indexes.appendAssumeCapacity(try linker_defined.addGlobal(stop, self)); | |
| 3227 | } | |
| 3214 | for (self.shdrs.items) |shdr| { | |
| 3215 | if (self.getStartStopBasename(shdr)) |name| { | |
| 3216 | const gpa = self.base.allocator; | |
| 3217 | try self.start_stop_indexes.ensureUnusedCapacity(gpa, 2); | |
| 3218 | ||
| 3219 | const start = try std.fmt.allocPrintZ(gpa, "__start_{s}", .{name}); | |
| 3220 | defer gpa.free(start); | |
| 3221 | const stop = try std.fmt.allocPrintZ(gpa, "__stop_{s}", .{name}); | |
| 3222 | defer gpa.free(stop); | |
| 3223 | ||
| 3224 | self.start_stop_indexes.appendAssumeCapacity(try linker_defined.addGlobal(start, self)); | |
| 3225 | self.start_stop_indexes.appendAssumeCapacity(try linker_defined.addGlobal(stop, self)); | |
| 3228 | 3226 | } |
| 3229 | 3227 | } |
| 3230 | 3228 | |
| ... | ... | @@ -3354,12 +3352,14 @@ fn allocateLinkerDefinedSymbols(self: *Elf) void { |
| 3354 | 3352 | } |
| 3355 | 3353 | } |
| 3356 | 3354 | |
| 3357 | fn initSections(self: *Elf) !void { | |
| 3358 | const ptr_size = self.ptrWidthBytes(); | |
| 3359 | ||
| 3355 | fn initOutputSections(self: *Elf) !void { | |
| 3360 | 3356 | for (self.objects.items) |index| { |
| 3361 | 3357 | try self.file(index).?.object.initOutputSections(self); |
| 3362 | 3358 | } |
| 3359 | } | |
| 3360 | ||
| 3361 | fn initSyntheticSections(self: *Elf) !void { | |
| 3362 | const ptr_size = self.ptrWidthBytes(); | |
| 3363 | 3363 | |
| 3364 | 3364 | const needs_eh_frame = for (self.objects.items) |index| { |
| 3365 | 3365 | if (self.file(index).?.object.cies.items.len > 0) break true; |
| ... | ... | @@ -3394,6 +3394,14 @@ fn initSections(self: *Elf) !void { |
| 3394 | 3394 | }); |
| 3395 | 3395 | } |
| 3396 | 3396 | |
| 3397 | self.got_plt_section_index = try self.addSection(.{ | |
| 3398 | .name = ".got.plt", | |
| 3399 | .type = elf.SHT_PROGBITS, | |
| 3400 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | |
| 3401 | .addralign = @alignOf(u64), | |
| 3402 | .offset = std.math.maxInt(u64), | |
| 3403 | }); | |
| 3404 | ||
| 3397 | 3405 | const needs_rela_dyn = blk: { |
| 3398 | 3406 | if (self.got.flags.needs_rela or self.got.flags.needs_tlsld or |
| 3399 | 3407 | self.zig_got.flags.needs_rela or self.copy_rel.symbols.items.len > 0) break :blk true; |
| ... | ... | @@ -3424,13 +3432,6 @@ fn initSections(self: *Elf) !void { |
| 3424 | 3432 | .addralign = 16, |
| 3425 | 3433 | .offset = std.math.maxInt(u64), |
| 3426 | 3434 | }); |
| 3427 | self.got_plt_section_index = try self.addSection(.{ | |
| 3428 | .name = ".got.plt", | |
| 3429 | .type = elf.SHT_PROGBITS, | |
| 3430 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | |
| 3431 | .addralign = @alignOf(u64), | |
| 3432 | .offset = std.math.maxInt(u64), | |
| 3433 | }); | |
| 3434 | 3435 | self.rela_plt_section_index = try self.addSection(.{ |
| 3435 | 3436 | .name = ".rela.plt", |
| 3436 | 3437 | .type = elf.SHT_RELA, |
| ... | ... | @@ -4819,15 +4820,12 @@ fn updateSymtabSize(self: *Elf) !void { |
| 4819 | 4820 | const gpa = self.base.allocator; |
| 4820 | 4821 | var files = std.ArrayList(File.Index).init(gpa); |
| 4821 | 4822 | defer files.deinit(); |
| 4822 | try files.ensureTotalCapacityPrecise(self.objects.items.len + self.shared_objects.items.len + 1); | |
| 4823 | try files.ensureTotalCapacityPrecise(self.objects.items.len + self.shared_objects.items.len + 2); | |
| 4823 | 4824 | |
| 4824 | 4825 | if (self.zig_object_index) |index| files.appendAssumeCapacity(index); |
| 4825 | for (self.objects.items) |index| { | |
| 4826 | files.appendAssumeCapacity(index); | |
| 4827 | } | |
| 4828 | for (self.shared_objects.items) |index| { | |
| 4829 | files.appendAssumeCapacity(index); | |
| 4830 | } | |
| 4826 | for (self.objects.items) |index| files.appendAssumeCapacity(index); | |
| 4827 | for (self.shared_objects.items) |index| files.appendAssumeCapacity(index); | |
| 4828 | if (self.linker_defined_index) |index| files.appendAssumeCapacity(index); | |
| 4831 | 4829 | |
| 4832 | 4830 | // Section symbols |
| 4833 | 4831 | for (self.output_sections.keys()) |_| { |
| ... | ... | @@ -5166,6 +5164,11 @@ fn writeSymtab(self: *Elf) !void { |
| 5166 | 5164 | file_ptr.writeSymtab(self); |
| 5167 | 5165 | } |
| 5168 | 5166 | |
| 5167 | if (self.linker_defined_index) |index| { | |
| 5168 | const file_ptr = self.file(index).?; | |
| 5169 | file_ptr.writeSymtab(self); | |
| 5170 | } | |
| 5171 | ||
| 5169 | 5172 | if (self.zig_got_section_index) |_| { |
| 5170 | 5173 | self.zig_got.writeSymtab(self); |
| 5171 | 5174 | } |
| ... | ... | @@ -5182,11 +5185,6 @@ fn writeSymtab(self: *Elf) !void { |
| 5182 | 5185 | self.plt_got.writeSymtab(self); |
| 5183 | 5186 | } |
| 5184 | 5187 | |
| 5185 | if (self.linker_defined_index) |index| { | |
| 5186 | const file_ptr = self.file(index).?; | |
| 5187 | file_ptr.writeSymtab(self); | |
| 5188 | } | |
| 5189 | ||
| 5190 | 5188 | const foreign_endian = self.base.options.target.cpu.arch.endian() != builtin.cpu.arch.endian(); |
| 5191 | 5189 | switch (self.ptr_width) { |
| 5192 | 5190 | .p32 => { |
| ... | ... | @@ -5750,10 +5748,9 @@ pub fn isCIdentifier(name: []const u8) bool { |
| 5750 | 5748 | return true; |
| 5751 | 5749 | } |
| 5752 | 5750 | |
| 5753 | fn getStartStopBasename(self: *Elf, atom_index: Atom.Index) ?[]const u8 { | |
| 5754 | const atom_ptr = self.atom(atom_index) orelse return null; | |
| 5755 | const name = atom_ptr.name(self); | |
| 5756 | if (atom_ptr.inputShdr(self).sh_flags & elf.SHF_ALLOC != 0 and name.len > 0) { | |
| 5751 | fn getStartStopBasename(self: *Elf, shdr: elf.Elf64_Shdr) ?[]const u8 { | |
| 5752 | const name = self.getShString(shdr.sh_name); | |
| 5753 | if (shdr.sh_flags & elf.SHF_ALLOC != 0 and name.len > 0) { | |
| 5757 | 5754 | if (isCIdentifier(name)) return name; |
| 5758 | 5755 | } |
| 5759 | 5756 | return null; |
src/link/Elf/LinkerDefined.zig+33-1| ... | ... | @@ -48,10 +48,42 @@ pub fn resolveSymbols(self: *LinkerDefined, elf_file: *Elf) void { |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | pub fn globals(self: *LinkerDefined) []const Symbol.Index { | |
| 51 | pub fn globals(self: LinkerDefined) []const Symbol.Index { | |
| 52 | 52 | return self.symbols.items; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | pub fn updateSymtabSize(self: *LinkerDefined, elf_file: *Elf) !void { | |
| 56 | for (self.globals()) |global_index| { | |
| 57 | const global = elf_file.symbol(global_index); | |
| 58 | const file_ptr = global.file(elf_file) orelse continue; | |
| 59 | if (file_ptr.index() != self.index) continue; | |
| 60 | global.flags.output_symtab = true; | |
| 61 | if (global.isLocal(elf_file)) { | |
| 62 | try global.setOutputSymtabIndex(self.output_symtab_ctx.nlocals, elf_file); | |
| 63 | self.output_symtab_ctx.nlocals += 1; | |
| 64 | } else { | |
| 65 | try global.setOutputSymtabIndex(self.output_symtab_ctx.nglobals, elf_file); | |
| 66 | self.output_symtab_ctx.nglobals += 1; | |
| 67 | } | |
| 68 | self.output_symtab_ctx.strsize += @as(u32, @intCast(global.name(elf_file).len)) + 1; | |
| 69 | } | |
| 70 | } | |
| 71 | ||
| 72 | pub fn writeSymtab(self: LinkerDefined, elf_file: *Elf) void { | |
| 73 | for (self.globals()) |global_index| { | |
| 74 | const global = elf_file.symbol(global_index); | |
| 75 | const file_ptr = global.file(elf_file) orelse continue; | |
| 76 | if (file_ptr.index() != self.index) continue; | |
| 77 | const idx = global.outputSymtabIndex(elf_file) orelse continue; | |
| 78 | const st_name = @as(u32, @intCast(elf_file.strtab.items.len)); | |
| 79 | elf_file.strtab.appendSliceAssumeCapacity(global.name(elf_file)); | |
| 80 | elf_file.strtab.appendAssumeCapacity(0); | |
| 81 | const out_sym = &elf_file.symtab.items[idx]; | |
| 82 | out_sym.st_name = st_name; | |
| 83 | global.setOutputSym(elf_file, out_sym); | |
| 84 | } | |
| 85 | } | |
| 86 | ||
| 55 | 87 | pub fn asFile(self: *LinkerDefined) File { |
| 56 | 88 | return .{ .linker_defined = self }; |
| 57 | 89 | } |
src/link/Elf/Object.zig+57| ... | ... | @@ -741,6 +741,63 @@ pub fn writeAr(self: Object, writer: anytype) !void { |
| 741 | 741 | try writer.writeAll(self.data); |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | pub fn updateSymtabSize(self: *Object, elf_file: *Elf) !void { | |
| 745 | for (self.locals()) |local_index| { | |
| 746 | const local = elf_file.symbol(local_index); | |
| 747 | if (local.atom(elf_file)) |atom| if (!atom.flags.alive) continue; | |
| 748 | const esym = local.elfSym(elf_file); | |
| 749 | switch (esym.st_type()) { | |
| 750 | elf.STT_SECTION, elf.STT_NOTYPE => continue, | |
| 751 | else => {}, | |
| 752 | } | |
| 753 | local.flags.output_symtab = true; | |
| 754 | try local.setOutputSymtabIndex(self.output_symtab_ctx.nlocals, elf_file); | |
| 755 | self.output_symtab_ctx.nlocals += 1; | |
| 756 | self.output_symtab_ctx.strsize += @as(u32, @intCast(local.name(elf_file).len)) + 1; | |
| 757 | } | |
| 758 | ||
| 759 | for (self.globals()) |global_index| { | |
| 760 | const global = elf_file.symbol(global_index); | |
| 761 | const file_ptr = global.file(elf_file) orelse continue; | |
| 762 | if (file_ptr.index() != self.index) continue; | |
| 763 | if (global.atom(elf_file)) |atom| if (!atom.flags.alive) continue; | |
| 764 | global.flags.output_symtab = true; | |
| 765 | if (global.isLocal(elf_file)) { | |
| 766 | try global.setOutputSymtabIndex(self.output_symtab_ctx.nlocals, elf_file); | |
| 767 | self.output_symtab_ctx.nlocals += 1; | |
| 768 | } else { | |
| 769 | try global.setOutputSymtabIndex(self.output_symtab_ctx.nglobals, elf_file); | |
| 770 | self.output_symtab_ctx.nglobals += 1; | |
| 771 | } | |
| 772 | self.output_symtab_ctx.strsize += @as(u32, @intCast(global.name(elf_file).len)) + 1; | |
| 773 | } | |
| 774 | } | |
| 775 | ||
| 776 | pub fn writeSymtab(self: Object, elf_file: *Elf) void { | |
| 777 | for (self.locals()) |local_index| { | |
| 778 | const local = elf_file.symbol(local_index); | |
| 779 | const idx = local.outputSymtabIndex(elf_file) orelse continue; | |
| 780 | const out_sym = &elf_file.symtab.items[idx]; | |
| 781 | out_sym.st_name = @intCast(elf_file.strtab.items.len); | |
| 782 | elf_file.strtab.appendSliceAssumeCapacity(local.name(elf_file)); | |
| 783 | elf_file.strtab.appendAssumeCapacity(0); | |
| 784 | local.setOutputSym(elf_file, out_sym); | |
| 785 | } | |
| 786 | ||
| 787 | for (self.globals()) |global_index| { | |
| 788 | const global = elf_file.symbol(global_index); | |
| 789 | const file_ptr = global.file(elf_file) orelse continue; | |
| 790 | if (file_ptr.index() != self.index) continue; | |
| 791 | const idx = global.outputSymtabIndex(elf_file) orelse continue; | |
| 792 | const st_name = @as(u32, @intCast(elf_file.strtab.items.len)); | |
| 793 | elf_file.strtab.appendSliceAssumeCapacity(global.name(elf_file)); | |
| 794 | elf_file.strtab.appendAssumeCapacity(0); | |
| 795 | const out_sym = &elf_file.symtab.items[idx]; | |
| 796 | out_sym.st_name = st_name; | |
| 797 | global.setOutputSym(elf_file, out_sym); | |
| 798 | } | |
| 799 | } | |
| 800 | ||
| 744 | 801 | pub fn locals(self: Object) []const Symbol.Index { |
| 745 | 802 | if (self.symbols.items.len == 0) return &[0]Symbol.Index{}; |
| 746 | 803 | const end = self.first_global orelse self.symbols.items.len; |
src/link/Elf/SharedObject.zig+28| ... | ... | @@ -191,6 +191,34 @@ pub fn globals(self: SharedObject) []const Symbol.Index { |
| 191 | 191 | return self.symbols.items; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | pub fn updateSymtabSize(self: *SharedObject, elf_file: *Elf) !void { | |
| 195 | for (self.globals()) |global_index| { | |
| 196 | const global = elf_file.symbol(global_index); | |
| 197 | const file_ptr = global.file(elf_file) orelse continue; | |
| 198 | if (file_ptr.index() != self.index) continue; | |
| 199 | if (global.isLocal(elf_file)) continue; | |
| 200 | global.flags.output_symtab = true; | |
| 201 | try global.setOutputSymtabIndex(self.output_symtab_ctx.nglobals, elf_file); | |
| 202 | self.output_symtab_ctx.nglobals += 1; | |
| 203 | self.output_symtab_ctx.strsize += @as(u32, @intCast(global.name(elf_file).len)) + 1; | |
| 204 | } | |
| 205 | } | |
| 206 | ||
| 207 | pub fn writeSymtab(self: SharedObject, elf_file: *Elf) void { | |
| 208 | for (self.globals()) |global_index| { | |
| 209 | const global = elf_file.symbol(global_index); | |
| 210 | const file_ptr = global.file(elf_file) orelse continue; | |
| 211 | if (file_ptr.index() != self.index) continue; | |
| 212 | const idx = global.outputSymtabIndex(elf_file) orelse continue; | |
| 213 | const st_name = @as(u32, @intCast(elf_file.strtab.items.len)); | |
| 214 | elf_file.strtab.appendSliceAssumeCapacity(global.name(elf_file)); | |
| 215 | elf_file.strtab.appendAssumeCapacity(0); | |
| 216 | const out_sym = &elf_file.symtab.items[idx]; | |
| 217 | out_sym.st_name = st_name; | |
| 218 | global.setOutputSym(elf_file, out_sym); | |
| 219 | } | |
| 220 | } | |
| 221 | ||
| 194 | 222 | pub fn shdrContents(self: SharedObject, index: u16) []const u8 { |
| 195 | 223 | const shdr = self.shdrs.items[index]; |
| 196 | 224 | return self.data[shdr.sh_offset..][0..shdr.sh_size]; |
src/link/Elf/ZigObject.zig+57| ... | ... | @@ -528,6 +528,63 @@ pub fn globals(self: ZigObject) []const Symbol.Index { |
| 528 | 528 | return self.global_symbols.items; |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | pub fn updateSymtabSize(self: *ZigObject, elf_file: *Elf) !void { | |
| 532 | for (self.locals()) |local_index| { | |
| 533 | const local = elf_file.symbol(local_index); | |
| 534 | if (local.atom(elf_file)) |atom| if (!atom.flags.alive) continue; | |
| 535 | const esym = local.elfSym(elf_file); | |
| 536 | switch (esym.st_type()) { | |
| 537 | elf.STT_SECTION, elf.STT_NOTYPE => continue, | |
| 538 | else => {}, | |
| 539 | } | |
| 540 | local.flags.output_symtab = true; | |
| 541 | try local.setOutputSymtabIndex(self.output_symtab_ctx.nlocals, elf_file); | |
| 542 | self.output_symtab_ctx.nlocals += 1; | |
| 543 | self.output_symtab_ctx.strsize += @as(u32, @intCast(local.name(elf_file).len)) + 1; | |
| 544 | } | |
| 545 | ||
| 546 | for (self.globals()) |global_index| { | |
| 547 | const global = elf_file.symbol(global_index); | |
| 548 | const file_ptr = global.file(elf_file) orelse continue; | |
| 549 | if (file_ptr.index() != self.index) continue; | |
| 550 | if (global.atom(elf_file)) |atom| if (!atom.flags.alive) continue; | |
| 551 | global.flags.output_symtab = true; | |
| 552 | if (global.isLocal(elf_file)) { | |
| 553 | try global.setOutputSymtabIndex(self.output_symtab_ctx.nlocals, elf_file); | |
| 554 | self.output_symtab_ctx.nlocals += 1; | |
| 555 | } else { | |
| 556 | try global.setOutputSymtabIndex(self.output_symtab_ctx.nglobals, elf_file); | |
| 557 | self.output_symtab_ctx.nglobals += 1; | |
| 558 | } | |
| 559 | self.output_symtab_ctx.strsize += @as(u32, @intCast(global.name(elf_file).len)) + 1; | |
| 560 | } | |
| 561 | } | |
| 562 | ||
| 563 | pub fn writeSymtab(self: ZigObject, elf_file: *Elf) void { | |
| 564 | for (self.locals()) |local_index| { | |
| 565 | const local = elf_file.symbol(local_index); | |
| 566 | const idx = local.outputSymtabIndex(elf_file) orelse continue; | |
| 567 | const out_sym = &elf_file.symtab.items[idx]; | |
| 568 | out_sym.st_name = @intCast(elf_file.strtab.items.len); | |
| 569 | elf_file.strtab.appendSliceAssumeCapacity(local.name(elf_file)); | |
| 570 | elf_file.strtab.appendAssumeCapacity(0); | |
| 571 | local.setOutputSym(elf_file, out_sym); | |
| 572 | } | |
| 573 | ||
| 574 | for (self.globals()) |global_index| { | |
| 575 | const global = elf_file.symbol(global_index); | |
| 576 | const file_ptr = global.file(elf_file) orelse continue; | |
| 577 | if (file_ptr.index() != self.index) continue; | |
| 578 | const idx = global.outputSymtabIndex(elf_file) orelse continue; | |
| 579 | const st_name = @as(u32, @intCast(elf_file.strtab.items.len)); | |
| 580 | elf_file.strtab.appendSliceAssumeCapacity(global.name(elf_file)); | |
| 581 | elf_file.strtab.appendAssumeCapacity(0); | |
| 582 | const out_sym = &elf_file.symtab.items[idx]; | |
| 583 | out_sym.st_name = st_name; | |
| 584 | global.setOutputSym(elf_file, out_sym); | |
| 585 | } | |
| 586 | } | |
| 587 | ||
| 531 | 588 | pub fn asFile(self: *ZigObject) File { |
| 532 | 589 | return .{ .zig_object = self }; |
| 533 | 590 | } |
src/link/Elf/file.zig+5-53| ... | ... | @@ -128,63 +128,15 @@ pub const File = union(enum) { |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | pub fn updateSymtabSize(file: File, elf_file: *Elf) !void { |
| 131 | const output_symtab_ctx = switch (file) { | |
| 132 | inline else => |x| &x.output_symtab_ctx, | |
| 131 | return switch (file) { | |
| 132 | inline else => |x| x.updateSymtabSize(elf_file), | |
| 133 | 133 | }; |
| 134 | for (file.locals()) |local_index| { | |
| 135 | const local = elf_file.symbol(local_index); | |
| 136 | if (local.atom(elf_file)) |atom| if (!atom.flags.alive) continue; | |
| 137 | const esym = local.elfSym(elf_file); | |
| 138 | switch (esym.st_type()) { | |
| 139 | elf.STT_SECTION, elf.STT_NOTYPE => continue, | |
| 140 | else => {}, | |
| 141 | } | |
| 142 | local.flags.output_symtab = true; | |
| 143 | try local.setOutputSymtabIndex(output_symtab_ctx.nlocals, elf_file); | |
| 144 | output_symtab_ctx.nlocals += 1; | |
| 145 | output_symtab_ctx.strsize += @as(u32, @intCast(local.name(elf_file).len)) + 1; | |
| 146 | } | |
| 147 | ||
| 148 | for (file.globals()) |global_index| { | |
| 149 | const global = elf_file.symbol(global_index); | |
| 150 | const file_ptr = global.file(elf_file) orelse continue; | |
| 151 | if (file_ptr.index() != file.index()) continue; | |
| 152 | if (global.atom(elf_file)) |atom| if (!atom.flags.alive) continue; | |
| 153 | global.flags.output_symtab = true; | |
| 154 | if (global.isLocal(elf_file)) { | |
| 155 | try global.setOutputSymtabIndex(output_symtab_ctx.nlocals, elf_file); | |
| 156 | output_symtab_ctx.nlocals += 1; | |
| 157 | } else { | |
| 158 | try global.setOutputSymtabIndex(output_symtab_ctx.nglobals, elf_file); | |
| 159 | output_symtab_ctx.nglobals += 1; | |
| 160 | } | |
| 161 | output_symtab_ctx.strsize += @as(u32, @intCast(global.name(elf_file).len)) + 1; | |
| 162 | } | |
| 163 | 134 | } |
| 164 | 135 | |
| 165 | 136 | pub fn writeSymtab(file: File, elf_file: *Elf) void { |
| 166 | for (file.locals()) |local_index| { | |
| 167 | const local = elf_file.symbol(local_index); | |
| 168 | const idx = local.outputSymtabIndex(elf_file) orelse continue; | |
| 169 | const out_sym = &elf_file.symtab.items[idx]; | |
| 170 | out_sym.st_name = @intCast(elf_file.strtab.items.len); | |
| 171 | elf_file.strtab.appendSliceAssumeCapacity(local.name(elf_file)); | |
| 172 | elf_file.strtab.appendAssumeCapacity(0); | |
| 173 | local.setOutputSym(elf_file, out_sym); | |
| 174 | } | |
| 175 | ||
| 176 | for (file.globals()) |global_index| { | |
| 177 | const global = elf_file.symbol(global_index); | |
| 178 | const file_ptr = global.file(elf_file) orelse continue; | |
| 179 | if (file_ptr.index() != file.index()) continue; | |
| 180 | const idx = global.outputSymtabIndex(elf_file) orelse continue; | |
| 181 | const st_name = @as(u32, @intCast(elf_file.strtab.items.len)); | |
| 182 | elf_file.strtab.appendSliceAssumeCapacity(global.name(elf_file)); | |
| 183 | elf_file.strtab.appendAssumeCapacity(0); | |
| 184 | const out_sym = &elf_file.symtab.items[idx]; | |
| 185 | out_sym.st_name = st_name; | |
| 186 | global.setOutputSym(elf_file, out_sym); | |
| 187 | } | |
| 137 | return switch (file) { | |
| 138 | inline else => |x| x.writeSymtab(elf_file), | |
| 139 | }; | |
| 188 | 140 | } |
| 189 | 141 | |
| 190 | 142 | pub fn updateArSymtab(file: File, ar_symtab: *Archive.ArSymtab, elf_file: *Elf) !void { |
src/link/Elf/synthetic_sections.zig+2-6| ... | ... | @@ -917,8 +917,7 @@ pub const PltSection = struct { |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | 919 | pub fn writeSymtab(plt: PltSection, elf_file: *Elf) void { |
| 920 | var ilocal = plt.output_symtab_ctx.ilocal; | |
| 921 | for (plt.symbols.items) |sym_index| { | |
| 920 | for (plt.symbols.items, plt.output_symtab_ctx.ilocal..) |sym_index, ilocal| { | |
| 922 | 921 | const sym = elf_file.symbol(sym_index); |
| 923 | 922 | const st_name = @as(u32, @intCast(elf_file.strtab.items.len)); |
| 924 | 923 | elf_file.strtab.appendSliceAssumeCapacity(sym.name(elf_file)); |
| ... | ... | @@ -932,7 +931,6 @@ pub const PltSection = struct { |
| 932 | 931 | .st_value = sym.pltAddress(elf_file), |
| 933 | 932 | .st_size = 16, |
| 934 | 933 | }; |
| 935 | ilocal += 1; | |
| 936 | 934 | } |
| 937 | 935 | } |
| 938 | 936 | |
| ... | ... | @@ -1046,8 +1044,7 @@ pub const PltGotSection = struct { |
| 1046 | 1044 | } |
| 1047 | 1045 | |
| 1048 | 1046 | pub fn writeSymtab(plt_got: PltGotSection, elf_file: *Elf) void { |
| 1049 | var ilocal = plt_got.output_symtab_ctx.ilocal; | |
| 1050 | for (plt_got.symbols.items) |sym_index| { | |
| 1047 | for (plt_got.symbols.items, plt_got.output_symtab_ctx.ilocal..) |sym_index, ilocal| { | |
| 1051 | 1048 | const sym = elf_file.symbol(sym_index); |
| 1052 | 1049 | const st_name = @as(u32, @intCast(elf_file.strtab.items.len)); |
| 1053 | 1050 | elf_file.strtab.appendSliceAssumeCapacity(sym.name(elf_file)); |
| ... | ... | @@ -1061,7 +1058,6 @@ pub const PltGotSection = struct { |
| 1061 | 1058 | .st_value = sym.pltGotAddress(elf_file), |
| 1062 | 1059 | .st_size = 16, |
| 1063 | 1060 | }; |
| 1064 | ilocal += 1; | |
| 1065 | 1061 | } |
| 1066 | 1062 | } |
| 1067 | 1063 | }; |