| author | |
| committer | |
| log | ccb2afacc00264897cc474befc13f36239c91b03 |
| tree | 9721a74a2212395012b11ea5224ee6bc502c9de8 |
| parent | 5affd29b4799712d4cbf00231ed52de4034b345d |
5 files changed, 14 insertions(+), 12 deletions(-)
src/arch/x86_64/CodeGen.zig+2-3| ... | ... | @@ -10235,7 +10235,7 @@ fn genCall(self: *Self, info: union(enum) { |
| 10235 | 10235 | if (self.bin_file.cast(link.File.Elf)) |elf_file| { |
| 10236 | 10236 | const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl); |
| 10237 | 10237 | const sym = elf_file.symbol(sym_index); |
| 10238 | try sym.createZigGotEntry(sym_index, elf_file); | |
| 10238 | sym.flags.needs_zig_got = true; | |
| 10239 | 10239 | if (self.bin_file.options.pic) { |
| 10240 | 10240 | const callee_reg: Register = switch (resolved_cc) { |
| 10241 | 10241 | .SysV => callee: { |
| ... | ... | @@ -13103,8 +13103,7 @@ fn genLazySymbolRef( |
| 13103 | 13103 | const sym_index = elf_file.zigObjectPtr().?.getOrCreateMetadataForLazySymbol(elf_file, lazy_sym) catch |err| |
| 13104 | 13104 | return self.fail("{s} creating lazy symbol", .{@errorName(err)}); |
| 13105 | 13105 | const sym = elf_file.symbol(sym_index); |
| 13106 | try sym.createZigGotEntry(sym_index, elf_file); | |
| 13107 | ||
| 13106 | sym.flags.needs_zig_got = true; | |
| 13108 | 13107 | if (self.bin_file.options.pic) { |
| 13109 | 13108 | switch (tag) { |
| 13110 | 13109 | .lea, .call => try self.genSetReg(reg, Type.usize, .{ |
src/arch/x86_64/Emit.zig+7-3| ... | ... | @@ -86,9 +86,13 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 86 | 86 | }), |
| 87 | 87 | .linker_reloc => |data| if (emit.lower.bin_file.cast(link.File.Elf)) |elf_file| { |
| 88 | 88 | const atom = elf_file.symbol(data.atom_index).atom(elf_file).?; |
| 89 | const sym = elf_file.symbol(elf_file.zigObjectPtr().?.symbol(data.sym_index)); | |
| 89 | const sym_index = elf_file.zigObjectPtr().?.symbol(data.sym_index); | |
| 90 | const sym = elf_file.symbol(sym_index); | |
| 91 | if (sym.flags.needs_zig_got and emit.lower.bin_file.options.effectiveOutputMode() != .Obj) { | |
| 92 | _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file); | |
| 93 | } | |
| 90 | 94 | if (emit.lower.bin_file.options.pic) { |
| 91 | const r_type: u32 = if (sym.flags.has_zig_got) | |
| 95 | const r_type: u32 = if (sym.flags.needs_zig_got) | |
| 92 | 96 | link.File.Elf.R_X86_64_ZIG_GOTPCREL |
| 93 | 97 | else if (sym.flags.needs_got) |
| 94 | 98 | std.elf.R_X86_64_GOTPCREL |
| ... | ... | @@ -100,7 +104,7 @@ pub fn emitMir(emit: *Emit) Error!void { |
| 100 | 104 | .r_addend = -4, |
| 101 | 105 | }); |
| 102 | 106 | } else { |
| 103 | const r_type: u32 = if (sym.flags.has_zig_got) | |
| 107 | const r_type: u32 = if (sym.flags.needs_zig_got) | |
| 104 | 108 | link.File.Elf.R_X86_64_ZIG_GOT32 |
| 105 | 109 | else if (sym.flags.needs_got) |
| 106 | 110 | std.elf.R_X86_64_GOT32 |
src/codegen.zig+1-1| ... | ... | @@ -909,7 +909,7 @@ fn genDeclRef( |
| 909 | 909 | } |
| 910 | 910 | const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, decl_index); |
| 911 | 911 | const sym = elf_file.symbol(sym_index); |
| 912 | try sym.createZigGotEntry(sym_index, elf_file); | |
| 912 | sym.flags.needs_zig_got = true; | |
| 913 | 913 | return GenResult.mcv(.{ .load_symbol = sym.esym_index }); |
| 914 | 914 | } else if (bin_file.cast(link.File.MachO)) |macho_file| { |
| 915 | 915 | if (is_extern) { |
src/link/Elf/Symbol.zig+2-5| ... | ... | @@ -169,16 +169,12 @@ const GetOrCreateZigGotEntryResult = struct { |
| 169 | 169 | |
| 170 | 170 | pub fn getOrCreateZigGotEntry(symbol: *Symbol, symbol_index: Index, elf_file: *Elf) !GetOrCreateZigGotEntryResult { |
| 171 | 171 | assert(!elf_file.isObject()); |
| 172 | assert(symbol.flags.needs_zig_got); | |
| 172 | 173 | if (symbol.flags.has_zig_got) return .{ .found_existing = true, .index = symbol.extra(elf_file).?.zig_got }; |
| 173 | 174 | const index = try elf_file.zig_got.addSymbol(symbol_index, elf_file); |
| 174 | 175 | return .{ .found_existing = false, .index = index }; |
| 175 | 176 | } |
| 176 | 177 | |
| 177 | pub fn createZigGotEntry(symbol: *Symbol, symbol_index: Index, elf_file: *Elf) !void { | |
| 178 | if (elf_file.isObject()) return; | |
| 179 | _ = try symbol.getOrCreateZigGotEntry(symbol_index, elf_file); | |
| 180 | } | |
| 181 | ||
| 182 | 178 | pub fn zigGotAddress(symbol: Symbol, elf_file: *Elf) u64 { |
| 183 | 179 | if (!symbol.flags.has_zig_got) return 0; |
| 184 | 180 | const extras = symbol.extra(elf_file).?; |
| ... | ... | @@ -385,6 +381,7 @@ pub const Flags = packed struct { |
| 385 | 381 | has_tlsdesc: bool = false, |
| 386 | 382 | |
| 387 | 383 | /// Whether the symbol contains .zig.got indirection. |
| 384 | needs_zig_got: bool = false, | |
| 388 | 385 | has_zig_got: bool = false, |
| 389 | 386 | }; |
| 390 | 387 |
src/link/Elf/ZigObject.zig+2| ... | ... | @@ -901,6 +901,7 @@ fn updateDeclCode( |
| 901 | 901 | errdefer self.freeDeclMetadata(elf_file, sym_index); |
| 902 | 902 | |
| 903 | 903 | sym.value = atom_ptr.value; |
| 904 | sym.flags.needs_zig_got = true; | |
| 904 | 905 | esym.st_value = atom_ptr.value; |
| 905 | 906 | |
| 906 | 907 | if (!elf_file.isObject()) { |
| ... | ... | @@ -1156,6 +1157,7 @@ fn updateLazySymbol( |
| 1156 | 1157 | errdefer self.freeDeclMetadata(elf_file, symbol_index); |
| 1157 | 1158 | |
| 1158 | 1159 | local_sym.value = atom_ptr.value; |
| 1160 | local_sym.flags.needs_zig_got = true; | |
| 1159 | 1161 | local_esym.st_value = atom_ptr.value; |
| 1160 | 1162 | |
| 1161 | 1163 | if (!elf_file.isObject()) { |