zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 509da2316c2f8ec3a3939df09ca288f92dc55905 (tree)
parent f0f19e18c77c435795b3454bd6c34517874f02cb
Author: Jakub Konka <kubkon@jakubkonka.com>
Date:   Mon,  2 Oct 2023 17:55:27 +0200

elf: run populateMissingMetadata only if ZigModule exists

Diffstat:
Msrc/link/Elf.zig | 53+++++++++++++++++++++++++----------------------------
1 file changed, 25 insertions(+), 28 deletions(-)

diff --git a/src/link/Elf.zig b/src/link/Elf.zig @@ -231,11 +231,34 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option self.dwarf = Dwarf.init(allocator, &self.base, options.target); } + const index = @as(File.Index, @intCast(try self.files.addOne(allocator))); + self.files.set(index, .{ .zig_module = .{ + .index = index, + .path = options.module.?.main_pkg.root_src_path, + } }); + self.zig_module_index = index; + const zig_module = self.file(index).?.zig_module; + + try zig_module.atoms.append(allocator, 0); // null input section + + const name_off = try self.strtab.insert(allocator, std.fs.path.stem(options.module.?.main_mod.root_src_path)); + const symbol_index = try self.addSymbol(); + try zig_module.local_symbols.append(allocator, symbol_index); + const symbol_ptr = self.symbol(symbol_index); + symbol_ptr.file_index = zig_module.index; + symbol_ptr.name_offset = name_off; + + const esym_index = try zig_module.addLocalEsym(allocator); + const esym = &zig_module.local_esyms.items[esym_index]; + esym.st_name = name_off; + esym.st_info |= elf.STT_FILE; + esym.st_shndx = elf.SHN_ABS; + symbol_ptr.esym_index = esym_index; + // TODO move populateMissingMetadata here renamed to zig_module.initMetadata(); + try self.populateMissingMetadata(); } - try self.populateMissingMetadata(); - return self; } @@ -841,32 +864,6 @@ pub fn populateMissingMetadata(self: *Elf) !void { self.debug_line_header_dirty = true; } } - - if (self.base.options.module) |module| { - if (self.zig_module_index == null and !self.base.options.use_llvm) { - const index: File.Index = @intCast(try self.files.addOne(gpa)); - self.files.set(index, .{ .zig_module = .{ - .index = index, - .path = module.main_mod.root_src_path, - } }); - self.zig_module_index = index; - const zig_module = self.file(index).?.zig_module; - try zig_module.atoms.append(gpa, 0); // null input section - const name_off = try self.strtab.insert(gpa, std.fs.path.stem(module.main_mod.root_src_path)); - const symbol_index = try self.addSymbol(); - try zig_module.local_symbols.append(gpa, symbol_index); - const symbol_ptr = self.symbol(symbol_index); - symbol_ptr.file_index = zig_module.index; - symbol_ptr.name_offset = name_off; - - const esym_index = try zig_module.addLocalEsym(gpa); - const esym = &zig_module.local_esyms.items[esym_index]; - esym.st_name = name_off; - esym.st_info |= elf.STT_FILE; - esym.st_shndx = elf.SHN_ABS; - symbol_ptr.esym_index = esym_index; - } - } } pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {