authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-17 11:43:18+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-02-17 11:46:01+01:00
log9542ee9bf87424f89b7ca182944fe825193a5702
treebdad4881b0874730e18b9fb7e46d738f4055eb86
parentace1a69a55dd77a8189b7408b126d9d1ca0066ee

elf: create Zig specific reloc type shared across ISAs


4 files changed, 10 insertions(+), 9 deletions(-)

src/arch/x86_64/Emit.zig+2-2
...@@ -120,7 +120,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -120,7 +120,7 @@ pub fn emitMir(emit: *Emit) Error!void {
120 }120 }
121 if (emit.lower.pic) {121 if (emit.lower.pic) {
122 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)122 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)
123 link.File.Elf.R_X86_64_ZIG_GOTPCREL123 link.File.Elf.R_ZIG_GOTPCREL
124 else if (sym.flags.needs_got)124 else if (sym.flags.needs_got)
125 @intFromEnum(std.elf.R_X86_64.R_X86_64_GOTPCREL)125 @intFromEnum(std.elf.R_X86_64.R_X86_64_GOTPCREL)
126 else126 else
...@@ -140,7 +140,7 @@ pub fn emitMir(emit: *Emit) Error!void {...@@ -140,7 +140,7 @@ pub fn emitMir(emit: *Emit) Error!void {
140 });140 });
141 } else {141 } else {
142 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)142 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)
143 link.File.Elf.R_X86_64_ZIG_GOT32143 link.File.Elf.R_ZIG_GOT32
144 else if (sym.flags.needs_got)144 else if (sym.flags.needs_got)
145 @intFromEnum(std.elf.R_X86_64.R_X86_64_GOT32)145 @intFromEnum(std.elf.R_X86_64.R_X86_64_GOT32)
146 else if (sym.flags.is_tls)146 else if (sym.flags.is_tls)
src/link/Elf.zig+3-2
...@@ -6065,8 +6065,9 @@ const RelaSection = struct {...@@ -6065,8 +6065,9 @@ const RelaSection = struct {
6065};6065};
6066const RelaSectionTable = std.AutoArrayHashMapUnmanaged(u32, RelaSection);6066const RelaSectionTable = std.AutoArrayHashMapUnmanaged(u32, RelaSection);
60676067
6068pub const R_X86_64_ZIG_GOT32: u32 = 0xff00;6068// TODO: add comptime check we don't clobber any reloc for any ISA
6069pub const R_X86_64_ZIG_GOTPCREL: u32 = 0xff01;6069pub const R_ZIG_GOT32: u32 = 0xff00;
6070pub const R_ZIG_GOTPCREL: u32 = 0xff01;
60706071
6071fn defaultEntrySymbolName(cpu_arch: std.Target.Cpu.Arch) []const u8 {6072fn defaultEntrySymbolName(cpu_arch: std.Target.Cpu.Arch) []const u8 {
6072 return switch (cpu_arch) {6073 return switch (cpu_arch) {
src/link/Elf/Atom.zig+4-4
...@@ -968,8 +968,8 @@ const x86_64 = struct {...@@ -968,8 +968,8 @@ const x86_64 = struct {
968968
969 else => |x| switch (@intFromEnum(x)) {969 else => |x| switch (@intFromEnum(x)) {
970 // Zig custom relocations970 // Zig custom relocations
971 Elf.R_X86_64_ZIG_GOT32,971 Elf.R_ZIG_GOT32,
972 Elf.R_X86_64_ZIG_GOTPCREL,972 Elf.R_ZIG_GOTPCREL,
973 => {973 => {
974 assert(symbol.flags.has_zig_got);974 assert(symbol.flags.has_zig_got);
975 },975 },
...@@ -1153,8 +1153,8 @@ const x86_64 = struct {...@@ -1153,8 +1153,8 @@ const x86_64 = struct {
11531153
1154 else => |x| switch (@intFromEnum(x)) {1154 else => |x| switch (@intFromEnum(x)) {
1155 // Zig custom relocations1155 // Zig custom relocations
1156 Elf.R_X86_64_ZIG_GOT32 => try cwriter.writeInt(u32, @as(u32, @intCast(ZIG_GOT + A)), .little),1156 Elf.R_ZIG_GOT32 => try cwriter.writeInt(u32, @as(u32, @intCast(ZIG_GOT + A)), .little),
1157 Elf.R_X86_64_ZIG_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(ZIG_GOT + A - P)), .little),1157 Elf.R_ZIG_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(ZIG_GOT + A - P)), .little),
11581158
1159 else => {},1159 else => {},
1160 },1160 },
src/link/Elf/relocation.zig+1-1
...@@ -55,7 +55,7 @@ const aarch64_relocs = Table(10, elf.R_AARCH64, .{...@@ -55,7 +55,7 @@ const aarch64_relocs = Table(10, elf.R_AARCH64, .{
55 .{ .tlsdesc, .R_AARCH64_TLSDESC },55 .{ .tlsdesc, .R_AARCH64_TLSDESC },
56});56});
5757
58const riscv64_relocs = Table(8, elf.R_RISCV, .{58const riscv64_relocs = Table(9, elf.R_RISCV, .{
59 .{ .abs, .R_RISCV_64 },59 .{ .abs, .R_RISCV_64 },
60 .{ .copy, .R_RISCV_COPY },60 .{ .copy, .R_RISCV_COPY },
61 .{ .rel, .R_RISCV_RELATIVE },61 .{ .rel, .R_RISCV_RELATIVE },