authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-02 17:55:27+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:04+02:00
log509da2316c2f8ec3a3939df09ca288f92dc55905
tree6bacb2680f583d0b135af073526f68e7cda40f5e
parentf0f19e18c77c435795b3454bd6c34517874f02cb

elf: run populateMissingMetadata only if ZigModule exists


1 files changed, 25 insertions(+), 28 deletions(-)

src/link/Elf.zig+25-28
......@@ -231,11 +231,34 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option
231231 self.dwarf = Dwarf.init(allocator, &self.base, options.target);
232232 }
233233
234 const index = @as(File.Index, @intCast(try self.files.addOne(allocator)));
235 self.files.set(index, .{ .zig_module = .{
236 .index = index,
237 .path = options.module.?.main_pkg.root_src_path,
238 } });
239 self.zig_module_index = index;
240 const zig_module = self.file(index).?.zig_module;
241
242 try zig_module.atoms.append(allocator, 0); // null input section
243
244 const name_off = try self.strtab.insert(allocator, std.fs.path.stem(options.module.?.main_mod.root_src_path));
245 const symbol_index = try self.addSymbol();
246 try zig_module.local_symbols.append(allocator, symbol_index);
247 const symbol_ptr = self.symbol(symbol_index);
248 symbol_ptr.file_index = zig_module.index;
249 symbol_ptr.name_offset = name_off;
250
251 const esym_index = try zig_module.addLocalEsym(allocator);
252 const esym = &zig_module.local_esyms.items[esym_index];
253 esym.st_name = name_off;
254 esym.st_info |= elf.STT_FILE;
255 esym.st_shndx = elf.SHN_ABS;
256 symbol_ptr.esym_index = esym_index;
257
234258 // TODO move populateMissingMetadata here renamed to zig_module.initMetadata();
259 try self.populateMissingMetadata();
235260 }
236261
237 try self.populateMissingMetadata();
238
239262 return self;
240263}
241264
......@@ -841,32 +864,6 @@ pub fn populateMissingMetadata(self: *Elf) !void {
841864 self.debug_line_header_dirty = true;
842865 }
843866 }
844
845 if (self.base.options.module) |module| {
846 if (self.zig_module_index == null and !self.base.options.use_llvm) {
847 const index: File.Index = @intCast(try self.files.addOne(gpa));
848 self.files.set(index, .{ .zig_module = .{
849 .index = index,
850 .path = module.main_mod.root_src_path,
851 } });
852 self.zig_module_index = index;
853 const zig_module = self.file(index).?.zig_module;
854 try zig_module.atoms.append(gpa, 0); // null input section
855 const name_off = try self.strtab.insert(gpa, std.fs.path.stem(module.main_mod.root_src_path));
856 const symbol_index = try self.addSymbol();
857 try zig_module.local_symbols.append(gpa, symbol_index);
858 const symbol_ptr = self.symbol(symbol_index);
859 symbol_ptr.file_index = zig_module.index;
860 symbol_ptr.name_offset = name_off;
861
862 const esym_index = try zig_module.addLocalEsym(gpa);
863 const esym = &zig_module.local_esyms.items[esym_index];
864 esym.st_name = name_off;
865 esym.st_info |= elf.STT_FILE;
866 esym.st_shndx = elf.SHN_ABS;
867 symbol_ptr.esym_index = esym_index;
868 }
869 }
870867}
871868
872869pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void {