diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-02-21 20:58:43 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-02-21 20:58:43 +0100 |
| commit | 60a8f9b989d64bb6dfbb9e85cd0dd4e1b41750e1 (patch) | |
| tree | 5e62c44c20dc747fcbe2b798de5c965150fff8e5 | |
| parent | 775a161794c9486b7866b27d364acea1cb78b6cd (diff) | |
| download | zig-60a8f9b989d64bb6dfbb9e85cd0dd4e1b41750e1.tar.gz zig-60a8f9b989d64bb6dfbb9e85cd0dd4e1b41750e1.zip | |
elf: make GOT arch aware when resolving relocs
| -rw-r--r-- | src/link/Elf.zig | 9 | ||||
| -rw-r--r-- | src/link/Elf/Atom.zig | 20 |
2 files changed, 11 insertions, 18 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 7356429312..cd795eb345 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -5550,6 +5550,15 @@ pub fn comdatGroupOwner(self: *Elf, index: ComdatGroupOwner.Index) *ComdatGroupO return &self.comdat_groups_owners.items[index]; } +pub fn gotAddress(self: *Elf) u64 { + const shndx = blk: { + if (self.getTarget().cpu.arch == .x86_64 and self.got_plt_section_index != null) + break :blk self.got_plt_section_index.?; + break :blk if (self.got_section_index) |shndx| shndx else null; + }; + return if (shndx) |index| self.shdrs.items[index].sh_addr else 0; +} + pub fn tpAddress(self: *Elf) u64 { const index = self.phdr_tls_index orelse return 0; const phdr = self.phdrs.items[index]; diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig index dc5147e9c4..05ecf24bd6 100644 --- a/src/link/Elf/Atom.zig +++ b/src/link/Elf/Atom.zig @@ -731,15 +731,7 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi // Address of the target symbol - can be address of the symbol within an atom or address of PLT stub. const S = @as(i64, @intCast(target.address(.{}, elf_file))); // Address of the global offset table. - const GOT = blk: { - const shndx = if (elf_file.got_plt_section_index) |shndx| - shndx - else if (elf_file.got_section_index) |shndx| - shndx - else - null; - break :blk if (shndx) |index| @as(i64, @intCast(elf_file.shdrs.items[index].sh_addr)) else 0; - }; + const GOT = @as(i64, @intCast(elf_file.gotAddress())); // Address of the .zig.got table entry if any. const ZIG_GOT = @as(i64, @intCast(target.zigGotAddress(elf_file))); // Relative offset to the start of the global offset table. @@ -924,15 +916,7 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any // Address of the target symbol - can be address of the symbol within an atom or address of PLT stub. const S = @as(i64, @intCast(target.address(.{}, elf_file))); // Address of the global offset table. - const GOT = blk: { - const shndx = if (elf_file.got_plt_section_index) |shndx| - shndx - else if (elf_file.got_section_index) |shndx| - shndx - else - null; - break :blk if (shndx) |index| @as(i64, @intCast(elf_file.shdrs.items[index].sh_addr)) else 0; - }; + const GOT = @as(i64, @intCast(elf_file.gotAddress())); // Address of the dynamic thread pointer. const DTP = @as(i64, @intCast(elf_file.dtpAddress())); |
