| ... | ... | @@ -1,6 +1,7 @@ |
| 1 | 1 | pub const Atom = @import("Elf/Atom.zig"); |
| 2 | 2 | |
| 3 | 3 | base: link.File, |
| 4 | zig_object: ?*ZigObject, |
| 4 | 5 | rpath_table: std.StringArrayHashMapUnmanaged(void), |
| 5 | 6 | image_base: u64, |
| 6 | 7 | emit_relocs: bool, |
| ... | ... | @@ -299,6 +300,7 @@ pub fn createEmpty( |
| 299 | 300 | .disable_lld_caching = options.disable_lld_caching, |
| 300 | 301 | .build_id = options.build_id, |
| 301 | 302 | }, |
| 303 | .zig_object = null, |
| 302 | 304 | .rpath_table = rpath_table, |
| 303 | 305 | .ptr_width = ptr_width, |
| 304 | 306 | .page_size = page_size, |
| ... | ... | @@ -423,14 +425,17 @@ pub fn createEmpty( |
| 423 | 425 | if (opt_zcu) |zcu| { |
| 424 | 426 | if (!use_llvm) { |
| 425 | 427 | const index: File.Index = @intCast(try self.files.addOne(gpa)); |
| 426 | | self.files.set(index, .{ .zig_object = .{ |
| 428 | self.files.set(index, .zig_object); |
| 429 | self.zig_object_index = index; |
| 430 | const zig_object = try arena.create(ZigObject); |
| 431 | self.zig_object = zig_object; |
| 432 | zig_object.* = .{ |
| 427 | 433 | .index = index, |
| 428 | 434 | .basename = try std.fmt.allocPrint(arena, "{s}.o", .{ |
| 429 | 435 | fs.path.stem(zcu.main_mod.root_src_path), |
| 430 | 436 | }), |
| 431 | | } }); |
| 432 | | self.zig_object_index = index; |
| 433 | | try self.zigObjectPtr().?.init(self, .{ |
| 437 | }; |
| 438 | try zig_object.init(self, .{ |
| 434 | 439 | .symbol_count_hint = options.symbol_count_hint, |
| 435 | 440 | .program_code_size_hint = options.program_code_size_hint, |
| 436 | 441 | }); |
| ... | ... | @@ -462,12 +467,14 @@ pub fn deinit(self: *Elf) void { |
| 462 | 467 | self.file_handles.deinit(gpa); |
| 463 | 468 | |
| 464 | 469 | for (self.files.items(.tags), self.files.items(.data)) |tag, *data| switch (tag) { |
| 465 | | .null => {}, |
| 466 | | .zig_object => data.zig_object.deinit(gpa), |
| 470 | .null, .zig_object => {}, |
| 467 | 471 | .linker_defined => data.linker_defined.deinit(gpa), |
| 468 | 472 | .object => data.object.deinit(gpa), |
| 469 | 473 | .shared_object => data.shared_object.deinit(gpa), |
| 470 | 474 | }; |
| 475 | if (self.zig_object) |zig_object| { |
| 476 | zig_object.deinit(gpa); |
| 477 | } |
| 471 | 478 | self.files.deinit(gpa); |
| 472 | 479 | self.objects.deinit(gpa); |
| 473 | 480 | self.shared_objects.deinit(gpa); |
| ... | ... | @@ -1242,7 +1249,7 @@ fn parseDso( |
| 1242 | 1249 | .output_symtab_ctx = .{}, |
| 1243 | 1250 | }, |
| 1244 | 1251 | }); |
| 1245 | | const so = fileLookup(files.*, index).?.shared_object; |
| 1252 | const so = fileLookup(files.*, index, null).?.shared_object; |
| 1246 | 1253 | |
| 1247 | 1254 | // TODO: save this work for later |
| 1248 | 1255 | const nsyms = parsed.symbols.len; |
| ... | ... | @@ -3118,7 +3125,7 @@ pub fn sortShdrs( |
| 3118 | 3125 | for (slice.items(.shdr), slice.items(.atom_list_2)) |*shdr, *atom_list| { |
| 3119 | 3126 | atom_list.output_section_index = backlinks[atom_list.output_section_index]; |
| 3120 | 3127 | for (atom_list.atoms.keys()) |ref| { |
| 3121 | | fileLookup(files, ref.file).?.atom(ref.index).?.output_section_index = atom_list.output_section_index; |
| 3128 | fileLookup(files, ref.file, zig_object_ptr).?.atom(ref.index).?.output_section_index = atom_list.output_section_index; |
| 3122 | 3129 | } |
| 3123 | 3130 | if (shdr.sh_type == elf.SHT_RELA) { |
| 3124 | 3131 | // FIXME:JK we should spin up .symtab potentially earlier, or set all non-dynamic RELA sections |
| ... | ... | @@ -4348,15 +4355,15 @@ pub fn thunk(self: *Elf, index: Thunk.Index) *Thunk { |
| 4348 | 4355 | } |
| 4349 | 4356 | |
| 4350 | 4357 | pub fn file(self: *Elf, index: File.Index) ?File { |
| 4351 | | return fileLookup(self.files, index); |
| 4358 | return fileLookup(self.files, index, self.zig_object); |
| 4352 | 4359 | } |
| 4353 | 4360 | |
| 4354 | | fn fileLookup(files: std.MultiArrayList(File.Entry), index: File.Index) ?File { |
| 4361 | fn fileLookup(files: std.MultiArrayList(File.Entry), index: File.Index, zig_object: ?*ZigObject) ?File { |
| 4355 | 4362 | const tag = files.items(.tags)[index]; |
| 4356 | 4363 | return switch (tag) { |
| 4357 | 4364 | .null => null, |
| 4358 | 4365 | .linker_defined => .{ .linker_defined = &files.items(.data)[index].linker_defined }, |
| 4359 | | .zig_object => .{ .zig_object = &files.items(.data)[index].zig_object }, |
| 4366 | .zig_object => .{ .zig_object = zig_object.? }, |
| 4360 | 4367 | .object => .{ .object = &files.items(.data)[index].object }, |
| 4361 | 4368 | .shared_object => .{ .shared_object = &files.items(.data)[index].shared_object }, |
| 4362 | 4369 | }; |
| ... | ... | @@ -4394,8 +4401,7 @@ pub fn getGlobalSymbol(self: *Elf, name: []const u8, lib_name: ?[]const u8) !u32 |
| 4394 | 4401 | } |
| 4395 | 4402 | |
| 4396 | 4403 | pub fn zigObjectPtr(self: *Elf) ?*ZigObject { |
| 4397 | | const index = self.zig_object_index orelse return null; |
| 4398 | | return self.file(index).?.zig_object; |
| 4404 | return self.zig_object; |
| 4399 | 4405 | } |
| 4400 | 4406 | |
| 4401 | 4407 | pub fn linkerDefinedPtr(self: *Elf) ?*LinkerDefined { |