authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 20:58:43+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-21 20:58:43+01:00
log60a8f9b989d64bb6dfbb9e85cd0dd4e1b41750e1
tree5e62c44c20dc747fcbe2b798de5c965150fff8e5
parent775a161794c9486b7866b27d364acea1cb78b6cd

elf: make GOT arch aware when resolving relocs


2 files changed, 11 insertions(+), 18 deletions(-)

src/link/Elf.zig+9
......@@ -5550,6 +5550,15 @@ pub fn comdatGroupOwner(self: *Elf, index: ComdatGroupOwner.Index) *ComdatGroupO
55505550 return &self.comdat_groups_owners.items[index];
55515551}
55525552
5553pub fn gotAddress(self: *Elf) u64 {
5554 const shndx = blk: {
5555 if (self.getTarget().cpu.arch == .x86_64 and self.got_plt_section_index != null)
5556 break :blk self.got_plt_section_index.?;
5557 break :blk if (self.got_section_index) |shndx| shndx else null;
5558 };
5559 return if (shndx) |index| self.shdrs.items[index].sh_addr else 0;
5560}
5561
55535562pub fn tpAddress(self: *Elf) u64 {
55545563 const index = self.phdr_tls_index orelse return 0;
55555564 const phdr = self.phdrs.items[index];
src/link/Elf/Atom.zig+2-18
......@@ -731,15 +731,7 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi
731731 // Address of the target symbol - can be address of the symbol within an atom or address of PLT stub.
732732 const S = @as(i64, @intCast(target.address(.{}, elf_file)));
733733 // Address of the global offset table.
734 const GOT = blk: {
735 const shndx = if (elf_file.got_plt_section_index) |shndx|
736 shndx
737 else if (elf_file.got_section_index) |shndx|
738 shndx
739 else
740 null;
741 break :blk if (shndx) |index| @as(i64, @intCast(elf_file.shdrs.items[index].sh_addr)) else 0;
742 };
734 const GOT = @as(i64, @intCast(elf_file.gotAddress()));
743735 // Address of the .zig.got table entry if any.
744736 const ZIG_GOT = @as(i64, @intCast(target.zigGotAddress(elf_file)));
745737 // 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
924916 // Address of the target symbol - can be address of the symbol within an atom or address of PLT stub.
925917 const S = @as(i64, @intCast(target.address(.{}, elf_file)));
926918 // Address of the global offset table.
927 const GOT = blk: {
928 const shndx = if (elf_file.got_plt_section_index) |shndx|
929 shndx
930 else if (elf_file.got_section_index) |shndx|
931 shndx
932 else
933 null;
934 break :blk if (shndx) |index| @as(i64, @intCast(elf_file.shdrs.items[index].sh_addr)) else 0;
935 };
919 const GOT = @as(i64, @intCast(elf_file.gotAddress()));
936920 // Address of the dynamic thread pointer.
937921 const DTP = @as(i64, @intCast(elf_file.dtpAddress()));
938922