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 {
120120 }
121121 if (emit.lower.pic) {
122122 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)
123 link.File.Elf.R_X86_64_ZIG_GOTPCREL
123 link.File.Elf.R_ZIG_GOTPCREL
124124 else if (sym.flags.needs_got)
125125 @intFromEnum(std.elf.R_X86_64.R_X86_64_GOTPCREL)
126126 else
......@@ -140,7 +140,7 @@ pub fn emitMir(emit: *Emit) Error!void {
140140 });
141141 } else {
142142 const r_type: u32 = if (sym.flags.needs_zig_got and !is_obj_or_static_lib)
143 link.File.Elf.R_X86_64_ZIG_GOT32
143 link.File.Elf.R_ZIG_GOT32
144144 else if (sym.flags.needs_got)
145145 @intFromEnum(std.elf.R_X86_64.R_X86_64_GOT32)
146146 else if (sym.flags.is_tls)
src/link/Elf.zig+3-2
......@@ -6065,8 +6065,9 @@ const RelaSection = struct {
60656065};
60666066const RelaSectionTable = std.AutoArrayHashMapUnmanaged(u32, RelaSection);
60676067
6068pub const R_X86_64_ZIG_GOT32: u32 = 0xff00;
6069pub const R_X86_64_ZIG_GOTPCREL: u32 = 0xff01;
6068// TODO: add comptime check we don't clobber any reloc for any ISA
6069pub const R_ZIG_GOT32: u32 = 0xff00;
6070pub const R_ZIG_GOTPCREL: u32 = 0xff01;
60706071
60716072fn defaultEntrySymbolName(cpu_arch: std.Target.Cpu.Arch) []const u8 {
60726073 return switch (cpu_arch) {
src/link/Elf/Atom.zig+4-4
......@@ -968,8 +968,8 @@ const x86_64 = struct {
968968
969969 else => |x| switch (@intFromEnum(x)) {
970970 // Zig custom relocations
971 Elf.R_X86_64_ZIG_GOT32,
972 Elf.R_X86_64_ZIG_GOTPCREL,
971 Elf.R_ZIG_GOT32,
972 Elf.R_ZIG_GOTPCREL,
973973 => {
974974 assert(symbol.flags.has_zig_got);
975975 },
......@@ -1153,8 +1153,8 @@ const x86_64 = struct {
11531153
11541154 else => |x| switch (@intFromEnum(x)) {
11551155 // Zig custom relocations
1156 Elf.R_X86_64_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),
1156 Elf.R_ZIG_GOT32 => try cwriter.writeInt(u32, @as(u32, @intCast(ZIG_GOT + A)), .little),
1157 Elf.R_ZIG_GOTPCREL => try cwriter.writeInt(i32, @as(i32, @intCast(ZIG_GOT + A - P)), .little),
11581158
11591159 else => {},
11601160 },
src/link/Elf/relocation.zig+1-1
......@@ -55,7 +55,7 @@ const aarch64_relocs = Table(10, elf.R_AARCH64, .{
5555 .{ .tlsdesc, .R_AARCH64_TLSDESC },
5656});
5757
58const riscv64_relocs = Table(8, elf.R_RISCV, .{
58const riscv64_relocs = Table(9, elf.R_RISCV, .{
5959 .{ .abs, .R_RISCV_64 },
6060 .{ .copy, .R_RISCV_COPY },
6161 .{ .rel, .R_RISCV_RELATIVE },