| ... | @@ -231,11 +231,34 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option | ... | @@ -231,11 +231,34 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option |
| 231 | self.dwarf = Dwarf.init(allocator, &self.base, options.target); | 231 | self.dwarf = Dwarf.init(allocator, &self.base, options.target); |
| 232 | } | 232 | } |
| 233 | | 233 | |
| | 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 | |
| 234 | // TODO move populateMissingMetadata here renamed to zig_module.initMetadata(); | 258 | // TODO move populateMissingMetadata here renamed to zig_module.initMetadata(); |
| | 259 | try self.populateMissingMetadata(); |
| 235 | } | 260 | } |
| 236 | | 261 | |
| 237 | try self.populateMissingMetadata(); | | |
| 238 | | | |
| 239 | return self; | 262 | return self; |
| 240 | } | 263 | } |
| 241 | | 264 | |
| ... | @@ -841,32 +864,6 @@ pub fn populateMissingMetadata(self: *Elf) !void { | ... | @@ -841,32 +864,6 @@ pub fn populateMissingMetadata(self: *Elf) !void { |
| 841 | self.debug_line_header_dirty = true; | 864 | self.debug_line_header_dirty = true; |
| 842 | } | 865 | } |
| 843 | } | 866 | } |
| 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 | } | | |
| 870 | } | 867 | } |
| 871 | | 868 | |
| 872 | pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void { | 869 | pub fn growAllocSection(self: *Elf, shdr_index: u16, needed_size: u64) !void { |