From 542423915466c0e20b0947f745a1de276fbd8b03 Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Sat, 20 Jul 2024 07:43:53 -0400 Subject: [PATCH] dev: add missing x86_64 backend checks --- src/dev.zig | 1 - src/link/Elf/Atom.zig | 12 ++++++++++++ src/link/MachO/Atom.zig | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/dev.zig b/src/dev.zig index 6d99df4aa5..fc518e93b6 100644 --- a/src/dev.zig +++ b/src/dev.zig @@ -23,7 +23,6 @@ pub const Env = enum { sema, /// - sema - /// - jit command on x86_64-linux host /// - `zig build-* -fno-llvm -fno-lld -target x86_64-linux` @"x86_64-linux", diff --git a/src/link/Elf/Atom.zig b/src/link/Elf/Atom.zig index 1c303980c3..53a8ca4b69 100644 --- a/src/link/Elf/Atom.zig +++ b/src/link/Elf/Atom.zig @@ -1113,6 +1113,7 @@ const x86_64 = struct { code: ?[]const u8, it: *RelocsIterator, ) !void { + dev.check(.x86_64_backend); const is_static = elf_file.base.isStatic(); const is_dyn_lib = elf_file.isEffectivelyDynLib(); @@ -1235,6 +1236,7 @@ const x86_64 = struct { code: []u8, stream: anytype, ) (error{ InvalidInstruction, CannotEncode } || RelocError)!void { + dev.check(.x86_64_backend); const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type()); const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow; @@ -1380,6 +1382,7 @@ const x86_64 = struct { code: []u8, stream: anytype, ) !void { + dev.check(.x86_64_backend); _ = code; _ = it; const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type()); @@ -1420,6 +1423,7 @@ const x86_64 = struct { } fn relaxGotpcrelx(code: []u8) !void { + dev.check(.x86_64_backend); const old_inst = disassemble(code) orelse return error.RelaxFailure; const inst = switch (old_inst.encoding.mnemonic) { .call => try Instruction.new(old_inst.prefix, .call, &.{ @@ -1438,6 +1442,7 @@ const x86_64 = struct { } fn relaxRexGotpcrelx(code: []u8) !void { + dev.check(.x86_64_backend); const old_inst = disassemble(code) orelse return error.RelaxFailure; switch (old_inst.encoding.mnemonic) { .mov => { @@ -1456,6 +1461,7 @@ const x86_64 = struct { elf_file: *Elf, stream: anytype, ) !void { + dev.check(.x86_64_backend); assert(rels.len == 2); const writer = stream.writer(); const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type()); @@ -1495,6 +1501,7 @@ const x86_64 = struct { elf_file: *Elf, stream: anytype, ) !void { + dev.check(.x86_64_backend); assert(rels.len == 2); const writer = stream.writer(); const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type()); @@ -1543,6 +1550,7 @@ const x86_64 = struct { } fn canRelaxGotTpOff(code: []const u8) bool { + dev.check(.x86_64_backend); const old_inst = disassemble(code) orelse return false; switch (old_inst.encoding.mnemonic) { .mov => if (Instruction.new(old_inst.prefix, .mov, &.{ @@ -1558,6 +1566,7 @@ const x86_64 = struct { } fn relaxGotTpOff(code: []u8) void { + dev.check(.x86_64_backend); const old_inst = disassemble(code) orelse unreachable; switch (old_inst.encoding.mnemonic) { .mov => { @@ -1574,6 +1583,7 @@ const x86_64 = struct { } fn relaxGotPcTlsDesc(code: []u8) !void { + dev.check(.x86_64_backend); const old_inst = disassemble(code) orelse return error.RelaxFailure; switch (old_inst.encoding.mnemonic) { .lea => { @@ -1596,6 +1606,7 @@ const x86_64 = struct { elf_file: *Elf, stream: anytype, ) !void { + dev.check(.x86_64_backend); assert(rels.len == 2); const writer = stream.writer(); const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type()); @@ -2312,3 +2323,4 @@ const File = @import("file.zig").File; const Object = @import("Object.zig"); const Symbol = @import("Symbol.zig"); const Thunk = @import("thunks.zig").Thunk; +const dev = @import("../../dev.zig"); diff --git a/src/link/MachO/Atom.zig b/src/link/MachO/Atom.zig index 64f5723371..f82bf99700 100644 --- a/src/link/MachO/Atom.zig +++ b/src/link/MachO/Atom.zig @@ -897,6 +897,7 @@ fn resolveRelocInner( const x86_64 = struct { fn relaxGotLoad(self: Atom, code: []u8, rel: Relocation, macho_file: *MachO) ResolveError!void { + dev.check(.x86_64_backend); const old_inst = disassemble(code) orelse return error.RelaxFail; switch (old_inst.encoding.mnemonic) { .mov => { @@ -920,6 +921,7 @@ const x86_64 = struct { } fn relaxTlv(code: []u8) error{RelaxFail}!void { + dev.check(.x86_64_backend); const old_inst = disassemble(code) orelse return error.RelaxFail; switch (old_inst.encoding.mnemonic) { .mov => { @@ -1214,3 +1216,4 @@ const Relocation = @import("Relocation.zig"); const Symbol = @import("Symbol.zig"); const Thunk = @import("thunks.zig").Thunk; const UnwindInfo = @import("UnwindInfo.zig"); +const dev = @import("../../dev.zig");