| author | |
| committer | |
| log | 75f4420c2db46cc3d9fe9c75ac035c588bbcf4bf |
| tree | 5a450dd667f9454133cad9b9e1b2163554c36590 |
| parent | 605e3eb08cffd40af98ff1bb2080d3e5f29da861 |
4 files changed, 19 insertions(+), 20 deletions(-)
src/link/Elf.zig+3-3| ... | ... | @@ -887,7 +887,7 @@ pub fn populateMissingMetadata(self: *Elf) !void { |
| 887 | 887 | } }); |
| 888 | 888 | self.zig_module_index = index; |
| 889 | 889 | const zig_module = self.file(index).?.zig_module; |
| 890 | ||
| 890 | try zig_module.atoms.append(gpa, 0); // null input section | |
| 891 | 891 | const name_off = try self.strtab.insert(gpa, std.fs.path.stem(module.main_mod.root_src_path)); |
| 892 | 892 | const symbol_index = try self.addSymbol(); |
| 893 | 893 | try zig_module.local_symbols.append(gpa, symbol_index); |
| ... | ... | @@ -1319,7 +1319,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1319 | 1319 | // the relocations, and commit objects to file. |
| 1320 | 1320 | if (self.zig_module_index) |index| { |
| 1321 | 1321 | const zig_module = self.file(index).?.zig_module; |
| 1322 | for (zig_module.atoms.keys()) |atom_index| { | |
| 1322 | for (zig_module.atoms.items) |atom_index| { | |
| 1323 | 1323 | const atom_ptr = self.atom(atom_index).?; |
| 1324 | 1324 | if (!atom_ptr.flags.alive) continue; |
| 1325 | 1325 | const shdr = &self.shdrs.items[atom_ptr.outputShndx().?]; |
| ... | ... | @@ -3245,7 +3245,7 @@ pub fn updateDeclExports( |
| 3245 | 3245 | }; |
| 3246 | 3246 | const esym = &zig_module.global_esyms.items[sym_index & 0x0fffffff]; |
| 3247 | 3247 | esym.st_value = decl_sym.value; |
| 3248 | esym.st_shndx = decl_sym.atom_index; | |
| 3248 | esym.st_shndx = decl_esym.st_shndx; | |
| 3249 | 3249 | esym.st_info = (stb_bits << 4) | stt_bits; |
| 3250 | 3250 | esym.st_name = name_off; |
| 3251 | 3251 | } |
src/link/Elf/Atom.zig+6-8| ... | ... | @@ -14,13 +14,13 @@ size: u64 = 0, |
| 14 | 14 | alignment: Alignment = .@"1", |
| 15 | 15 | |
| 16 | 16 | /// Index of the input section. |
| 17 | input_section_index: Index = 0, | |
| 17 | input_section_index: u16 = 0, | |
| 18 | 18 | |
| 19 | 19 | /// Index of the output section. |
| 20 | 20 | output_section_index: u16 = 0, |
| 21 | 21 | |
| 22 | 22 | /// Index of the input section containing this atom's relocs. |
| 23 | relocs_section_index: Index = 0, | |
| 23 | relocs_section_index: u16 = 0, | |
| 24 | 24 | |
| 25 | 25 | /// Index of this atom in the linker's atoms table. |
| 26 | 26 | atom_index: Index = 0, |
| ... | ... | @@ -216,7 +216,6 @@ pub fn free(self: *Atom, elf_file: *Elf) void { |
| 216 | 216 | log.debug("freeAtom {d} ({s})", .{ self.atom_index, self.name(elf_file) }); |
| 217 | 217 | |
| 218 | 218 | const gpa = elf_file.base.allocator; |
| 219 | const zig_module = self.file(elf_file).?.zig_module; | |
| 220 | 219 | const shndx = self.outputShndx().?; |
| 221 | 220 | const meta = elf_file.last_atom_and_free_list_table.getPtr(shndx).?; |
| 222 | 221 | const free_list = &meta.free_list; |
| ... | ... | @@ -267,7 +266,9 @@ pub fn free(self: *Atom, elf_file: *Elf) void { |
| 267 | 266 | |
| 268 | 267 | // TODO create relocs free list |
| 269 | 268 | self.freeRelocs(elf_file); |
| 270 | assert(zig_module.atoms.swapRemove(self.atom_index)); | |
| 269 | // TODO figure out how to free input section mappind in ZigModule | |
| 270 | // const zig_module = self.file(elf_file).?.zig_module; | |
| 271 | // assert(zig_module.atoms.swapRemove(self.atom_index)); | |
| 271 | 272 | self.* = .{}; |
| 272 | 273 | } |
| 273 | 274 | |
| ... | ... | @@ -698,10 +699,7 @@ fn format2( |
| 698 | 699 | } |
| 699 | 700 | } |
| 700 | 701 | |
| 701 | // TODO this has to be u32 but for now, to avoid redesigning elfSym machinery for | |
| 702 | // ZigModule, keep it at u16 with the intention of bumping it to u32 in the near | |
| 703 | // future. | |
| 704 | pub const Index = u16; | |
| 702 | pub const Index = u32; | |
| 705 | 703 | |
| 706 | 704 | pub const Flags = packed struct { |
| 707 | 705 | /// Specifies whether this atom is alive or has been garbage collected. |
src/link/Elf/ZigModule.zig+9-8| ... | ... | @@ -13,7 +13,7 @@ local_symbols: std.ArrayListUnmanaged(Symbol.Index) = .{}, |
| 13 | 13 | global_symbols: std.ArrayListUnmanaged(Symbol.Index) = .{}, |
| 14 | 14 | globals_lookup: std.AutoHashMapUnmanaged(u32, Symbol.Index) = .{}, |
| 15 | 15 | |
| 16 | atoms: std.AutoArrayHashMapUnmanaged(Atom.Index, void) = .{}, | |
| 16 | atoms: std.ArrayListUnmanaged(Atom.Index) = .{}, | |
| 17 | 17 | relocs: std.ArrayListUnmanaged(std.ArrayListUnmanaged(elf.Elf64_Rela)) = .{}, |
| 18 | 18 | |
| 19 | 19 | output_symtab_size: Elf.SymtabSize = .{}, |
| ... | ... | @@ -56,7 +56,8 @@ pub fn addAtom(self: *ZigModule, elf_file: *Elf) !Symbol.Index { |
| 56 | 56 | const symbol_index = try elf_file.addSymbol(); |
| 57 | 57 | const esym_index = try self.addLocalEsym(gpa); |
| 58 | 58 | |
| 59 | try self.atoms.putNoClobber(gpa, atom_index, {}); | |
| 59 | const shndx = @as(u16, @intCast(self.atoms.items.len)); | |
| 60 | try self.atoms.append(gpa, atom_index); | |
| 60 | 61 | try self.local_symbols.append(gpa, symbol_index); |
| 61 | 62 | |
| 62 | 63 | const atom_ptr = elf_file.atom(atom_index).?; |
| ... | ... | @@ -67,10 +68,10 @@ pub fn addAtom(self: *ZigModule, elf_file: *Elf) !Symbol.Index { |
| 67 | 68 | symbol_ptr.atom_index = atom_index; |
| 68 | 69 | |
| 69 | 70 | const esym = &self.local_esyms.items[esym_index]; |
| 70 | esym.st_shndx = atom_index; | |
| 71 | esym.st_shndx = shndx; | |
| 71 | 72 | symbol_ptr.esym_index = esym_index; |
| 72 | 73 | |
| 73 | const relocs_index = @as(Atom.Index, @intCast(self.relocs.items.len)); | |
| 74 | const relocs_index = @as(u16, @intCast(self.relocs.items.len)); | |
| 74 | 75 | const relocs = try self.relocs.addOne(gpa); |
| 75 | 76 | relocs.* = .{}; |
| 76 | 77 | atom_ptr.relocs_section_index = relocs_index; |
| ... | ... | @@ -86,7 +87,7 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void { |
| 86 | 87 | if (esym.st_shndx == elf.SHN_UNDEF) continue; |
| 87 | 88 | |
| 88 | 89 | if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) { |
| 89 | const atom_index = esym.st_shndx; | |
| 90 | const atom_index = self.atoms.items[esym.st_shndx]; | |
| 90 | 91 | const atom = elf_file.atom(atom_index) orelse continue; |
| 91 | 92 | if (!atom.flags.alive) continue; |
| 92 | 93 | } |
| ... | ... | @@ -95,7 +96,7 @@ pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void { |
| 95 | 96 | if (self.asFile().symbolRank(esym, false) < global.symbolRank(elf_file)) { |
| 96 | 97 | const atom_index = switch (esym.st_shndx) { |
| 97 | 98 | elf.SHN_ABS, elf.SHN_COMMON => 0, |
| 98 | else => esym.st_shndx, | |
| 99 | else => self.atoms.items[esym.st_shndx], | |
| 99 | 100 | }; |
| 100 | 101 | const output_section_index = if (elf_file.atom(atom_index)) |atom| |
| 101 | 102 | atom.outputShndx().? |
| ... | ... | @@ -141,7 +142,7 @@ pub fn claimUnresolved(self: *ZigModule, elf_file: *Elf) void { |
| 141 | 142 | } |
| 142 | 143 | |
| 143 | 144 | pub fn scanRelocs(self: *ZigModule, elf_file: *Elf, undefs: anytype) !void { |
| 144 | for (self.atoms.keys()) |atom_index| { | |
| 145 | for (self.atoms.items) |atom_index| { | |
| 145 | 146 | const atom = elf_file.atom(atom_index) orelse continue; |
| 146 | 147 | if (!atom.flags.alive) continue; |
| 147 | 148 | if (try atom.scanRelocsRequiresCode(elf_file)) { |
| ... | ... | @@ -324,7 +325,7 @@ fn formatAtoms( |
| 324 | 325 | _ = unused_fmt_string; |
| 325 | 326 | _ = options; |
| 326 | 327 | try writer.writeAll(" atoms\n"); |
| 327 | for (ctx.self.atoms.keys()) |atom_index| { | |
| 328 | for (ctx.self.atoms.items) |atom_index| { | |
| 328 | 329 | const atom = ctx.elf_file.atom(atom_index) orelse continue; |
| 329 | 330 | try writer.print(" {}\n", .{atom.fmt(ctx.elf_file)}); |
| 330 | 331 | } |
src/link/Elf/file.zig+1-1| ... | ... | @@ -92,7 +92,7 @@ pub const File = union(enum) { |
| 92 | 92 | pub fn atoms(file: File) []const Atom.Index { |
| 93 | 93 | return switch (file) { |
| 94 | 94 | .linker_defined => unreachable, |
| 95 | .zig_module => |x| x.atoms.keys(), | |
| 95 | .zig_module => |x| x.atoms.items, | |
| 96 | 96 | .object => |x| x.atoms.items, |
| 97 | 97 | }; |
| 98 | 98 | } |