From 1c3fd16c3777d8bf61e681a49fbcff0803dd9609 Mon Sep 17 00:00:00 2001 From: Jakub Konka Date: Sun, 10 Sep 2023 09:10:00 +0200 Subject: elf: write linker-defined symbols to symtab --- src/link/Elf.zig | 12 +++++++++++ src/link/Elf/LinkerDefined.zig | 46 +++++++++++++++++------------------------- 2 files changed, 31 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/link/Elf.zig b/src/link/Elf.zig index e858a0ecb2..535550c8fc 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -2774,6 +2774,12 @@ fn updateSymtabSize(self: *Elf) !void { sizes.nglobals += zig_module.output_symtab_size.nglobals; } + if (self.linker_defined_index) |index| { + const linker_defined = self.file(index).?.linker_defined; + linker_defined.updateSymtabSize(self); + sizes.nlocals += linker_defined.output_symtab_size.nlocals; + } + if (self.got_section_index) |_| { self.got.updateSymtabSize(self); sizes.nlocals += self.got.output_symtab_size.nlocals; @@ -2823,6 +2829,12 @@ fn writeSymtab(self: *Elf) !void { ctx.iglobal += zig_module.output_symtab_size.nglobals; } + if (self.linker_defined_index) |index| { + const linker_defined = self.file(index).?.linker_defined; + linker_defined.writeSymtab(self, ctx); + ctx.ilocal += linker_defined.output_symtab_size.nlocals; + } + if (self.got_section_index) |_| { try self.got.writeSymtab(self, ctx); ctx.ilocal += self.got.output_symtab_size.nlocals; diff --git a/src/link/Elf/LinkerDefined.zig b/src/link/Elf/LinkerDefined.zig index 9bfff35302..3f71e0a58e 100644 --- a/src/link/Elf/LinkerDefined.zig +++ b/src/link/Elf/LinkerDefined.zig @@ -3,7 +3,7 @@ symtab: std.ArrayListUnmanaged(elf.Elf64_Sym) = .{}, symbols: std.ArrayListUnmanaged(Symbol.Index) = .{}, alive: bool = true, -// output_symtab_size: Elf.SymtabSize = .{}, +output_symtab_size: Elf.SymtabSize = .{}, pub fn deinit(self: *LinkerDefined, allocator: Allocator) void { self.symtab.deinit(allocator); @@ -56,33 +56,25 @@ pub fn resolveSymbols(self: *LinkerDefined, elf_file: *Elf) void { // } // } -// pub fn calcSymtabSize(self: *InternalObject, elf_file: *Elf) !void { -// if (elf_file.options.strip_all) return; - -// for (self.getGlobals()) |global_index| { -// const global = elf_file.getSymbol(global_index); -// if (global.getFile(elf_file)) |file| if (file.getIndex() != self.index) continue; -// global.flags.output_symtab = true; -// self.output_symtab_size.nlocals += 1; -// self.output_symtab_size.strsize += @as(u32, @intCast(global.getName(elf_file).len + 1)); -// } -// } - -// pub fn writeSymtab(self: *LinkerDefined, elf_file: *Elf, ctx: Elf.WriteSymtabCtx) !void { -// if (elf_file.options.strip_all) return; - -// const gpa = elf_file.base.allocator; +pub fn updateSymtabSize(self: *LinkerDefined, elf_file: *Elf) void { + for (self.globals()) |global_index| { + const global = elf_file.symbol(global_index); + if (global.file(elf_file)) |file| if (file.index() != self.index) continue; + global.flags.output_symtab = true; + self.output_symtab_size.nlocals += 1; + } +} -// var ilocal = ctx.ilocal; -// for (self.getGlobals()) |global_index| { -// const global = elf_file.getSymbol(global_index); -// if (global.getFile(elf_file)) |file| if (file.getIndex() != self.index) continue; -// if (!global.flags.output_symtab) continue; -// const st_name = try ctx.strtab.insert(gpa, global.getName(elf_file)); -// ctx.symtab[ilocal] = global.asElfSym(st_name, elf_file); -// ilocal += 1; -// } -// } +pub fn writeSymtab(self: *LinkerDefined, elf_file: *Elf, ctx: anytype) void { + var ilocal = ctx.ilocal; + for (self.globals()) |global_index| { + const global = elf_file.symbol(global_index); + if (global.file(elf_file)) |file| if (file.index() != self.index) continue; + if (!global.flags.output_symtab) continue; + global.setOutputSym(elf_file, &ctx.symtab[ilocal]); + ilocal += 1; + } +} pub fn sourceSymbol(self: *LinkerDefined, symbol_index: Symbol.Index) *elf.Elf64_Sym { return &self.symtab.items[symbol_index]; -- cgit v1.2.3