authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-07-20 07:43:53-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-07-20 07:43:53-04:00
log542423915466c0e20b0947f745a1de276fbd8b03
tree1399f8c2a1d523788b85c28e4230729b7d1380e3
parent2e65244cae7e4365ecf3aa6857b84451272316a1

dev: add missing x86_64 backend checks


3 files changed, 15 insertions(+), 1 deletions(-)

src/dev.zig-1
...@@ -23,7 +23,6 @@ pub const Env = enum {...@@ -23,7 +23,6 @@ pub const Env = enum {
23 sema,23 sema,
2424
25 /// - sema25 /// - sema
26 /// - jit command on x86_64-linux host
27 /// - `zig build-* -fno-llvm -fno-lld -target x86_64-linux`26 /// - `zig build-* -fno-llvm -fno-lld -target x86_64-linux`
28 @"x86_64-linux",27 @"x86_64-linux",
2928
src/link/Elf/Atom.zig+12
...@@ -1113,6 +1113,7 @@ const x86_64 = struct {...@@ -1113,6 +1113,7 @@ const x86_64 = struct {
1113 code: ?[]const u8,1113 code: ?[]const u8,
1114 it: *RelocsIterator,1114 it: *RelocsIterator,
1115 ) !void {1115 ) !void {
1116 dev.check(.x86_64_backend);
1116 const is_static = elf_file.base.isStatic();1117 const is_static = elf_file.base.isStatic();
1117 const is_dyn_lib = elf_file.isEffectivelyDynLib();1118 const is_dyn_lib = elf_file.isEffectivelyDynLib();
11181119
...@@ -1235,6 +1236,7 @@ const x86_64 = struct {...@@ -1235,6 +1236,7 @@ const x86_64 = struct {
1235 code: []u8,1236 code: []u8,
1236 stream: anytype,1237 stream: anytype,
1237 ) (error{ InvalidInstruction, CannotEncode } || RelocError)!void {1238 ) (error{ InvalidInstruction, CannotEncode } || RelocError)!void {
1239 dev.check(.x86_64_backend);
1238 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());1240 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
1239 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;1241 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;
12401242
...@@ -1380,6 +1382,7 @@ const x86_64 = struct {...@@ -1380,6 +1382,7 @@ const x86_64 = struct {
1380 code: []u8,1382 code: []u8,
1381 stream: anytype,1383 stream: anytype,
1382 ) !void {1384 ) !void {
1385 dev.check(.x86_64_backend);
1383 _ = code;1386 _ = code;
1384 _ = it;1387 _ = it;
1385 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());1388 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
...@@ -1420,6 +1423,7 @@ const x86_64 = struct {...@@ -1420,6 +1423,7 @@ const x86_64 = struct {
1420 }1423 }
14211424
1422 fn relaxGotpcrelx(code: []u8) !void {1425 fn relaxGotpcrelx(code: []u8) !void {
1426 dev.check(.x86_64_backend);
1423 const old_inst = disassemble(code) orelse return error.RelaxFailure;1427 const old_inst = disassemble(code) orelse return error.RelaxFailure;
1424 const inst = switch (old_inst.encoding.mnemonic) {1428 const inst = switch (old_inst.encoding.mnemonic) {
1425 .call => try Instruction.new(old_inst.prefix, .call, &.{1429 .call => try Instruction.new(old_inst.prefix, .call, &.{
...@@ -1438,6 +1442,7 @@ const x86_64 = struct {...@@ -1438,6 +1442,7 @@ const x86_64 = struct {
1438 }1442 }
14391443
1440 fn relaxRexGotpcrelx(code: []u8) !void {1444 fn relaxRexGotpcrelx(code: []u8) !void {
1445 dev.check(.x86_64_backend);
1441 const old_inst = disassemble(code) orelse return error.RelaxFailure;1446 const old_inst = disassemble(code) orelse return error.RelaxFailure;
1442 switch (old_inst.encoding.mnemonic) {1447 switch (old_inst.encoding.mnemonic) {
1443 .mov => {1448 .mov => {
...@@ -1456,6 +1461,7 @@ const x86_64 = struct {...@@ -1456,6 +1461,7 @@ const x86_64 = struct {
1456 elf_file: *Elf,1461 elf_file: *Elf,
1457 stream: anytype,1462 stream: anytype,
1458 ) !void {1463 ) !void {
1464 dev.check(.x86_64_backend);
1459 assert(rels.len == 2);1465 assert(rels.len == 2);
1460 const writer = stream.writer();1466 const writer = stream.writer();
1461 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());1467 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());
...@@ -1495,6 +1501,7 @@ const x86_64 = struct {...@@ -1495,6 +1501,7 @@ const x86_64 = struct {
1495 elf_file: *Elf,1501 elf_file: *Elf,
1496 stream: anytype,1502 stream: anytype,
1497 ) !void {1503 ) !void {
1504 dev.check(.x86_64_backend);
1498 assert(rels.len == 2);1505 assert(rels.len == 2);
1499 const writer = stream.writer();1506 const writer = stream.writer();
1500 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());1507 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());
...@@ -1543,6 +1550,7 @@ const x86_64 = struct {...@@ -1543,6 +1550,7 @@ const x86_64 = struct {
1543 }1550 }
15441551
1545 fn canRelaxGotTpOff(code: []const u8) bool {1552 fn canRelaxGotTpOff(code: []const u8) bool {
1553 dev.check(.x86_64_backend);
1546 const old_inst = disassemble(code) orelse return false;1554 const old_inst = disassemble(code) orelse return false;
1547 switch (old_inst.encoding.mnemonic) {1555 switch (old_inst.encoding.mnemonic) {
1548 .mov => if (Instruction.new(old_inst.prefix, .mov, &.{1556 .mov => if (Instruction.new(old_inst.prefix, .mov, &.{
...@@ -1558,6 +1566,7 @@ const x86_64 = struct {...@@ -1558,6 +1566,7 @@ const x86_64 = struct {
1558 }1566 }
15591567
1560 fn relaxGotTpOff(code: []u8) void {1568 fn relaxGotTpOff(code: []u8) void {
1569 dev.check(.x86_64_backend);
1561 const old_inst = disassemble(code) orelse unreachable;1570 const old_inst = disassemble(code) orelse unreachable;
1562 switch (old_inst.encoding.mnemonic) {1571 switch (old_inst.encoding.mnemonic) {
1563 .mov => {1572 .mov => {
...@@ -1574,6 +1583,7 @@ const x86_64 = struct {...@@ -1574,6 +1583,7 @@ const x86_64 = struct {
1574 }1583 }
15751584
1576 fn relaxGotPcTlsDesc(code: []u8) !void {1585 fn relaxGotPcTlsDesc(code: []u8) !void {
1586 dev.check(.x86_64_backend);
1577 const old_inst = disassemble(code) orelse return error.RelaxFailure;1587 const old_inst = disassemble(code) orelse return error.RelaxFailure;
1578 switch (old_inst.encoding.mnemonic) {1588 switch (old_inst.encoding.mnemonic) {
1579 .lea => {1589 .lea => {
...@@ -1596,6 +1606,7 @@ const x86_64 = struct {...@@ -1596,6 +1606,7 @@ const x86_64 = struct {
1596 elf_file: *Elf,1606 elf_file: *Elf,
1597 stream: anytype,1607 stream: anytype,
1598 ) !void {1608 ) !void {
1609 dev.check(.x86_64_backend);
1599 assert(rels.len == 2);1610 assert(rels.len == 2);
1600 const writer = stream.writer();1611 const writer = stream.writer();
1601 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());1612 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());
...@@ -2312,3 +2323,4 @@ const File = @import("file.zig").File;...@@ -2312,3 +2323,4 @@ const File = @import("file.zig").File;
2312const Object = @import("Object.zig");2323const Object = @import("Object.zig");
2313const Symbol = @import("Symbol.zig");2324const Symbol = @import("Symbol.zig");
2314const Thunk = @import("thunks.zig").Thunk;2325const Thunk = @import("thunks.zig").Thunk;
2326const dev = @import("../../dev.zig");
src/link/MachO/Atom.zig+3
...@@ -897,6 +897,7 @@ fn resolveRelocInner(...@@ -897,6 +897,7 @@ fn resolveRelocInner(
897897
898const x86_64 = struct {898const x86_64 = struct {
899 fn relaxGotLoad(self: Atom, code: []u8, rel: Relocation, macho_file: *MachO) ResolveError!void {899 fn relaxGotLoad(self: Atom, code: []u8, rel: Relocation, macho_file: *MachO) ResolveError!void {
900 dev.check(.x86_64_backend);
900 const old_inst = disassemble(code) orelse return error.RelaxFail;901 const old_inst = disassemble(code) orelse return error.RelaxFail;
901 switch (old_inst.encoding.mnemonic) {902 switch (old_inst.encoding.mnemonic) {
902 .mov => {903 .mov => {
...@@ -920,6 +921,7 @@ const x86_64 = struct {...@@ -920,6 +921,7 @@ const x86_64 = struct {
920 }921 }
921922
922 fn relaxTlv(code: []u8) error{RelaxFail}!void {923 fn relaxTlv(code: []u8) error{RelaxFail}!void {
924 dev.check(.x86_64_backend);
923 const old_inst = disassemble(code) orelse return error.RelaxFail;925 const old_inst = disassemble(code) orelse return error.RelaxFail;
924 switch (old_inst.encoding.mnemonic) {926 switch (old_inst.encoding.mnemonic) {
925 .mov => {927 .mov => {
...@@ -1214,3 +1216,4 @@ const Relocation = @import("Relocation.zig");...@@ -1214,3 +1216,4 @@ const Relocation = @import("Relocation.zig");
1214const Symbol = @import("Symbol.zig");1216const Symbol = @import("Symbol.zig");
1215const Thunk = @import("thunks.zig").Thunk;1217const Thunk = @import("thunks.zig").Thunk;
1216const UnwindInfo = @import("UnwindInfo.zig");1218const UnwindInfo = @import("UnwindInfo.zig");
1219const dev = @import("../../dev.zig");