diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-11-02 12:46:37 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-11-04 09:11:29 +0100 |
| commit | ccb2afacc00264897cc474befc13f36239c91b03 (patch) | |
| tree | 9721a74a2212395012b11ea5224ee6bc502c9de8 /src/arch | |
| parent | 5affd29b4799712d4cbf00231ed52de4034b345d (diff) | |
| download | zig-ccb2afacc00264897cc474befc13f36239c91b03.tar.gz zig-ccb2afacc00264897cc474befc13f36239c91b03.zip | |
elf: postpone creation of .got.zig entry until code emit
Diffstat (limited to 'src/arch')
| -rw-r--r-- | src/arch/x86_64/CodeGen.zig | 5 | ||||
| -rw-r--r-- | src/arch/x86_64/Emit.zig | 10 |
2 files changed, 9 insertions, 6 deletions
diff --git a/src/arch/x86_64/CodeGen.zig b/src/arch/x86_64/CodeGen.zig index b65a704351..f842033484 100644 --- a/src/arch/x86_64/CodeGen.zig +++ b/src/arch/x86_64/CodeGen.zig @@ -10235,7 +10235,7 @@ fn genCall(self: *Self, info: union(enum) { if (self.bin_file.cast(link.File.Elf)) |elf_file| { const sym_index = try elf_file.zigObjectPtr().?.getOrCreateMetadataForDecl(elf_file, func.owner_decl); const sym = elf_file.symbol(sym_index); - try sym.createZigGotEntry(sym_index, elf_file); + sym.flags.needs_zig_got = true; if (self.bin_file.options.pic) { const callee_reg: Register = switch (resolved_cc) { .SysV => callee: { @@ -13103,8 +13103,7 @@ fn genLazySymbolRef( const sym_index = elf_file.zigObjectPtr().?.getOrCreateMetadataForLazySymbol(elf_file, lazy_sym) catch |err| return self.fail("{s} creating lazy symbol", .{@errorName(err)}); const sym = elf_file.symbol(sym_index); - try sym.createZigGotEntry(sym_index, elf_file); - + sym.flags.needs_zig_got = true; if (self.bin_file.options.pic) { switch (tag) { .lea, .call => try self.genSetReg(reg, Type.usize, .{ diff --git a/src/arch/x86_64/Emit.zig b/src/arch/x86_64/Emit.zig index 36f4b05a6e..c2f7d8c436 100644 --- a/src/arch/x86_64/Emit.zig +++ b/src/arch/x86_64/Emit.zig @@ -86,9 +86,13 @@ pub fn emitMir(emit: *Emit) Error!void { }), .linker_reloc => |data| if (emit.lower.bin_file.cast(link.File.Elf)) |elf_file| { const atom = elf_file.symbol(data.atom_index).atom(elf_file).?; - const sym = elf_file.symbol(elf_file.zigObjectPtr().?.symbol(data.sym_index)); + const sym_index = elf_file.zigObjectPtr().?.symbol(data.sym_index); + const sym = elf_file.symbol(sym_index); + if (sym.flags.needs_zig_got and emit.lower.bin_file.options.effectiveOutputMode() != .Obj) { + _ = try sym.getOrCreateZigGotEntry(sym_index, elf_file); + } if (emit.lower.bin_file.options.pic) { - const r_type: u32 = if (sym.flags.has_zig_got) + const r_type: u32 = if (sym.flags.needs_zig_got) link.File.Elf.R_X86_64_ZIG_GOTPCREL else if (sym.flags.needs_got) std.elf.R_X86_64_GOTPCREL @@ -100,7 +104,7 @@ pub fn emitMir(emit: *Emit) Error!void { .r_addend = -4, }); } else { - const r_type: u32 = if (sym.flags.has_zig_got) + const r_type: u32 = if (sym.flags.needs_zig_got) link.File.Elf.R_X86_64_ZIG_GOT32 else if (sym.flags.needs_got) std.elf.R_X86_64_GOT32 |
