| author | |
| committer | |
| log | ce88df497c096f5a35200d975de855ba4502a4d8 |
| tree | 05c1f0f612f5149c0a258377d704fef81389dcaa |
| parent | dbde746f9d95f2dbc8872e2d6283c2db64ac7519 |
9 files changed, 33 insertions(+), 26 deletions(-)
src/arch/aarch64/CodeGen.zig+1-1| ... | ... | @@ -4316,7 +4316,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 4316 | 4316 | if (self.bin_file.cast(link.File.Elf)) |elf_file| { |
| 4317 | 4317 | const sym_index = try elf_file.getOrCreateMetadataForDecl(func.owner_decl); |
| 4318 | 4318 | const sym = elf_file.symbol(sym_index); |
| 4319 | _ = try sym.getOrCreateGotEntry(elf_file); | |
| 4319 | _ = try sym.getOrCreateGotEntry(sym_index, elf_file); | |
| 4320 | 4320 | const got_addr = @as(u32, @intCast(sym.gotAddress(elf_file))); |
| 4321 | 4321 | try self.genSetReg(Type.usize, .x30, .{ .memory = got_addr }); |
| 4322 | 4322 | } else if (self.bin_file.cast(link.File.MachO)) |macho_file| { |
src/arch/arm/CodeGen.zig+1-1| ... | ... | @@ -4296,7 +4296,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 4296 | 4296 | if (self.bin_file.cast(link.File.Elf)) |elf_file| { |
| 4297 | 4297 | const sym_index = try elf_file.getOrCreateMetadataForDecl(func.owner_decl); |
| 4298 | 4298 | const sym = elf_file.symbol(sym_index); |
| 4299 | _ = try sym.getOrCreateGotEntry(elf_file); | |
| 4299 | _ = try sym.getOrCreateGotEntry(sym_index, elf_file); | |
| 4300 | 4300 | const got_addr = @as(u32, @intCast(sym.gotAddress(elf_file))); |
| 4301 | 4301 | try self.genSetReg(Type.usize, .lr, .{ .memory = got_addr }); |
| 4302 | 4302 | } else if (self.bin_file.cast(link.File.MachO)) |_| { |
src/arch/riscv64/CodeGen.zig+1-1| ... | ... | @@ -1749,7 +1749,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 1749 | 1749 | .func => |func| { |
| 1750 | 1750 | const sym_index = try elf_file.getOrCreateMetadataForDecl(func.owner_decl); |
| 1751 | 1751 | const sym = elf_file.symbol(sym_index); |
| 1752 | _ = try sym.getOrCreateGotEntry(elf_file); | |
| 1752 | _ = try sym.getOrCreateGotEntry(sym_index, elf_file); | |
| 1753 | 1753 | const got_addr = @as(u32, @intCast(sym.gotAddress(elf_file))); |
| 1754 | 1754 | try self.genSetReg(Type.usize, .ra, .{ .memory = got_addr }); |
| 1755 | 1755 | _ = try self.addInst(.{ |
src/arch/sparc64/CodeGen.zig+1-1| ... | ... | @@ -1351,7 +1351,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 1351 | 1351 | const got_addr = if (self.bin_file.cast(link.File.Elf)) |elf_file| blk: { |
| 1352 | 1352 | const sym_index = try elf_file.getOrCreateMetadataForDecl(func.owner_decl); |
| 1353 | 1353 | const sym = elf_file.symbol(sym_index); |
| 1354 | _ = try sym.getOrCreateGotEntry(elf_file); | |
| 1354 | _ = try sym.getOrCreateGotEntry(sym_index, elf_file); | |
| 1355 | 1355 | break :blk @as(u32, @intCast(sym.gotAddress(elf_file))); |
| 1356 | 1356 | } else unreachable; |
| 1357 | 1357 |
src/arch/x86_64/CodeGen.zig+2-2| ... | ... | @@ -8157,7 +8157,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier |
| 8157 | 8157 | const sym_index = try elf_file.getOrCreateMetadataForDecl(owner_decl); |
| 8158 | 8158 | const sym = elf_file.symbol(sym_index); |
| 8159 | 8159 | sym.flags.needs_got = true; |
| 8160 | _ = try sym.getOrCreateGotEntry(elf_file); | |
| 8160 | _ = try sym.getOrCreateGotEntry(sym_index, elf_file); | |
| 8161 | 8161 | const got_addr = sym.gotAddress(elf_file); |
| 8162 | 8162 | try self.asmMemory(.{ ._, .call }, Memory.sib(.qword, .{ |
| 8163 | 8163 | .base = .{ .reg = .ds }, |
| ... | ... | @@ -10236,7 +10236,7 @@ fn genLazySymbolRef( |
| 10236 | 10236 | return self.fail("{s} creating lazy symbol", .{@errorName(err)}); |
| 10237 | 10237 | const sym = elf_file.symbol(sym_index); |
| 10238 | 10238 | sym.flags.needs_got = true; |
| 10239 | _ = try sym.getOrCreateGotEntry(elf_file); | |
| 10239 | _ = try sym.getOrCreateGotEntry(sym_index, elf_file); | |
| 10240 | 10240 | const got_addr = sym.gotAddress(elf_file); |
| 10241 | 10241 | const got_mem = |
| 10242 | 10242 | Memory.sib(.qword, .{ .base = .{ .reg = .ds }, .disp = @intCast(got_addr) }); |
src/codegen.zig+1-1| ... | ... | @@ -861,7 +861,7 @@ fn genDeclRef( |
| 861 | 861 | const sym_index = try elf_file.getOrCreateMetadataForDecl(decl_index); |
| 862 | 862 | const sym = elf_file.symbol(sym_index); |
| 863 | 863 | sym.flags.needs_got = true; |
| 864 | _ = try sym.getOrCreateGotEntry(elf_file); | |
| 864 | _ = try sym.getOrCreateGotEntry(sym_index, elf_file); | |
| 865 | 865 | return GenResult.mcv(.{ .memory = sym.gotAddress(elf_file) }); |
| 866 | 866 | } else if (bin_file.cast(link.File.MachO)) |macho_file| { |
| 867 | 867 | const atom_index = try macho_file.getOrCreateAtomForDecl(decl_index); |
src/link/Elf.zig+9-8| ... | ... | @@ -1082,9 +1082,10 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1082 | 1082 | if (comp.compiler_rt_obj) |x| break :blk x.full_object_path; |
| 1083 | 1083 | break :blk null; |
| 1084 | 1084 | }; |
| 1085 | if (compiler_rt_path) |path| { | |
| 1086 | try positionals.append(.{ .path = path }); | |
| 1087 | } | |
| 1085 | _ = compiler_rt_path; | |
| 1086 | // if (compiler_rt_path) |path| { | |
| 1087 | // try positionals.append(.{ .path = path }); | |
| 1088 | // } | |
| 1088 | 1089 | |
| 1089 | 1090 | for (positionals.items) |obj| { |
| 1090 | 1091 | const in_file = try std.fs.cwd().openFile(obj.path, .{}); |
| ... | ... | @@ -1643,11 +1644,11 @@ fn scanRelocs(self: *Elf) !void { |
| 1643 | 1644 | |
| 1644 | 1645 | try self.reportUndefined(&undefs); |
| 1645 | 1646 | |
| 1646 | for (self.symbols.items) |*sym| { | |
| 1647 | for (self.symbols.items, 0..) |*sym, sym_index| { | |
| 1647 | 1648 | if (sym.flags.needs_got) { |
| 1648 | 1649 | log.debug("'{s}' needs GOT", .{sym.name(self)}); |
| 1649 | 1650 | // TODO how can we tell we need to write it again, aka the entry is dirty? |
| 1650 | const gop = try sym.getOrCreateGotEntry(self); | |
| 1651 | const gop = try sym.getOrCreateGotEntry(@intCast(sym_index), self); | |
| 1651 | 1652 | try self.got.writeEntry(self, gop.index); |
| 1652 | 1653 | } |
| 1653 | 1654 | } |
| ... | ... | @@ -2695,7 +2696,7 @@ fn updateDeclCode( |
| 2695 | 2696 | esym.st_value = atom_ptr.value; |
| 2696 | 2697 | |
| 2697 | 2698 | sym.flags.needs_got = true; |
| 2698 | const gop = try sym.getOrCreateGotEntry(self); | |
| 2699 | const gop = try sym.getOrCreateGotEntry(sym_index, self); | |
| 2699 | 2700 | try self.got.writeEntry(self, gop.index); |
| 2700 | 2701 | } |
| 2701 | 2702 | |
| ... | ... | @@ -2930,7 +2931,7 @@ fn updateLazySymbol(self: *Elf, sym: link.File.LazySymbol, symbol_index: Symbol. |
| 2930 | 2931 | local_esym.st_value = atom_ptr.value; |
| 2931 | 2932 | |
| 2932 | 2933 | local_sym.flags.needs_got = true; |
| 2933 | const gop = try local_sym.getOrCreateGotEntry(self); | |
| 2934 | const gop = try local_sym.getOrCreateGotEntry(symbol_index, self); | |
| 2934 | 2935 | try self.got.writeEntry(self, gop.index); |
| 2935 | 2936 | |
| 2936 | 2937 | const section_offset = atom_ptr.value - self.phdrs.items[phdr_index].p_vaddr; |
| ... | ... | @@ -3801,7 +3802,7 @@ pub fn addSymbol(self: *Elf) !Symbol.Index { |
| 3801 | 3802 | break :blk index; |
| 3802 | 3803 | } |
| 3803 | 3804 | }; |
| 3804 | self.symbols.items[index] = .{ .index = index }; | |
| 3805 | self.symbols.items[index] = .{}; | |
| 3805 | 3806 | return index; |
| 3806 | 3807 | } |
| 3807 | 3808 |
src/link/Elf/Atom.zig+14-6| ... | ... | @@ -322,11 +322,12 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, undefs: anytype) !void { |
| 322 | 322 | |
| 323 | 323 | if (rel.r_type() == elf.R_X86_64_NONE) continue; |
| 324 | 324 | |
| 325 | const symbol = switch (file_ptr) { | |
| 326 | .zig_module => |x| elf_file.symbol(x.symbol(rel.r_sym())), | |
| 327 | .object => |x| elf_file.symbol(x.symbols.items[rel.r_sym()]), | |
| 325 | const symbol_index = switch (file_ptr) { | |
| 326 | .zig_module => |x| x.symbol(rel.r_sym()), | |
| 327 | .object => |x| x.symbols.items[rel.r_sym()], | |
| 328 | 328 | else => unreachable, |
| 329 | 329 | }; |
| 330 | const symbol = elf_file.symbol(symbol_index); | |
| 330 | 331 | |
| 331 | 332 | // Check for violation of One Definition Rule for COMDATs. |
| 332 | 333 | if (symbol.file(elf_file) == null) { |
| ... | ... | @@ -340,7 +341,7 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, undefs: anytype) !void { |
| 340 | 341 | } |
| 341 | 342 | |
| 342 | 343 | // Report an undefined symbol. |
| 343 | try self.reportUndefined(elf_file, symbol, rel, undefs); | |
| 344 | try self.reportUndefined(elf_file, symbol, symbol_index, rel, undefs); | |
| 344 | 345 | |
| 345 | 346 | // While traversing relocations, mark symbols that require special handling such as |
| 346 | 347 | // pointer indirection via GOT, or a stub trampoline via PLT. |
| ... | ... | @@ -379,7 +380,14 @@ pub fn scanRelocs(self: Atom, elf_file: *Elf, undefs: anytype) !void { |
| 379 | 380 | } |
| 380 | 381 | |
| 381 | 382 | // This function will report any undefined non-weak symbols that are not imports. |
| 382 | fn reportUndefined(self: Atom, elf_file: *Elf, sym: *const Symbol, rel: elf.Elf64_Rela, undefs: anytype) !void { | |
| 383 | fn reportUndefined( | |
| 384 | self: Atom, | |
| 385 | elf_file: *Elf, | |
| 386 | sym: *const Symbol, | |
| 387 | sym_index: Symbol.Index, | |
| 388 | rel: elf.Elf64_Rela, | |
| 389 | undefs: anytype, | |
| 390 | ) !void { | |
| 383 | 391 | const rel_esym = switch (elf_file.file(self.file_index).?) { |
| 384 | 392 | .zig_module => |x| x.elfSym(rel.r_sym()).*, |
| 385 | 393 | .object => |x| x.symtab[rel.r_sym()], |
| ... | ... | @@ -392,7 +400,7 @@ fn reportUndefined(self: Atom, elf_file: *Elf, sym: *const Symbol, rel: elf.Elf6 |
| 392 | 400 | !sym.flags.import and |
| 393 | 401 | esym.st_shndx == elf.SHN_UNDEF) |
| 394 | 402 | { |
| 395 | const gop = try undefs.getOrPut(sym.index); | |
| 403 | const gop = try undefs.getOrPut(sym_index); | |
| 396 | 404 | if (!gop.found_existing) { |
| 397 | 405 | gop.value_ptr.* = std.ArrayList(Atom.Index).init(elf_file.base.allocator); |
| 398 | 406 | } |
src/link/Elf/Symbol.zig+3-5| ... | ... | @@ -1,7 +1,5 @@ |
| 1 | 1 | //! Represents a defined symbol. |
| 2 | 2 | |
| 3 | index: Index = 0, | |
| 4 | ||
| 5 | 3 | /// Allocated address value of this symbol. |
| 6 | 4 | value: u64 = 0, |
| 7 | 5 | |
| ... | ... | @@ -117,10 +115,10 @@ const GetOrCreateGotEntryResult = struct { |
| 117 | 115 | index: GotSection.Index, |
| 118 | 116 | }; |
| 119 | 117 | |
| 120 | pub fn getOrCreateGotEntry(symbol: *Symbol, elf_file: *Elf) !GetOrCreateGotEntryResult { | |
| 118 | pub fn getOrCreateGotEntry(symbol: *Symbol, symbol_index: Index, elf_file: *Elf) !GetOrCreateGotEntryResult { | |
| 121 | 119 | assert(symbol.flags.needs_got); |
| 122 | 120 | if (symbol.flags.has_got) return .{ .found_existing = true, .index = symbol.extra(elf_file).?.got }; |
| 123 | const index = try elf_file.got.addGotSymbol(symbol.index, elf_file); | |
| 121 | const index = try elf_file.got.addGotSymbol(symbol_index, elf_file); | |
| 124 | 122 | symbol.flags.has_got = true; |
| 125 | 123 | return .{ .found_existing = false, .index = index }; |
| 126 | 124 | } |
| ... | ... | @@ -270,7 +268,7 @@ fn format2( |
| 270 | 268 | _ = options; |
| 271 | 269 | _ = unused_fmt_string; |
| 272 | 270 | const symbol = ctx.symbol; |
| 273 | try writer.print("%{d} : {s} : @{x}", .{ symbol.index, symbol.fmtName(ctx.elf_file), symbol.value }); | |
| 271 | try writer.print("%{d} : {s} : @{x}", .{ symbol.esym_index, symbol.fmtName(ctx.elf_file), symbol.value }); | |
| 274 | 272 | if (symbol.file(ctx.elf_file)) |file_ptr| { |
| 275 | 273 | if (symbol.isAbs(ctx.elf_file)) { |
| 276 | 274 | if (symbol.elfSym(ctx.elf_file).st_shndx == elf.SHN_UNDEF) { |