| ... | @@ -750,8 +750,6 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi | ... | @@ -750,8 +750,6 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi |
| 750 | const S = target.address(.{}, elf_file); | 750 | const S = target.address(.{}, elf_file); |
| 751 | // Address of the global offset table. | 751 | // Address of the global offset table. |
| 752 | const GOT = elf_file.gotAddress(); | 752 | const GOT = elf_file.gotAddress(); |
| 753 | // Address of the zig jump table entry if any. | | |
| 754 | const ZJT = target.zigJumpTableAddress(elf_file); | | |
| 755 | // Relative offset to the start of the global offset table. | 753 | // Relative offset to the start of the global offset table. |
| 756 | const G = target.gotAddress(elf_file) - GOT; | 754 | const G = target.gotAddress(elf_file) - GOT; |
| 757 | // // Address of the thread pointer. | 755 | // // Address of the thread pointer. |
| ... | @@ -759,19 +757,18 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi | ... | @@ -759,19 +757,18 @@ pub fn resolveRelocsAlloc(self: Atom, elf_file: *Elf, code: []u8) RelocError!voi |
| 759 | // Address of the dynamic thread pointer. | 757 | // Address of the dynamic thread pointer. |
| 760 | const DTP = elf_file.dtpAddress(); | 758 | const DTP = elf_file.dtpAddress(); |
| 761 | | 759 | |
| 762 | relocs_log.debug(" {s}: {x}: [{x} => {x}] GOT({x}) ZJT({x}) ({s})", .{ | 760 | relocs_log.debug(" {s}: {x}: [{x} => {x}] GOT({x}) ({s})", .{ |
| 763 | relocation.fmtRelocType(rel.r_type(), cpu_arch), | 761 | relocation.fmtRelocType(rel.r_type(), cpu_arch), |
| 764 | r_offset, | 762 | r_offset, |
| 765 | P, | 763 | P, |
| 766 | S + A, | 764 | S + A, |
| 767 | G + GOT + A, | 765 | G + GOT + A, |
| 768 | ZJT + A, | | |
| 769 | target.name(elf_file), | 766 | target.name(elf_file), |
| 770 | }); | 767 | }); |
| 771 | | 768 | |
| 772 | try stream.seekTo(r_offset); | 769 | try stream.seekTo(r_offset); |
| 773 | | 770 | |
| 774 | const args = ResolveArgs{ P, A, S, GOT, G, TP, DTP, ZJT }; | 771 | const args = ResolveArgs{ P, A, S, GOT, G, TP, DTP }; |
| 775 | | 772 | |
| 776 | switch (cpu_arch) { | 773 | switch (cpu_arch) { |
| 777 | .x86_64 => x86_64.resolveRelocAlloc(self, elf_file, rel, target, args, &it, code, &stream) catch |err| switch (err) { | 774 | .x86_64 => x86_64.resolveRelocAlloc(self, elf_file, rel, target, args, &it, code, &stream) catch |err| switch (err) { |
| ... | @@ -956,7 +953,7 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any | ... | @@ -956,7 +953,7 @@ pub fn resolveRelocsNonAlloc(self: Atom, elf_file: *Elf, code: []u8, undefs: any |
| 956 | // Address of the dynamic thread pointer. | 953 | // Address of the dynamic thread pointer. |
| 957 | const DTP = elf_file.dtpAddress(); | 954 | const DTP = elf_file.dtpAddress(); |
| 958 | | 955 | |
| 959 | const args = ResolveArgs{ P, A, S, GOT, 0, 0, DTP, 0 }; | 956 | const args = ResolveArgs{ P, A, S, GOT, 0, 0, DTP }; |
| 960 | | 957 | |
| 961 | relocs_log.debug(" {}: {x}: [{x} => {x}] ({s})", .{ | 958 | relocs_log.debug(" {}: {x}: [{x} => {x}] ({s})", .{ |
| 962 | relocation.fmtRelocType(rel.r_type(), cpu_arch), | 959 | relocation.fmtRelocType(rel.r_type(), cpu_arch), |
| ... | @@ -1200,7 +1197,7 @@ const x86_64 = struct { | ... | @@ -1200,7 +1197,7 @@ const x86_64 = struct { |
| 1200 | | 1197 | |
| 1201 | const cwriter = stream.writer(); | 1198 | const cwriter = stream.writer(); |
| 1202 | | 1199 | |
| 1203 | const P, const A, const S, const GOT, const G, const TP, const DTP, const ZJT = args; | 1200 | const P, const A, const S, const GOT, const G, const TP, const DTP = args; |
| 1204 | | 1201 | |
| 1205 | switch (r_type) { | 1202 | switch (r_type) { |
| 1206 | .NONE => unreachable, | 1203 | .NONE => unreachable, |
| ... | @@ -1215,10 +1212,7 @@ const x86_64 = struct { | ... | @@ -1215,10 +1212,7 @@ const x86_64 = struct { |
| 1215 | ); | 1212 | ); |
| 1216 | }, | 1213 | }, |
| 1217 | | 1214 | |
| 1218 | .PLT32 => { | 1215 | .PLT32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little), |
| 1219 | const S_ = if (target.flags.zig_jump_table) ZJT else S; | | |
| 1220 | try cwriter.writeInt(i32, @as(i32, @intCast(S_ + A - P)), .little); | | |
| 1221 | }, | | |
| 1222 | .PC32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little), | 1216 | .PC32 => try cwriter.writeInt(i32, @as(i32, @intCast(S + A - P)), .little), |
| 1223 | | 1217 | |
| 1224 | .GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little), | 1218 | .GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little), |
| ... | @@ -1243,10 +1237,7 @@ const x86_64 = struct { | ... | @@ -1243,10 +1237,7 @@ const x86_64 = struct { |
| 1243 | try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little); | 1237 | try cwriter.writeInt(i32, @as(i32, @intCast(G + GOT + A - P)), .little); |
| 1244 | }, | 1238 | }, |
| 1245 | | 1239 | |
| 1246 | .@"32" => { | 1240 | .@"32" => try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S + A)))), .little), |
| 1247 | const S_ = if (target.flags.zig_jump_table) ZJT else S; | | |
| 1248 | try cwriter.writeInt(u32, @as(u32, @truncate(@as(u64, @intCast(S_ + A)))), .little); | | |
| 1249 | }, | | |
| 1250 | .@"32S" => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .little), | 1241 | .@"32S" => try cwriter.writeInt(i32, @as(i32, @truncate(S + A)), .little), |
| 1251 | | 1242 | |
| 1252 | .TPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - TP)), .little), | 1243 | .TPOFF32 => try cwriter.writeInt(i32, @as(i32, @truncate(S + A - TP)), .little), |
| ... | @@ -1345,7 +1336,7 @@ const x86_64 = struct { | ... | @@ -1345,7 +1336,7 @@ const x86_64 = struct { |
| 1345 | const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type()); | 1336 | const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type()); |
| 1346 | const cwriter = stream.writer(); | 1337 | const cwriter = stream.writer(); |
| 1347 | | 1338 | |
| 1348 | _, const A, const S, const GOT, _, _, const DTP, _ = args; | 1339 | _, const A, const S, const GOT, _, _, const DTP = args; |
| 1349 | | 1340 | |
| 1350 | switch (r_type) { | 1341 | switch (r_type) { |
| 1351 | .NONE => unreachable, | 1342 | .NONE => unreachable, |
| ... | @@ -1728,9 +1719,8 @@ const aarch64 = struct { | ... | @@ -1728,9 +1719,8 @@ const aarch64 = struct { |
| 1728 | const code = code_buffer[r_offset..][0..4]; | 1719 | const code = code_buffer[r_offset..][0..4]; |
| 1729 | const file_ptr = atom.file(elf_file).?; | 1720 | const file_ptr = atom.file(elf_file).?; |
| 1730 | | 1721 | |
| 1731 | const P, const A, const S, const GOT, const G, const TP, const DTP, const ZJT = args; | 1722 | const P, const A, const S, const GOT, const G, const TP, const DTP = args; |
| 1732 | _ = DTP; | 1723 | _ = DTP; |
| 1733 | _ = ZJT; | | |
| 1734 | | 1724 | |
| 1735 | switch (r_type) { | 1725 | switch (r_type) { |
| 1736 | .NONE => unreachable, | 1726 | .NONE => unreachable, |
| ... | @@ -1932,7 +1922,7 @@ const aarch64 = struct { | ... | @@ -1932,7 +1922,7 @@ const aarch64 = struct { |
| 1932 | const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type()); | 1922 | const r_type: elf.R_AARCH64 = @enumFromInt(rel.r_type()); |
| 1933 | const cwriter = stream.writer(); | 1923 | const cwriter = stream.writer(); |
| 1934 | | 1924 | |
| 1935 | _, const A, const S, _, _, _, _, _ = args; | 1925 | _, const A, const S, _, _, _, _ = args; |
| 1936 | | 1926 | |
| 1937 | switch (r_type) { | 1927 | switch (r_type) { |
| 1938 | .NONE => unreachable, | 1928 | .NONE => unreachable, |
| ... | @@ -2012,10 +2002,9 @@ const riscv = struct { | ... | @@ -2012,10 +2002,9 @@ const riscv = struct { |
| 2012 | const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow; | 2002 | const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow; |
| 2013 | const cwriter = stream.writer(); | 2003 | const cwriter = stream.writer(); |
| 2014 | | 2004 | |
| 2015 | const P, const A, const S, const GOT, const G, const TP, const DTP, const ZJT = args; | 2005 | const P, const A, const S, const GOT, const G, const TP, const DTP = args; |
| 2016 | _ = TP; | 2006 | _ = TP; |
| 2017 | _ = DTP; | 2007 | _ = DTP; |
| 2018 | _ = ZJT; | | |
| 2019 | | 2008 | |
| 2020 | switch (r_type) { | 2009 | switch (r_type) { |
| 2021 | .NONE => unreachable, | 2010 | .NONE => unreachable, |
| ... | @@ -2167,7 +2156,7 @@ const riscv = struct { | ... | @@ -2167,7 +2156,7 @@ const riscv = struct { |
| 2167 | const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow; | 2156 | const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow; |
| 2168 | const cwriter = stream.writer(); | 2157 | const cwriter = stream.writer(); |
| 2169 | | 2158 | |
| 2170 | _, const A, const S, const GOT, _, _, const DTP, _ = args; | 2159 | _, const A, const S, const GOT, _, _, const DTP = args; |
| 2171 | _ = GOT; | 2160 | _ = GOT; |
| 2172 | _ = DTP; | 2161 | _ = DTP; |
| 2173 | | 2162 | |
| ... | @@ -2203,7 +2192,7 @@ const riscv = struct { | ... | @@ -2203,7 +2192,7 @@ const riscv = struct { |
| 2203 | const riscv_util = @import("../riscv.zig"); | 2192 | const riscv_util = @import("../riscv.zig"); |
| 2204 | }; | 2193 | }; |
| 2205 | | 2194 | |
| 2206 | const ResolveArgs = struct { i64, i64, i64, i64, i64, i64, i64, i64 }; | 2195 | const ResolveArgs = struct { i64, i64, i64, i64, i64, i64, i64 }; |
| 2207 | | 2196 | |
| 2208 | const RelocError = error{ | 2197 | const RelocError = error{ |
| 2209 | Overflow, | 2198 | Overflow, |