authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-02 07:38:17-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-09-03 12:59:38-04:00
logbac57b3d15b84b1e4d5365acde3a78d98f439de3
treef6ebfb619bec8703852c9580e44e9ec9d1437f38
parentbe38eff2c0723d995df56c97bc582c8403c6803d

dev: fix some missing checks


28 files changed, 269 insertions(+), 187 deletions(-)

src/Compilation.zig+1
...@@ -2384,6 +2384,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,...@@ -2384,6 +2384,7 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic,
2384 comp.verbose_llvm_bc != null))2384 comp.verbose_llvm_bc != null))
2385 {2385 {
2386 if (opt_zcu) |zcu| {2386 if (opt_zcu) |zcu| {
2387 dev.check(.llvm_backend);
2387 zcu.llvm_object = try LlvmObject.create(arena, zcu);2388 zcu.llvm_object = try LlvmObject.create(arena, zcu);
2388 }2389 }
2389 }2390 }
src/Zcu.zig+99-62
...@@ -4572,13 +4572,17 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.lang.CallingConvention) union(enum)...@@ -4572,13 +4572,17 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.lang.CallingConvention) union(enum)
4572 if (allowed_arch == target.cpu.arch) break;4572 if (allowed_arch == target.cpu.arch) break;
4573 } else return .{ .bad_arch = cc.archs() },4573 } else return .{ .bad_arch = cc.archs() },
4574 }4574 }
4575 const backend_ok = switch (backend) {4575 const backend_ok = ok: switch (backend) {
4576 .stage1 => unreachable,4576 .stage1 => unreachable,
4577 .other => unreachable,4577 .other => unreachable,
4578 _ => unreachable,4578 _ => unreachable,
45794579
4580 .stage2_llvm => @import("codegen/llvm.zig").toLlvmCallConv(cc, target) != null,4580 .stage2_llvm => {
4581 .stage2_c => ok: {4581 dev.check(.llvm_backend);
4582 break :ok @import("codegen/llvm.zig").toLlvmCallConv(cc, target) != null;
4583 },
4584 .stage2_c => {
4585 dev.check(.c_backend);
4582 if (target.cCallingConvention()) |default_c| {4586 if (target.cCallingConvention()) |default_c| {
4583 if (cc.eql(default_c)) {4587 if (cc.eql(default_c)) {
4584 break :ok true;4588 break :ok true;
...@@ -4636,74 +4640,107 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.lang.CallingConvention) union(enum)...@@ -4636,74 +4640,107 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.lang.CallingConvention) union(enum)
4636 else => false,4640 else => false,
4637 };4641 };
4638 },4642 },
4639 .stage2_wasm => switch (cc) {4643 .stage2_wasm => {
4640 .wasm_mvp => |opts| opts.incoming_stack_alignment == null,4644 dev.check(.wasm_backend);
4641 else => false,4645 break :ok switch (cc) {
4642 },4646 .wasm_mvp => |opts| opts.incoming_stack_alignment == null,
4643 .stage2_arm => switch (cc) {4647 else => false,
4644 .arm_aapcs => |opts| opts.incoming_stack_alignment == null,4648 };
4645 .naked => true,
4646 else => false,
4647 },
4648 .stage2_x86_64 => switch (cc) {
4649 .x86_64_sysv, .x86_64_win, .naked => true, // incoming stack alignment supported
4650 else => false,
4651 },4649 },
4652 .stage2_aarch64 => switch (cc) {4650 .stage2_arm => {
4653 .aarch64_aapcs, .aarch64_aapcs_darwin, .naked => true,4651 dev.check(.arm_backend);
4654 else => false,4652 break :ok switch (cc) {
4653 .arm_aapcs => |opts| opts.incoming_stack_alignment == null,
4654 .naked => true,
4655 else => false,
4656 };
4655 },4657 },
4656 .stage2_x86 => switch (cc) {4658 .stage2_x86_64 => {
4657 .x86_sysv,4659 dev.check(.x86_64_backend);
4658 .x86_win,4660 break :ok switch (cc) {
4659 .x86_mingw,4661 .x86_64_sysv, .x86_64_win, .naked => true, // incoming stack alignment supported
4660 => |opts| opts.incoming_stack_alignment == null and opts.register_params == 0,4662 else => false,
4661 .naked => true,4663 };
4662 else => false,
4663 },4664 },
4664 .stage2_powerpc => switch (target.cpu.arch) {4665 .stage2_aarch64 => {
4665 .powerpc, .powerpcle => switch (cc) {4666 dev.check(.aarch64_backend);
4666 .powerpc_sysv,4667 break :ok switch (cc) {
4667 .powerpc_sysv_altivec,4668 .aarch64_aapcs, .aarch64_aapcs_darwin, .naked => true,
4668 .powerpc_aix,
4669 .powerpc_aix_altivec,
4670 .naked,
4671 => true,
4672 else => false,4669 else => false,
4673 },4670 };
4674 .powerpc64, .powerpc64le => switch (cc) {4671 },
4675 .powerpc64_elf,4672 .stage2_x86 => {
4676 .powerpc64_elf_altivec,4673 dev.check(.x86_backend);
4677 .powerpc64_elf_v2,4674 break :ok switch (cc) {
4678 .naked,4675 .x86_sysv,
4679 => true,4676 .x86_win,
4677 .x86_mingw,
4678 => |opts| opts.incoming_stack_alignment == null and opts.register_params == 0,
4679 .naked => true,
4680 else => false,4680 else => false,
4681 },4681 };
4682 else => unreachable,
4683 },4682 },
4684 .stage2_riscv64 => switch (cc) {4683 .stage2_powerpc => {
4685 .riscv64_lp64 => |opts| opts.incoming_stack_alignment == null,4684 dev.check(.powerpc_backend);
4686 .naked => true,4685 break :ok switch (target.cpu.arch) {
4687 else => false,4686 .powerpc, .powerpcle => switch (cc) {
4687 .powerpc_sysv,
4688 .powerpc_sysv_altivec,
4689 .powerpc_aix,
4690 .powerpc_aix_altivec,
4691 .naked,
4692 => true,
4693 else => false,
4694 },
4695 .powerpc64, .powerpc64le => switch (cc) {
4696 .powerpc64_elf,
4697 .powerpc64_elf_altivec,
4698 .powerpc64_elf_v2,
4699 .naked,
4700 => true,
4701 else => false,
4702 },
4703 else => unreachable,
4704 };
4688 },4705 },
4689 .stage2_sparc64 => switch (cc) {4706 .stage2_riscv64 => {
4690 .sparc64_sysv => |opts| opts.incoming_stack_alignment == null,4707 dev.check(.riscv64_backend);
4691 .naked => true,4708 break :ok switch (cc) {
4692 else => false,4709 .riscv64_lp64 => |opts| opts.incoming_stack_alignment == null,
4710 .naked => true,
4711 else => false,
4712 };
4713 },
4714 .stage2_sparc64 => {
4715 dev.check(.sparc64_backend);
4716 break :ok switch (cc) {
4717 .sparc64_sysv => |opts| opts.incoming_stack_alignment == null,
4718 .naked => true,
4719 else => false,
4720 };
4693 },4721 },
4694 .stage2_spirv => switch (cc) {4722 .stage2_spirv => {
4695 .spirv_device, .spirv_kernel => true,4723 dev.check(.spirv_backend);
4696 .spirv_fragment, .spirv_vertex => target.os.tag == .vulkan or target.os.tag == .opengl,4724 break :ok switch (cc) {
4697 .spirv_task, .spirv_mesh => target.os.tag == .vulkan,4725 .spirv_device, .spirv_kernel => true,
4698 else => false,4726 .spirv_fragment, .spirv_vertex => target.os.tag == .vulkan or target.os.tag == .opengl,
4727 .spirv_task, .spirv_mesh => target.os.tag == .vulkan,
4728 else => false,
4729 };
4699 },4730 },
4700 .stage2_loongarch => switch (cc) {4731 .stage2_loongarch => {
4701 .loongarch64_lp64, .loongarch32_ilp32, .naked => true,4732 dev.check(.loongarch_backend);
4702 else => false,4733 break :ok switch (cc) {
4734 .loongarch64_lp64, .loongarch32_ilp32, .naked => true,
4735 else => false,
4736 };
4703 },4737 },
4704 .zsf_spork8 => switch (cc) {4738 .zsf_spork8 => {
4705 .spork8, .naked => true,4739 dev.check(.spork8_backend);
4706 else => false,4740 break :ok switch (cc) {
4741 .spork8, .naked => true,
4742 else => false,
4743 };
4707 },4744 },
4708 };4745 };
4709 if (!backend_ok) return .{ .bad_backend = backend };4746 if (!backend_ok) return .{ .bad_backend = backend };
...@@ -5243,7 +5280,7 @@ pub const CodegenTaskPool = struct {...@@ -5243,7 +5280,7 @@ pub const CodegenTaskPool = struct {
5243 /// memory on AIR/MIR, we see a limit of around 10 MiB of AIR in-flight.5280 /// memory on AIR/MIR, we see a limit of around 10 MiB of AIR in-flight.
5244 const max_air_bytes_in_flight = 10 * 1024 * 1024;5281 const max_air_bytes_in_flight = 10 * 1024 * 1024;
52455282
5246 const max_funcs_in_flight = @import("link.zig").Queue.buffer_size;5283 const max_funcs_in_flight = link.Queue.buffer_size;
52475284
5248 available_air_bytes: u32,5285 available_air_bytes: u32,
52495286
src/Zcu/PerThread.zig+1-2
...@@ -4461,8 +4461,7 @@ pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) Ru...@@ -4461,8 +4461,7 @@ pub fn runCodegen(pt: Zcu.PerThread, func_index: InternPool.Index, air: *Air) Ru
4461 comp.config.use_llvm,4461 comp.config.use_llvm,
4462 )) {4462 )) {
4463 else => unreachable, // assertion failure4463 else => unreachable, // assertion failure
4464 .stage2_llvm,4464 .stage2_llvm => {},
4465 => {},
4466 },4465 },
4467 error.Canceled => |e| return e,4466 error.Canceled => |e| return e,
4468 }4467 }
src/codegen.zig-2
...@@ -744,7 +744,6 @@ fn lowerUavRef(...@@ -744,7 +744,6 @@ fn lowerUavRef(
744 .c => unreachable,744 .c => unreachable,
745 .spirv => unreachable,745 .spirv => unreachable,
746 .wasm => {746 .wasm => {
747 dev.check(link.File.Tag.wasm.devFeature());
748 const wasm = lf.cast(.wasm).?;747 const wasm = lf.cast(.wasm).?;
749 assert(reloc_parent == .none);748 assert(reloc_parent == .none);
750 try wasm.addUavReloc(w.end, uav.val, uav.orig_ty, @intCast(offset));749 try wasm.addUavReloc(w.end, uav.val, uav.orig_ty, @intCast(offset));
...@@ -797,7 +796,6 @@ fn lowerNavRef(...@@ -797,7 +796,6 @@ fn lowerNavRef(
797 .c => unreachable,796 .c => unreachable,
798 .spirv => unreachable,797 .spirv => unreachable,
799 .wasm => {798 .wasm => {
800 dev.check(link.File.Tag.wasm.devFeature());
801 const wasm = lf.cast(.wasm).?;799 const wasm = lf.cast(.wasm).?;
802 assert(reloc_parent == .none);800 assert(reloc_parent == .none);
803 try wasm.addNavReloc(w.end, nav_index, nav_ty, @intCast(offset));801 try wasm.addNavReloc(w.end, nav_index, nav_ty, @intCast(offset));
src/codegen/c.zig+1-2
...@@ -7,7 +7,6 @@ const Allocator = mem.Allocator;...@@ -7,7 +7,6 @@ const Allocator = mem.Allocator;
7const Writer = std.Io.Writer;7const Writer = std.Io.Writer;
88
9const codegen = @import("../codegen.zig");9const codegen = @import("../codegen.zig");
10const dev = @import("../dev.zig");
11const link = @import("../link.zig");10const link = @import("../link.zig");
12const Zcu = @import("../Zcu.zig");11const Zcu = @import("../Zcu.zig");
13const Module = @import("../Module.zig");12const Module = @import("../Module.zig");
...@@ -25,7 +24,7 @@ const BigIntLimb = std.math.big.Limb;...@@ -25,7 +24,7 @@ const BigIntLimb = std.math.big.Limb;
25const BigInt = std.math.big.int;24const BigInt = std.math.big.int;
2625
27pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {26pub fn legalizeFeatures(_: *const std.Target) ?*const Air.Legalize.Features {
28 return comptime switch (dev.env.supports(.legalize)) {27 return comptime switch (@import("../dev.zig").env.supports(.legalize)) {
29 inline false, true => |supports_legalize| &.init(.{28 inline false, true => |supports_legalize| &.init(.{
30 // we don't currently ask zig1 to use safe optimization modes29 // we don't currently ask zig1 to use safe optimization modes
31 .expand_bit_cast_safe = supports_legalize,30 .expand_bit_cast_safe = supports_legalize,
src/codegen/llvm.zig+1-3
...@@ -10,7 +10,6 @@ const build_options = @import("build_options");...@@ -10,7 +10,6 @@ const build_options = @import("build_options");
10const Air = @import("../Air.zig");10const Air = @import("../Air.zig");
11const codegen = @import("../codegen.zig");11const codegen = @import("../codegen.zig");
12const Compilation = @import("../Compilation.zig");12const Compilation = @import("../Compilation.zig");
13const dev = @import("../dev.zig");
14const InternPool = @import("../InternPool.zig");13const InternPool = @import("../InternPool.zig");
15const link = @import("../link.zig");14const link = @import("../link.zig");
16const Module = @import("../Module.zig");15const Module = @import("../Module.zig");
...@@ -155,12 +154,11 @@ pub const Object = struct {...@@ -155,12 +154,11 @@ pub const Object = struct {
155 /// Values for `@llvm.used`.154 /// Values for `@llvm.used`.
156 used: std.ArrayList(Builder.Constant),155 used: std.ArrayList(Builder.Constant),
157156
158 pub const Ptr = if (dev.env.supports(.llvm_backend)) *Object else noreturn;157 pub const Ptr = if (@import("../dev.zig").env.supports(.llvm_backend)) *Object else noreturn;
159158
160 const TypeMap = std.AutoHashMapUnmanaged(InternPool.Index, Builder.Type);159 const TypeMap = std.AutoHashMapUnmanaged(InternPool.Index, Builder.Type);
161160
162 pub fn create(arena: Allocator, zcu: *Zcu) !Ptr {161 pub fn create(arena: Allocator, zcu: *Zcu) !Ptr {
163 dev.check(.llvm_backend);
164 const comp = zcu.comp;162 const comp = zcu.comp;
165 const gpa = comp.gpa;163 const gpa = comp.gpa;
166 const target = zcu.getTarget();164 const target = zcu.getTarget();
src/crash_report.zig-1
...@@ -215,7 +215,6 @@ const Sema = @import("Sema.zig");...@@ -215,7 +215,6 @@ const Sema = @import("Sema.zig");
215const Zcu = @import("Zcu.zig");215const Zcu = @import("Zcu.zig");
216const link = @import("link.zig");216const link = @import("link.zig");
217const InternPool = @import("InternPool.zig");217const InternPool = @import("InternPool.zig");
218const dev = @import("dev.zig");
219const print_zir = @import("print_zir.zig");218const print_zir = @import("print_zir.zig");
220219
221const build_options = @import("build_options");220const build_options = @import("build_options");
src/dev.zig-1
...@@ -227,7 +227,6 @@ pub const Env = enum {...@@ -227,7 +227,6 @@ pub const Env = enum {
227 else => Env.sema.supports(feature),227 else => Env.sema.supports(feature),
228 },228 },
229 .@"x86_64-windows" => switch (feature) {229 .@"x86_64-windows" => switch (feature) {
230 .build_command,
231 .stdio_listen,230 .stdio_listen,
232 .incremental,231 .incremental,
233 .legalize,232 .legalize,
src/link.zig+1-5
...@@ -97,7 +97,6 @@ pub const Diags = struct {...@@ -97,7 +97,6 @@ pub const Diags = struct {
97 return switch (msg.source_location) {97 return switch (msg.source_location) {
98 .none => try bundle.addString(msg.msg),98 .none => try bundle.addString(msg.msg),
99 .wasm => |sl| {99 .wasm => |sl| {
100 dev.check(.wasm_linker);
101 const wasm = base.?.cast(.wasm).?;100 const wasm = base.?.cast(.wasm).?;
102 return sl.string(msg.msg, bundle, wasm);101 return sl.string(msg.msg, bundle, wasm);
103 },102 },
...@@ -396,8 +395,6 @@ pub const Diags = struct {...@@ -396,8 +395,6 @@ pub const Diags = struct {
396 }395 }
397};396};
398397
399pub const producer_string = if (builtin.is_test) "zig test" else "zig " ++ build_options.version;
400
401pub const File = struct {398pub const File = struct {
402 tag: Tag,399 tag: Tag,
403400
...@@ -655,7 +652,6 @@ pub const File = struct {...@@ -655,7 +652,6 @@ pub const File = struct {
655 base.file = try emit.root_dir.handle.openFile(io, emit.sub_path, .{ .mode = .read_write });652 base.file = try emit.root_dir.handle.openFile(io, emit.sub_path, .{ .mode = .read_write });
656 },653 },
657 .elf2, .coff2 => if (base.file == null) {654 .elf2, .coff2 => if (base.file == null) {
658 dev.checkAny(&.{ .elf2_linker, .coff2_linker });
659 const mf = if (base.cast(.elf2)) |elf|655 const mf = if (base.cast(.elf2)) |elf|
660 &elf.mf656 &elf.mf
661 else if (base.cast(.coff2)) |coff|657 else if (base.cast(.coff2)) |coff|
...@@ -1347,7 +1343,7 @@ pub const File = struct {...@@ -1347,7 +1343,7 @@ pub const File = struct {
1347 };1343 };
1348 }1344 }
13491345
1350 pub fn devFeature(tag: Tag) dev.Feature {1346 fn devFeature(tag: Tag) dev.Feature {
1351 return @field(dev.Feature, @tagName(tag) ++ "_linker");1347 return @field(dev.Feature, @tagName(tag) ++ "_linker");
1352 }1348 }
1353 };1349 };
src/link/Coff.zig+1-1
...@@ -13,7 +13,7 @@ const codegen = @import("../codegen.zig");...@@ -13,7 +13,7 @@ const codegen = @import("../codegen.zig");
13const Compilation = @import("../Compilation.zig");13const Compilation = @import("../Compilation.zig");
14const InternPool = @import("../InternPool.zig");14const InternPool = @import("../InternPool.zig");
15const link = @import("../link.zig");15const link = @import("../link.zig");
16const MappedFile = @import("MappedFile.zig");16const MappedFile = link.MappedFile;
17const target_util = @import("../target.zig");17const target_util = @import("../target.zig");
18const Type = @import("../Type.zig");18const Type = @import("../Type.zig");
19const Value = @import("../Value.zig");19const Value = @import("../Value.zig");
src/link/ConstPool.zig+25-4
...@@ -45,11 +45,22 @@ pub const Index = enum(u32) {...@@ -45,11 +45,22 @@ pub const Index = enum(u32) {
45};45};
4646
47pub const User = union(enum) {47pub const User = union(enum) {
48 dwarf: *@import("Dwarf.zig"),48 elf: *@import("Dwarf.zig"),
49 elf2: *@import("Elf2.zig"),49 elf2: *@import("Elf2.zig"),
50 macho: *@import("Dwarf.zig"),
50 c: *@import("C.zig"),51 c: *@import("C.zig"),
51 llvm: @import("../codegen/llvm.zig").Object.Ptr,52 llvm: @import("../codegen/llvm.zig").Object.Ptr,
5253
54 fn devFeature(tag: @typeInfo(User).@"union".tag_type.?) dev.Feature {
55 return switch (tag) {
56 .elf => .elf_linker,
57 .elf2 => .elf2_linker,
58 .macho => .macho_linker,
59 .c => .c_linker,
60 .llvm => .llvm_backend,
61 };
62 }
63
53 /// Inform the debug info implementation that the new constant `val` was added to the pool at64 /// Inform the debug info implementation that the new constant `val` was added to the pool at
54 /// the given index (which equals the current pool length) due to a `get` call. It is guaranteed65 /// the given index (which equals the current pool length) due to a `get` call. It is guaranteed
55 /// that there will eventually be a call to either `updateConst` or `updateConstIncomplete`66 /// that there will eventually be a call to either `updateConst` or `updateConstIncomplete`
...@@ -61,7 +72,10 @@ pub const User = union(enum) {...@@ -61,7 +72,10 @@ pub const User = union(enum) {
61 val: InternPool.Index,72 val: InternPool.Index,
62 ) link.Error!void {73 ) link.Error!void {
63 switch (user) {74 switch (user) {
64 inline else => |impl| return impl.addConst(pt, index, val),75 inline else => |impl, tag| {
76 dev.check(devFeature(tag));
77 return impl.addConst(pt, index, val);
78 },
65 }79 }
66 }80 }
6781
...@@ -76,7 +90,10 @@ pub const User = union(enum) {...@@ -76,7 +90,10 @@ pub const User = union(enum) {
76 val: InternPool.Index,90 val: InternPool.Index,
77 ) link.Error!void {91 ) link.Error!void {
78 switch (user) {92 switch (user) {
79 inline else => |impl| return impl.updateConst(pt, index, val),93 inline else => |impl, tag| {
94 dev.check(devFeature(tag));
95 return impl.updateConst(pt, index, val);
96 },
80 }97 }
81 }98 }
8299
...@@ -92,7 +109,10 @@ pub const User = union(enum) {...@@ -92,7 +109,10 @@ pub const User = union(enum) {
92 val: InternPool.Index,109 val: InternPool.Index,
93 ) link.Error!void {110 ) link.Error!void {
94 switch (user) {111 switch (user) {
95 inline else => |impl| return impl.updateConstIncomplete(pt, index, val),112 inline else => |impl, tag| {
113 dev.check(devFeature(tag));
114 return impl.updateConstIncomplete(pt, index, val);
115 },
96 }116 }
97 }117 }
98};118};
...@@ -289,6 +309,7 @@ fn registerTypeDeps(pool: *ConstPool, root: Index, ty: Type, zcu: *const Zcu) Al...@@ -289,6 +309,7 @@ fn registerTypeDeps(pool: *ConstPool, root: Index, ty: Type, zcu: *const Zcu) Al
289const std = @import("std");309const std = @import("std");
290const Allocator = std.mem.Allocator;310const Allocator = std.mem.Allocator;
291311
312const dev = @import("../dev.zig");
292const InternPool = @import("../InternPool.zig");313const InternPool = @import("../InternPool.zig");
293const link = @import("../link.zig");314const link = @import("../link.zig");
294const Type = @import("../Type.zig");315const Type = @import("../Type.zig");
src/link/Dwarf.zig+24-16
...@@ -122,7 +122,7 @@ const DebugFrame = struct {...@@ -122,7 +122,7 @@ const DebugFrame = struct {
122 uleb128Bytes(1) + 1,122 uleb128Bytes(1) + 1,
123 } + switch (target.cpu.arch) {123 } + switch (target.cpu.arch) {
124 .x86_64 => len: {124 .x86_64 => len: {
125 dev.check(.x86_64_backend);125 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
126 const Register = @import("../codegen/x86_64/bits.zig").Register;126 const Register = @import("../codegen/x86_64/bits.zig").Register;
127 break :len uleb128Bytes(1) + sleb128Bytes(-8) + uleb128Bytes(Register.rip.dwarfNum()) +127 break :len uleb128Bytes(1) + sleb128Bytes(-8) + uleb128Bytes(Register.rip.dwarfNum()) +
128 1 + uleb128Bytes(Register.rsp.dwarfNum()) + sleb128Bytes(-1) +128 1 + uleb128Bytes(Register.rsp.dwarfNum()) + sleb128Bytes(-1) +
...@@ -2092,7 +2092,7 @@ pub const WipNav = struct {...@@ -2092,7 +2092,7 @@ pub const WipNav = struct {
2092 assert(value.typeOf(wip_nav.pt.zcu).comptimeOnly(wip_nav.pt.zcu));2092 assert(value.typeOf(wip_nav.pt.zcu).comptimeOnly(wip_nav.pt.zcu));
2093 }2093 }
2094 const dwarf = wip_nav.dwarf;2094 const dwarf = wip_nav.dwarf;
2095 const index = try dwarf.const_pool.get(wip_nav.pt, .{ .dwarf = dwarf }, value.toIntern());2095 const index = try dwarf.const_pool.get(wip_nav.pt, dwarf.constPoolUser(), value.toIntern());
2096 return dwarf.values.items[@backingInt(index)];2096 return dwarf.values.items[@backingInt(index)];
2097 }2097 }
20982098
...@@ -3005,7 +3005,7 @@ fn finishWipNavWriterError(...@@ -3005,7 +3005,7 @@ fn finishWipNavWriterError(
3005 try dwarf.debug_line.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_line.written());3005 try dwarf.debug_line.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_line.written());
3006 try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.written());3006 try dwarf.debug_loclists.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_loclists.written());
30073007
3008 try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf });3008 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
3009}3009}
30103010
3011pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) link.Error!void {3011pub fn updateComptimeNav(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) link.Error!void {
...@@ -3067,8 +3067,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3067,8 +3067,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3067 const loaded_struct = ip.loadStructType(nav_val.toIntern());3067 const loaded_struct = ip.loadStructType(nav_val.toIntern());
3068 if (nav_index.toOptional() == loaded_struct.name_nav) {3068 if (nav_index.toOptional() == loaded_struct.name_nav) {
3069 // This Nav's entry is populated by the type, not the actual Nav.3069 // This Nav's entry is populated by the type, not the actual Nav.
3070 _ = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, nav_val.toIntern());3070 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
3071 try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf });3071 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
3072 return;3072 return;
3073 }3073 }
3074 break :tag .alias;3074 break :tag .alias;
...@@ -3077,8 +3077,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3077,8 +3077,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3077 const loaded_enum = ip.loadEnumType(nav_val.toIntern());3077 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
3078 if (nav_index.toOptional() == loaded_enum.name_nav) {3078 if (nav_index.toOptional() == loaded_enum.name_nav) {
3079 // This Nav's entry is populated by the type, not the actual Nav.3079 // This Nav's entry is populated by the type, not the actual Nav.
3080 _ = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, nav_val.toIntern());3080 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
3081 try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf });3081 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
3082 return;3082 return;
3083 }3083 }
3084 break :tag .alias;3084 break :tag .alias;
...@@ -3087,8 +3087,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3087,8 +3087,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3087 const loaded_union = ip.loadUnionType(nav_val.toIntern());3087 const loaded_union = ip.loadUnionType(nav_val.toIntern());
3088 if (nav_index.toOptional() == loaded_union.name_nav) {3088 if (nav_index.toOptional() == loaded_union.name_nav) {
3089 // This Nav's entry is populated by the type, not the actual Nav.3089 // This Nav's entry is populated by the type, not the actual Nav.
3090 _ = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, nav_val.toIntern());3090 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
3091 try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf });3091 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
3092 return;3092 return;
3093 }3093 }
3094 break :tag .alias;3094 break :tag .alias;
...@@ -3097,8 +3097,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3097,8 +3097,8 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3097 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());3097 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
3098 if (nav_index.toOptional() == loaded_opaque.name_nav) {3098 if (nav_index.toOptional() == loaded_opaque.name_nav) {
3099 // This Nav's entry is populated by the type, not the actual Nav.3099 // This Nav's entry is populated by the type, not the actual Nav.
3100 _ = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, nav_val.toIntern());3100 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
3101 try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf });3101 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
3102 return;3102 return;
3103 }3103 }
3104 break :tag .alias;3104 break :tag .alias;
...@@ -3274,7 +3274,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo...@@ -3274,7 +3274,7 @@ fn updateComptimeNavInner(dwarf: *Dwarf, pt: Zcu.PerThread, nav_index: InternPoo
3274 },3274 },
3275 }3275 }
3276 try dwarf.debug_info.section.replaceEntry(unit, wip_nav.entry, dwarf, wip_nav.debug_info.written());3276 try dwarf.debug_info.section.replaceEntry(unit, wip_nav.entry, dwarf, wip_nav.debug_info.written());
3277 try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf });3277 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
3278}3278}
32793279
3280pub fn updateContainerType(3280pub fn updateContainerType(
...@@ -3283,7 +3283,7 @@ pub fn updateContainerType(...@@ -3283,7 +3283,7 @@ pub fn updateContainerType(
3283 ty: InternPool.Index,3283 ty: InternPool.Index,
3284 success: bool,3284 success: bool,
3285) !void {3285) !void {
3286 try dwarf.const_pool.updateContainerType(pt, .{ .dwarf = dwarf }, ty, success);3286 try dwarf.const_pool.updateContainerType(pt, dwarf.constPoolUser(), ty, success);
3287}3287}
3288/// Should only be called by the `link.ConstPool` implementation.3288/// Should only be called by the `link.ConstPool` implementation.
3289pub fn addConst(dwarf: *Dwarf, pt: Zcu.PerThread, index: link.ConstPool.Index, val: InternPool.Index) Allocator.Error!void {3289pub fn addConst(dwarf: *Dwarf, pt: Zcu.PerThread, index: link.ConstPool.Index, val: InternPool.Index) Allocator.Error!void {
...@@ -4702,7 +4702,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (UpdateError || Writer.Err...@@ -4702,7 +4702,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (UpdateError || Writer.Err
47024702
4703 // Update `anyerror` based on the finished global error set.4703 // Update `anyerror` based on the finished global error set.
4704 {4704 {
4705 const index = try dwarf.const_pool.get(pt, .{ .dwarf = dwarf }, .anyerror_type);4705 const index = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), .anyerror_type);
4706 const unit, const entry = dwarf.values.items[@backingInt(index)];4706 const unit, const entry = dwarf.values.items[@backingInt(index)];
4707 var wip_nav: WipNav = .{4707 var wip_nav: WipNav = .{
4708 .dwarf = dwarf,4708 .dwarf = dwarf,
...@@ -4737,7 +4737,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (UpdateError || Writer.Err...@@ -4737,7 +4737,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (UpdateError || Writer.Err
4737 }4737 }
4738 if (global_error_set_names.len > 0) try diw.writeUleb128(@backingInt(AbbrevCode.null));4738 if (global_error_set_names.len > 0) try diw.writeUleb128(@backingInt(AbbrevCode.null));
4739 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.written());4739 try dwarf.debug_info.section.replaceEntry(wip_nav.unit, wip_nav.entry, dwarf, wip_nav.debug_info.written());
4740 try dwarf.const_pool.flushPending(pt, .{ .dwarf = dwarf });4740 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
4741 }4741 }
47424742
4743 for (dwarf.mods.keys(), dwarf.mods.values()) |mod, *mod_info| {4743 for (dwarf.mods.keys(), dwarf.mods.values()) |mod, *mod_info| {
...@@ -4789,7 +4789,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (UpdateError || Writer.Err...@@ -4789,7 +4789,7 @@ fn flushWriterError(dwarf: *Dwarf, pt: Zcu.PerThread) (UpdateError || Writer.Err
4789 .debug_frame => unreachable,4789 .debug_frame => unreachable,
4790 .eh_frame => switch (target.cpu.arch) {4790 .eh_frame => switch (target.cpu.arch) {
4791 .x86_64 => {4791 .x86_64 => {
4792 dev.check(.x86_64_backend);4792 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
4793 const Register = @import("../codegen/x86_64/bits.zig").Register;4793 const Register = @import("../codegen/x86_64/bits.zig").Register;
4794 for (dwarf.debug_frame.section.units.items) |*unit| {4794 for (dwarf.debug_frame.section.units.items) |*unit| {
4795 header_aw.clearRetainingCapacity();4795 header_aw.clearRetainingCapacity();
...@@ -6307,6 +6307,14 @@ fn getFile(dwarf: *Dwarf) ?Io.File {...@@ -6307,6 +6307,14 @@ fn getFile(dwarf: *Dwarf) ?Io.File {
6307 return dwarf.bin_file.file;6307 return dwarf.bin_file.file;
6308}6308}
63096309
6310fn constPoolUser(dwarf: *Dwarf) link.ConstPool.User {
6311 return switch (dwarf.bin_file.tag) {
6312 else => unreachable,
6313 .elf => .{ .elf = dwarf },
6314 .macho => .{ .macho = dwarf },
6315 };
6316}
6317
6310fn addCommonEntry(dwarf: *Dwarf, unit: Unit.Index) UpdateError!Entry.Index {6318fn addCommonEntry(dwarf: *Dwarf, unit: Unit.Index) UpdateError!Entry.Index {
6311 const entry = try dwarf.debug_aranges.section.getUnit(unit).addEntry(dwarf.gpa);6319 const entry = try dwarf.debug_aranges.section.getUnit(unit).addEntry(dwarf.gpa);
6312 assert(try dwarf.debug_frame.section.getUnit(unit).addEntry(dwarf.gpa) == entry);6320 assert(try dwarf.debug_frame.section.getUnit(unit).addEntry(dwarf.gpa) == entry);
src/link/Dwarf2.zig+69-64
...@@ -27,15 +27,15 @@ pub const Unit = struct {...@@ -27,15 +27,15 @@ pub const Unit = struct {
27 alive: bool,27 alive: bool,
28 dirs: std.array_hash_map.Auto(Unit.Index, void),28 dirs: std.array_hash_map.Auto(Unit.Index, void),
29 files: std.array_hash_map.Auto(Zcu.File.Index, void),29 files: std.array_hash_map.Auto(Zcu.File.Index, void),
30 frame_ni: MappedFile.Node.Index.Optional,30 frame_ni: link.MappedFile.Node.Index.Optional,
31 cie_ni: MappedFile.Node.Index.Optional,31 cie_ni: link.MappedFile.Node.Index.Optional,
32 debug_info_ni: MappedFile.Node.Index.Optional,32 debug_info_ni: link.MappedFile.Node.Index.Optional,
33 debug_info_header_ni: MappedFile.Node.Index.Optional,33 debug_info_header_ni: link.MappedFile.Node.Index.Optional,
34 debug_info_footer_ni: MappedFile.Node.Index.Optional,34 debug_info_footer_ni: link.MappedFile.Node.Index.Optional,
35 debug_line_ni: MappedFile.Node.Index.Optional,35 debug_line_ni: link.MappedFile.Node.Index.Optional,
36 debug_line_header_ni: MappedFile.Node.Index.Optional,36 debug_line_header_ni: link.MappedFile.Node.Index.Optional,
37 debug_line_header_changed: bool,37 debug_line_header_changed: bool,
38 debug_rnglists_ni: MappedFile.Node.Index.Optional,38 debug_rnglists_ni: link.MappedFile.Node.Index.Optional,
39 debug_rnglists_offsets_table_offset: usize,39 debug_rnglists_offsets_table_offset: usize,
40 debug_rnglists_end: usize,40 debug_rnglists_end: usize,
4141
...@@ -96,7 +96,7 @@ pub const Unit = struct {...@@ -96,7 +96,7 @@ pub const Unit = struct {
96};96};
9797
98pub const Const = struct {98pub const Const = struct {
99 debug_info_ni: MappedFile.Node.Index.Optional,99 debug_info_ni: link.MappedFile.Node.Index.Optional,
100100
101 pub fn get(cpi: link.ConstPool.Index, dwarf: *Dwarf) *Const {101 pub fn get(cpi: link.ConstPool.Index, dwarf: *Dwarf) *Const {
102 return &dwarf.consts.items[@backingInt(cpi)];102 return &dwarf.consts.items[@backingInt(cpi)];
...@@ -104,7 +104,7 @@ pub const Const = struct {...@@ -104,7 +104,7 @@ pub const Const = struct {
104};104};
105105
106pub const Global = struct {106pub const Global = struct {
107 debug_info_ni: MappedFile.Node.Index.Optional,107 debug_info_ni: link.MappedFile.Node.Index.Optional,
108108
109 pub const Index = enum(u32) {109 pub const Index = enum(u32) {
110 _,110 _,
...@@ -121,9 +121,9 @@ pub const Global = struct {...@@ -121,9 +121,9 @@ pub const Global = struct {
121121
122pub const Func = struct {122pub const Func = struct {
123 state: State,123 state: State,
124 fde_ni: MappedFile.Node.Index.Optional,124 fde_ni: link.MappedFile.Node.Index.Optional,
125 debug_info_ni: MappedFile.Node.Index.Optional,125 debug_info_ni: link.MappedFile.Node.Index.Optional,
126 debug_line_ni: MappedFile.Node.Index.Optional,126 debug_line_ni: link.MappedFile.Node.Index.Optional,
127127
128 pub const State = enum { unresolved, resolved };128 pub const State = enum { unresolved, resolved };
129129
...@@ -141,7 +141,7 @@ pub const Func = struct {...@@ -141,7 +141,7 @@ pub const Func = struct {
141};141};
142142
143pub const Decl = struct {143pub const Decl = struct {
144 debug_info_ni: MappedFile.Node.Index.Optional,144 debug_info_ni: link.MappedFile.Node.Index.Optional,
145145
146 pub const Index = enum(u32) {146 pub const Index = enum(u32) {
147 _,147 _,
...@@ -170,7 +170,7 @@ pub const Frame = struct {...@@ -170,7 +170,7 @@ pub const Frame = struct {
170};170};
171171
172pub const Abbrev = struct {172pub const Abbrev = struct {
173 ni: MappedFile.Node.Index.Optional,173 ni: link.MappedFile.Node.Index.Optional,
174 end: usize,174 end: usize,
175 set: std.enums.EnumSet(AbbrevCode),175 set: std.enums.EnumSet(AbbrevCode),
176};176};
...@@ -191,16 +191,16 @@ pub const Line = struct {...@@ -191,16 +191,16 @@ pub const Line = struct {
191};191};
192192
193pub const Str = struct {193pub const Str = struct {
194 ni: MappedFile.Node.Index.Optional,194 ni: link.MappedFile.Node.Index.Optional,
195 offset: usize,195 offset: usize,
196 map: std.HashMapUnmanaged(usize, void, Context, std.hash_map.default_max_load_percentage),196 map: std.HashMapUnmanaged(usize, void, Context, std.hash_map.default_max_load_percentage),
197197
198 fn get(198 fn get(
199 s: *Str,199 s: *Str,
200 gpa: std.mem.Allocator,200 gpa: std.mem.Allocator,
201 mf: *MappedFile,201 mf: *link.MappedFile,
202 str: []const u8,202 str: []const u8,
203 ) MappedFile.Error!usize {203 ) link.MappedFile.Error!usize {
204 const ni = s.ni.unwrap().?;204 const ni = s.ni.unwrap().?;
205 const slice = ni.sliceConst(mf);205 const slice = ni.sliceConst(mf);
206 const gop = try s.map.getOrPutContextAdapted(206 const gop = try s.map.getOrPutContextAdapted(
...@@ -250,7 +250,7 @@ pub const Rnglists = struct {...@@ -250,7 +250,7 @@ pub const Rnglists = struct {
250};250};
251251
252pub const StrOffsets = struct {252pub const StrOffsets = struct {
253 ni: MappedFile.Node.Index.Optional,253 ni: link.MappedFile.Node.Index.Optional,
254 offset: usize,254 offset: usize,
255};255};
256256
...@@ -268,13 +268,13 @@ pub const Loc = union(enum) {...@@ -268,13 +268,13 @@ pub const Loc = union(enum) {
268 push_object_address,268 push_object_address,
269 call: struct {269 call: struct {
270 args: []const Loc = &.{},270 args: []const Loc = &.{},
271 node: MappedFile.Node.Index,271 node: link.MappedFile.Node.Index,
272 },272 },
273 form_tls_address: *const Loc,273 form_tls_address: *const Loc,
274 implicit_value: []const u8,274 implicit_value: []const u8,
275 stack_value: *const Loc,275 stack_value: *const Loc,
276 implicit_pointer: struct {276 implicit_pointer: struct {
277 node: MappedFile.Node.Index,277 node: link.MappedFile.Node.Index,
278 offset: i65 = 0,278 offset: i65 = 0,
279 },279 },
280 wasm_ext: union(enum) {280 wasm_ext: union(enum) {
...@@ -311,7 +311,7 @@ pub const Loc = union(enum) {...@@ -311,7 +311,7 @@ pub const Loc = union(enum) {
311311
312 fn write(loc: Loc, writer: union(enum) {312 fn write(loc: Loc, writer: union(enum) {
313 io: *std.Io.Writer,313 io: *std.Io.Writer,
314 mf: *MappedFile.Node.Writer,314 mf: *link.MappedFile.Node.Writer,
315 }, dwarf: *Dwarf) link.EmitError!void {315 }, dwarf: *Dwarf) link.EmitError!void {
316 const w = switch (writer) {316 const w = switch (writer) {
317 .io => |w| w,317 .io => |w| w,
...@@ -631,7 +631,7 @@ pub const WipNav = struct {...@@ -631,7 +631,7 @@ pub const WipNav = struct {
631 cfa: Cfa.RegOff,631 cfa: Cfa.RegOff,
632 },632 },
633 frame_format: Frame.Format,633 frame_format: Frame.Format,
634 fde_writer: MappedFile.Node.Writer,634 fde_writer: link.MappedFile.Node.Writer,
635 frame_func_length: struct { offset: usize, size: AddressSize },635 frame_func_length: struct { offset: usize, size: AddressSize },
636636
637 pub const Debug = struct {637 pub const Debug = struct {
...@@ -643,9 +643,9 @@ pub const WipNav = struct {...@@ -643,9 +643,9 @@ pub const WipNav = struct {
643 low_pc_off: usize,643 low_pc_off: usize,
644 high_pc: u32,644 high_pc: u32,
645 }),645 }),
646 info_writer: MappedFile.Node.Writer,646 info_writer: link.MappedFile.Node.Writer,
647 info_func_length_offset: usize,647 info_func_length_offset: usize,
648 line_writer: MappedFile.Node.Writer,648 line_writer: link.MappedFile.Node.Writer,
649649
650 pub fn deinit(debug: *Debug) void {650 pub fn deinit(debug: *Debug) void {
651 const gpa = debug.pt.zcu.gpa;651 const gpa = debug.pt.zcu.gpa;
...@@ -1268,7 +1268,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {...@@ -1268,7 +1268,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf {
1268 },1268 },
1269 .frame = .{1269 .frame = .{
1270 .header = if (target.cpu.arch == .x86_64 and target.ofmt == .elf) header: {1270 .header = if (target.cpu.arch == .x86_64 and target.ofmt == .elf) header: {
1271 dev.check(.x86_64_backend);1271 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1272 const Register = @import("../codegen/x86_64/bits.zig").Register;1272 const Register = @import("../codegen/x86_64/bits.zig").Register;
1273 break :header comptime .{1273 break :header comptime .{
1274 .code_alignment_factor = 1,1274 .code_alignment_factor = 1,
...@@ -1385,7 +1385,7 @@ pub fn getUnit(dwarf: *Dwarf, mod: *Module) Unit.Index {...@@ -1385,7 +1385,7 @@ pub fn getUnit(dwarf: *Dwarf, mod: *Module) Unit.Index {
13851385
1386pub fn getConst(dwarf: *Dwarf, pt: Zcu.PerThread, val: Value) link.Error!link.ConstPool.Index {1386pub fn getConst(dwarf: *Dwarf, pt: Zcu.PerThread, val: Value) link.Error!link.ConstPool.Index {
1387 assert(val.typeOf(pt.zcu).comptimeOnly(pt.zcu));1387 assert(val.typeOf(pt.zcu).comptimeOnly(pt.zcu));
1388 return dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, val.toIntern());1388 return dwarf.const_pool.get(pt, dwarf.constPoolUser(), val.toIntern());
1389}1389}
13901390
1391pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Index {1391pub fn getGlobal(dwarf: *Dwarf, nav: InternPool.Nav.Index) link.Error!Global.Index {
...@@ -1514,7 +1514,7 @@ pub fn getDecl(...@@ -1514,7 +1514,7 @@ pub fn getDecl(
1514 dwarf: *Dwarf,1514 dwarf: *Dwarf,
1515 pt: Zcu.PerThread,1515 pt: Zcu.PerThread,
1516 instance_val: InternPool.Index,1516 instance_val: InternPool.Index,
1517) link.Error!MappedFile.Node.Index {1517) link.Error!link.MappedFile.Node.Index {
1518 assert(dwarf.pending_decl.instance_val == .none);1518 assert(dwarf.pending_decl.instance_val == .none);
1519 const comp = dwarf.lf.comp;1519 const comp = dwarf.lf.comp;
1520 const gpa = comp.gpa;1520 const gpa = comp.gpa;
...@@ -1634,7 +1634,7 @@ pub fn genDebugFrameCie(...@@ -1634,7 +1634,7 @@ pub fn genDebugFrameCie(
1634 switch (arch orelse return) {1634 switch (arch orelse return) {
1635 else => unreachable,1635 else => unreachable,
1636 .x86_64 => {1636 .x86_64 => {
1637 dev.check(.x86_64_backend);1637 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1638 const Register = @import("../codegen/x86_64/bits.zig").Register;1638 const Register = @import("../codegen/x86_64/bits.zig").Register;
1639 switch (format) {1639 switch (format) {
1640 .eh_frame => try df_w.writeAll("zR\x00"),1640 .eh_frame => try df_w.writeAll("zR\x00"),
...@@ -1682,7 +1682,7 @@ pub fn genDebugInfoHeader(...@@ -1682,7 +1682,7 @@ pub fn genDebugInfoHeader(
1682 zcu: *Zcu,1682 zcu: *Zcu,
1683 mod: *Module,1683 mod: *Module,
1684 unit: *Unit,1684 unit: *Unit,
1685 dih_nw: *MappedFile.Node.Writer,1685 dih_nw: *link.MappedFile.Node.Writer,
1686) link.EmitError!void {1686) link.EmitError!void {
1687 const comp = zcu.comp;1687 const comp = zcu.comp;
1688 const dih_w = &dih_nw.interface;1688 const dih_w = &dih_nw.interface;
...@@ -1728,7 +1728,7 @@ pub fn genDebugInfoHeader(...@@ -1728,7 +1728,7 @@ pub fn genDebugInfoHeader(
17281728
1729fn genModuleDependency(1729fn genModuleDependency(
1730 dwarf: *Dwarf,1730 dwarf: *Dwarf,
1731 di_nw: *MappedFile.Node.Writer,1731 di_nw: *link.MappedFile.Node.Writer,
1732 name: []const u8,1732 name: []const u8,
1733 dep: *Module,1733 dep: *Module,
1734 module_offset: usize,1734 module_offset: usize,
...@@ -1773,7 +1773,7 @@ pub fn genDebugInfoPadding(dwarf: *Dwarf, di_w: *std.Io.Writer, size: u64) std.I...@@ -1773,7 +1773,7 @@ pub fn genDebugInfoPadding(dwarf: *Dwarf, di_w: *std.Io.Writer, size: u64) std.I
1773pub fn genDebugLineHeader(1773pub fn genDebugLineHeader(
1774 dwarf: *Dwarf,1774 dwarf: *Dwarf,
1775 unit: *Unit,1775 unit: *Unit,
1776 dlh_nw: *MappedFile.Node.Writer,1776 dlh_nw: *link.MappedFile.Node.Writer,
1777 zcu: *Zcu,1777 zcu: *Zcu,
1778) link.EmitError!void {1778) link.EmitError!void {
1779 const comp = zcu.comp;1779 const comp = zcu.comp;
...@@ -1911,7 +1911,7 @@ pub fn genDebugLinePadding(dl_w: *std.Io.Writer, size: u64) std.Io.Writer.Error!...@@ -1911,7 +1911,7 @@ pub fn genDebugLinePadding(dl_w: *std.Io.Writer, size: u64) std.Io.Writer.Error!
1911pub fn genDebugRnglistsHeader(1911pub fn genDebugRnglistsHeader(
1912 dwarf: *Dwarf,1912 dwarf: *Dwarf,
1913 unit: *Unit,1913 unit: *Unit,
1914 drh_nw: *MappedFile.Node.Writer,1914 drh_nw: *link.MappedFile.Node.Writer,
1915) std.Io.Writer.Error!void {1915) std.Io.Writer.Error!void {
1916 const drh_w = &drh_nw.interface;1916 const drh_w = &drh_nw.interface;
1917 try dwarf.genUnitLength(drh_w);1917 try dwarf.genUnitLength(drh_w);
...@@ -1931,7 +1931,7 @@ pub fn genDebugRnglistsHeader(...@@ -1931,7 +1931,7 @@ pub fn genDebugRnglistsHeader(
1931pub fn genDebugRnglists(1931pub fn genDebugRnglists(
1932 dwarf: *Dwarf,1932 dwarf: *Dwarf,
1933 unit: *Unit,1933 unit: *Unit,
1934 dr_nw: *MappedFile.Node.Writer,1934 dr_nw: *link.MappedFile.Node.Writer,
1935 func_si: link.File.SymbolId,1935 func_si: link.File.SymbolId,
1936 func_length: u64,1936 func_length: u64,
1937) link.EmitError!void {1937) link.EmitError!void {
...@@ -1965,7 +1965,7 @@ pub fn updateComptimeNav(...@@ -1965,7 +1965,7 @@ pub fn updateComptimeNav(
1965 .struct_type => {1965 .struct_type => {
1966 const loaded_struct = ip.loadStructType(nav_val.toIntern());1966 const loaded_struct = ip.loadStructType(nav_val.toIntern());
1967 if (nav_index.toOptional() == loaded_struct.name_nav) {1967 if (nav_index.toOptional() == loaded_struct.name_nav) {
1968 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());1968 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1969 break :done;1969 break :done;
1970 }1970 }
1971 return;1971 return;
...@@ -1973,7 +1973,7 @@ pub fn updateComptimeNav(...@@ -1973,7 +1973,7 @@ pub fn updateComptimeNav(
1973 .enum_type => {1973 .enum_type => {
1974 const loaded_enum = ip.loadEnumType(nav_val.toIntern());1974 const loaded_enum = ip.loadEnumType(nav_val.toIntern());
1975 if (nav_index.toOptional() == loaded_enum.name_nav) {1975 if (nav_index.toOptional() == loaded_enum.name_nav) {
1976 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());1976 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1977 break :done;1977 break :done;
1978 }1978 }
1979 return;1979 return;
...@@ -1981,7 +1981,7 @@ pub fn updateComptimeNav(...@@ -1981,7 +1981,7 @@ pub fn updateComptimeNav(
1981 .union_type => {1981 .union_type => {
1982 const loaded_union = ip.loadUnionType(nav_val.toIntern());1982 const loaded_union = ip.loadUnionType(nav_val.toIntern());
1983 if (nav_index.toOptional() == loaded_union.name_nav) {1983 if (nav_index.toOptional() == loaded_union.name_nav) {
1984 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());1984 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1985 break :done;1985 break :done;
1986 }1986 }
1987 return;1987 return;
...@@ -1989,13 +1989,13 @@ pub fn updateComptimeNav(...@@ -1989,13 +1989,13 @@ pub fn updateComptimeNav(
1989 .opaque_type => {1989 .opaque_type => {
1990 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());1990 const loaded_opaque = ip.loadOpaqueType(nav_val.toIntern());
1991 if (nav_index.toOptional() == loaded_opaque.name_nav) {1991 if (nav_index.toOptional() == loaded_opaque.name_nav) {
1992 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());1992 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1993 break :done;1993 break :done;
1994 }1994 }
1995 return;1995 return;
1996 },1996 },
1997 .func => |func| if (func.owner_nav == nav_index and func.generic_owner == .none) {1997 .func => |func| if (func.owner_nav == nav_index and func.generic_owner == .none) {
1998 _ = try dwarf.const_pool.get(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? }, nav_val.toIntern());1998 _ = try dwarf.const_pool.get(pt, dwarf.constPoolUser(), nav_val.toIntern());
1999 break :done;1999 break :done;
2000 } else return,2000 } else return,
20012001
...@@ -2004,7 +2004,7 @@ pub fn updateComptimeNav(...@@ -2004,7 +2004,7 @@ pub fn updateComptimeNav(
2004 // memoization, not values2004 // memoization, not values
2005 .memoized_call => unreachable,2005 .memoized_call => unreachable,
2006 }2006 }
2007 try dwarf.const_pool.flushPending(pt, .{ .elf2 = dwarf.lf.cast(.elf2).? });2007 try dwarf.const_pool.flushPending(pt, dwarf.constPoolUser());
2008}2008}
20092009
2010pub fn addConst(2010pub fn addConst(
...@@ -2015,7 +2015,7 @@ pub fn addConst(...@@ -2015,7 +2015,7 @@ pub fn addConst(
2015 lf: *link.File,2015 lf: *link.File,
2016 ui: Unit.Index,2016 ui: Unit.Index,
2017 cpi: link.ConstPool.Index,2017 cpi: link.ConstPool.Index,
2018 ) link.Error!MappedFile.Node.Index,2018 ) link.Error!link.MappedFile.Node.Index,
2019) link.Error!void {2019) link.Error!void {
2020 const zcu = dwarf.lf.comp.zcu.?;2020 const zcu = dwarf.lf.comp.zcu.?;
2021 const ip = &zcu.intern_pool;2021 const ip = &zcu.intern_pool;
...@@ -2053,7 +2053,7 @@ pub fn addConst(...@@ -2053,7 +2053,7 @@ pub fn addConst(
2053pub fn updateConst(2053pub fn updateConst(
2054 dwarf: *Dwarf,2054 dwarf: *Dwarf,
2055 pt: Zcu.PerThread,2055 pt: Zcu.PerThread,
2056 di_nw: *MappedFile.Node.Writer,2056 di_nw: *link.MappedFile.Node.Writer,
2057 val: InternPool.Index,2057 val: InternPool.Index,
2058) link.Error!void {2058) link.Error!void {
2059 switch (val) {2059 switch (val) {
...@@ -2068,7 +2068,7 @@ pub fn updateConst(...@@ -2068,7 +2068,7 @@ pub fn updateConst(
2068fn updateConstInner(2068fn updateConstInner(
2069 dwarf: *Dwarf,2069 dwarf: *Dwarf,
2070 pt: Zcu.PerThread,2070 pt: Zcu.PerThread,
2071 di_nw: *MappedFile.Node.Writer,2071 di_nw: *link.MappedFile.Node.Writer,
2072 val: InternPool.Index,2072 val: InternPool.Index,
2073) link.EmitError!void {2073) link.EmitError!void {
2074 const zcu = pt.zcu;2074 const zcu = pt.zcu;
...@@ -2956,7 +2956,7 @@ fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { unpacked, opv_null, err...@@ -2956,7 +2956,7 @@ fn optRepr(opt_child_type: Type, zcu: *const Zcu) enum { unpacked, opv_null, err
2956pub fn updateConstIncomplete(2956pub fn updateConstIncomplete(
2957 dwarf: *Dwarf,2957 dwarf: *Dwarf,
2958 pt: Zcu.PerThread,2958 pt: Zcu.PerThread,
2959 di_nw: *MappedFile.Node.Writer,2959 di_nw: *link.MappedFile.Node.Writer,
2960 val: InternPool.Index,2960 val: InternPool.Index,
2961) link.Error!void {2961) link.Error!void {
2962 log.debug("updateConstIncomplete({f})", .{Value.fromInterned(val).fmtValue(pt)});2962 log.debug("updateConstIncomplete({f})", .{Value.fromInterned(val).fmtValue(pt)});
...@@ -2968,7 +2968,7 @@ pub fn updateConstIncomplete(...@@ -2968,7 +2968,7 @@ pub fn updateConstIncomplete(
2968fn updateConstIncompleteInner(2968fn updateConstIncompleteInner(
2969 dwarf: *Dwarf,2969 dwarf: *Dwarf,
2970 pt: Zcu.PerThread,2970 pt: Zcu.PerThread,
2971 di_nw: *MappedFile.Node.Writer,2971 di_nw: *link.MappedFile.Node.Writer,
2972 val: InternPool.Index,2972 val: InternPool.Index,
2973) link.EmitError!void {2973) link.EmitError!void {
2974 const zcu = pt.zcu;2974 const zcu = pt.zcu;
...@@ -3185,7 +3185,7 @@ fn updateConstIncompleteInner(...@@ -3185,7 +3185,7 @@ fn updateConstIncompleteInner(
3185fn genCaptures(3185fn genCaptures(
3186 dwarf: *Dwarf,3186 dwarf: *Dwarf,
3187 pt: Zcu.PerThread,3187 pt: Zcu.PerThread,
3188 di_nw: *MappedFile.Node.Writer,3188 di_nw: *link.MappedFile.Node.Writer,
3189 captures: anytype,3189 captures: anytype,
3190) link.EmitError!void {3190) link.EmitError!void {
3191 const zcu = pt.zcu;3191 const zcu = pt.zcu;
...@@ -3229,7 +3229,7 @@ fn genCaptures(...@@ -3229,7 +3229,7 @@ fn genCaptures(
3229pub fn genDecl(3229pub fn genDecl(
3230 dwarf: *Dwarf,3230 dwarf: *Dwarf,
3231 pt: Zcu.PerThread,3231 pt: Zcu.PerThread,
3232 di_nw: *MappedFile.Node.Writer,3232 di_nw: *link.MappedFile.Node.Writer,
3233 instance_val: InternPool.Index,3233 instance_val: InternPool.Index,
3234) link.Error!void {3234) link.Error!void {
3235 log.debug("genDecl({f})", .{Value.fromInterned(instance_val).fmtValue(pt)});3235 log.debug("genDecl({f})", .{Value.fromInterned(instance_val).fmtValue(pt)});
...@@ -3241,7 +3241,7 @@ pub fn genDecl(...@@ -3241,7 +3241,7 @@ pub fn genDecl(
3241fn genDeclInner(3241fn genDeclInner(
3242 dwarf: *Dwarf,3242 dwarf: *Dwarf,
3243 pt: Zcu.PerThread,3243 pt: Zcu.PerThread,
3244 di_nw: *MappedFile.Node.Writer,3244 di_nw: *link.MappedFile.Node.Writer,
3245 instance_val: InternPool.Index,3245 instance_val: InternPool.Index,
3246) link.EmitError!void {3246) link.EmitError!void {
3247 const zcu = pt.zcu;3247 const zcu = pt.zcu;
...@@ -3458,7 +3458,7 @@ fn genDeclInner(...@@ -3458,7 +3458,7 @@ fn genDeclInner(
34583458
3459pub fn updateLineNumber(3459pub fn updateLineNumber(
3460 dwarf: *Dwarf,3460 dwarf: *Dwarf,
3461 mf: *MappedFile,3461 mf: *link.MappedFile,
3462 inst: InternPool.TrackedInst.Index,3462 inst: InternPool.TrackedInst.Index,
3463 line: u32,3463 line: u32,
3464) void {3464) void {
...@@ -3472,7 +3472,7 @@ pub fn updateLineNumber(...@@ -3472,7 +3472,7 @@ pub fn updateLineNumber(
3472 );3472 );
3473}3473}
34743474
3475pub fn lostTracking(dwarf: *Dwarf, di_nw: *MappedFile.Node.Writer) link.EmitError!void {3475pub fn lostTracking(dwarf: *Dwarf, di_nw: *link.MappedFile.Node.Writer) link.EmitError!void {
3476 try dwarf.abbrevCode(di_nw, .decl_lost);3476 try dwarf.abbrevCode(di_nw, .decl_lost);
3477}3477}
34783478
...@@ -3485,14 +3485,14 @@ fn refAbbrevCodeIfExists(...@@ -3485,14 +3485,14 @@ fn refAbbrevCodeIfExists(
3485}3485}
3486fn refAbbrevCode(3486fn refAbbrevCode(
3487 dwarf: *Dwarf,3487 dwarf: *Dwarf,
3488 mf: *MappedFile,3488 mf: *link.MappedFile,
3489 abbrev_code: AbbrevCode,3489 abbrev_code: AbbrevCode,
3490) link.Error!@typeInfo(AbbrevCode).@"enum".tag_type {3490) link.Error!@typeInfo(AbbrevCode).@"enum".tag_type {
3491 if (dwarf.refAbbrevCodeIfExists(abbrev_code)) |backing_int| {3491 if (dwarf.refAbbrevCodeIfExists(abbrev_code)) |backing_int| {
3492 @branchHint(.likely);3492 @branchHint(.likely);
3493 return backing_int;3493 return backing_int;
3494 }3494 }
3495 var da_nw: MappedFile.Node.Writer = undefined;3495 var da_nw: link.MappedFile.Node.Writer = undefined;
3496 dwarf.debug_abbrev.ni.unwrap().?.writer(dwarf.lf.comp.gpa, mf, &da_nw);3496 dwarf.debug_abbrev.ni.unwrap().?.writer(dwarf.lf.comp.gpa, mf, &da_nw);
3497 defer da_nw.deinit();3497 defer da_nw.deinit();
3498 dwarf.genDebugAbbrev(&da_nw, abbrev_code) catch |err| switch (err) {3498 dwarf.genDebugAbbrev(&da_nw, abbrev_code) catch |err| switch (err) {
...@@ -3504,7 +3504,7 @@ fn refAbbrevCode(...@@ -3504,7 +3504,7 @@ fn refAbbrevCode(
3504}3504}
3505fn abbrevCode(3505fn abbrevCode(
3506 dwarf: *Dwarf,3506 dwarf: *Dwarf,
3507 nw: *MappedFile.Node.Writer,3507 nw: *link.MappedFile.Node.Writer,
3508 abbrev_code: AbbrevCode,3508 abbrev_code: AbbrevCode,
3509) link.EmitError!void {3509) link.EmitError!void {
3510 try nw.interface.writeUleb128(try dwarf.refAbbrevCode(nw.mf, abbrev_code));3510 try nw.interface.writeUleb128(try dwarf.refAbbrevCode(nw.mf, abbrev_code));
...@@ -3512,7 +3512,7 @@ fn abbrevCode(...@@ -3512,7 +3512,7 @@ fn abbrevCode(
35123512
3513fn genDebugAbbrev(3513fn genDebugAbbrev(
3514 dwarf: *Dwarf,3514 dwarf: *Dwarf,
3515 da_nw: *MappedFile.Node.Writer,3515 da_nw: *link.MappedFile.Node.Writer,
3516 abbrev_code: AbbrevCode,3516 abbrev_code: AbbrevCode,
3517) link.EmitError!void {3517) link.EmitError!void {
3518 const abbrev = AbbrevCode.abbrevs.get(abbrev_code);3518 const abbrev = AbbrevCode.abbrevs.get(abbrev_code);
...@@ -3543,8 +3543,8 @@ fn secOffsetPlaceholder(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!vo...@@ -3543,8 +3543,8 @@ fn secOffsetPlaceholder(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!vo
3543}3543}
3544fn secOffset(3544fn secOffset(
3545 dwarf: *Dwarf,3545 dwarf: *Dwarf,
3546 nw: *MappedFile.Node.Writer,3546 nw: *link.MappedFile.Node.Writer,
3547 target_ni: MappedFile.Node.Index,3547 target_ni: link.MappedFile.Node.Index,
3548 addend: usize,3548 addend: usize,
3549) link.EmitError!void {3549) link.EmitError!void {
3550 const offset = nw.interface.end;3550 const offset = nw.interface.end;
...@@ -3566,7 +3566,7 @@ fn addrPlaceholder(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {...@@ -3566,7 +3566,7 @@ fn addrPlaceholder(dwarf: *Dwarf, w: *std.Io.Writer) std.Io.Writer.Error!void {
3566}3566}
3567fn addrSym(3567fn addrSym(
3568 dwarf: *Dwarf,3568 dwarf: *Dwarf,
3569 nw: *MappedFile.Node.Writer,3569 nw: *link.MappedFile.Node.Writer,
3570 target_si: link.File.SymbolId,3570 target_si: link.File.SymbolId,
3571 addend: usize,3571 addend: usize,
3572) link.EmitError!void {3572) link.EmitError!void {
...@@ -3584,7 +3584,7 @@ fn addrSym(...@@ -3584,7 +3584,7 @@ fn addrSym(
3584fn blockConst(3584fn blockConst(
3585 dwarf: *Dwarf,3585 dwarf: *Dwarf,
3586 pt: Zcu.PerThread,3586 pt: Zcu.PerThread,
3587 nw: *MappedFile.Node.Writer,3587 nw: *link.MappedFile.Node.Writer,
3588 val: Value,3588 val: Value,
3589) link.EmitError!void {3589) link.EmitError!void {
3590 const ty = val.typeOf(pt.zcu);3590 const ty = val.typeOf(pt.zcu);
...@@ -3604,7 +3604,7 @@ fn blockConst(...@@ -3604,7 +3604,7 @@ fn blockConst(
3604fn refType(3604fn refType(
3605 dwarf: *Dwarf,3605 dwarf: *Dwarf,
3606 pt: Zcu.PerThread,3606 pt: Zcu.PerThread,
3607 nw: *MappedFile.Node.Writer,3607 nw: *link.MappedFile.Node.Writer,
3608 ty: Type,3608 ty: Type,
3609) link.EmitError!void {3609) link.EmitError!void {
3610 return dwarf.refConst(pt, nw, ty.toValue());3610 return dwarf.refConst(pt, nw, ty.toValue());
...@@ -3612,7 +3612,7 @@ fn refType(...@@ -3612,7 +3612,7 @@ fn refType(
3612fn refConst(3612fn refConst(
3613 dwarf: *Dwarf,3613 dwarf: *Dwarf,
3614 pt: Zcu.PerThread,3614 pt: Zcu.PerThread,
3615 nw: *MappedFile.Node.Writer,3615 nw: *link.MappedFile.Node.Writer,
3616 val: Value,3616 val: Value,
3617) link.EmitError!void {3617) link.EmitError!void {
3618 try dwarf.secOffset(nw, Const.get(try dwarf.getConst(pt, val), dwarf).debug_info_ni.unwrap().?, 0);3618 try dwarf.secOffset(nw, Const.get(try dwarf.getConst(pt, val), dwarf).debug_info_ni.unwrap().?, 0);
...@@ -3685,7 +3685,7 @@ fn enumConstValue(...@@ -3685,7 +3685,7 @@ fn enumConstValue(
3685 );3685 );
3686}3686}
36873687
3688fn exprLoc(dwarf: *Dwarf, nw: *MappedFile.Node.Writer, loc: Loc) link.EmitError!void {3688fn exprLoc(dwarf: *Dwarf, nw: *link.MappedFile.Node.Writer, loc: Loc) link.EmitError!void {
3689 var buf: [@max(8, std.atomic.cache_line)]u8 = undefined;3689 var buf: [@max(8, std.atomic.cache_line)]u8 = undefined;
3690 var dw: std.Io.Writer.Discarding = .init(&buf);3690 var dw: std.Io.Writer.Discarding = .init(&buf);
3691 try loc.write(.{ .io = &dw.writer }, dwarf);3691 try loc.write(.{ .io = &dw.writer }, dwarf);
...@@ -3694,7 +3694,7 @@ fn exprLoc(dwarf: *Dwarf, nw: *MappedFile.Node.Writer, loc: Loc) link.EmitError!...@@ -3694,7 +3694,7 @@ fn exprLoc(dwarf: *Dwarf, nw: *MappedFile.Node.Writer, loc: Loc) link.EmitError!
3694 try loc.write(.{ .mf = nw }, dwarf);3694 try loc.write(.{ .mf = nw }, dwarf);
3695}3695}
36963696
3697fn strp(dwarf: *Dwarf, s: *Str, nw: *MappedFile.Node.Writer, str: []const u8) link.EmitError!void {3697fn strp(dwarf: *Dwarf, s: *Str, nw: *link.MappedFile.Node.Writer, str: []const u8) link.EmitError!void {
3698 const comp = dwarf.lf.comp;3698 const comp = dwarf.lf.comp;
3699 try dwarf.secOffset(nw, s.ni.unwrap().?, s.get(comp.gpa, nw.mf, str) catch |err| switch (err) {3699 try dwarf.secOffset(nw, s.ni.unwrap().?, s.get(comp.gpa, nw.mf, str) catch |err| switch (err) {
3700 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{3700 error.MappedFileIo => return comp.link_diags.fail("failed to write output file: {t}", .{
...@@ -3704,7 +3704,7 @@ fn strp(dwarf: *Dwarf, s: *Str, nw: *MappedFile.Node.Writer, str: []const u8) li...@@ -3704,7 +3704,7 @@ fn strp(dwarf: *Dwarf, s: *Str, nw: *MappedFile.Node.Writer, str: []const u8) li
3704 });3704 });
3705}3705}
37063706
3707fn reportWriteError(dwarf: *Dwarf, nw: *const MappedFile.Node.Writer) link.Error {3707fn reportWriteError(dwarf: *Dwarf, nw: *const link.MappedFile.Node.Writer) link.Error {
3708 switch (nw.err.?) {3708 switch (nw.err.?) {
3709 else => |e| return e,3709 else => |e| return e,
3710 error.MappedFileIo => return dwarf.lf.comp.link_diags.fail(3710 error.MappedFileIo => return dwarf.lf.comp.link_diags.fail(
...@@ -3714,6 +3714,12 @@ fn reportWriteError(dwarf: *Dwarf, nw: *const MappedFile.Node.Writer) link.Error...@@ -3714,6 +3714,12 @@ fn reportWriteError(dwarf: *Dwarf, nw: *const MappedFile.Node.Writer) link.Error
3714 }3714 }
3715}3715}
37163716
3717fn constPoolUser(dwarf: *Dwarf) link.ConstPool.User {
3718 return if (dwarf.lf.cast(.elf2)) |elf| .{
3719 .elf2 = elf,
3720 } else unreachable;
3721}
3722
3717fn DeclValEnum(comptime T: type) type {3723fn DeclValEnum(comptime T: type) type {
3718 const decl_names = @typeInfo(T).@"struct".decl_names;3724 const decl_names = @typeInfo(T).@"struct".decl_names;
3719 @setEvalBranchQuota(10 * decl_names.len);3725 @setEvalBranchQuota(10 * decl_names.len);
...@@ -5239,7 +5245,6 @@ const Dwarf = @This();...@@ -5239,7 +5245,6 @@ const Dwarf = @This();
5239const InternPool = @import("../InternPool.zig");5245const InternPool = @import("../InternPool.zig");
5240const link = @import("../link.zig");5246const link = @import("../link.zig");
5241const log = std.log.scoped(.dwarf);5247const log = std.log.scoped(.dwarf);
5242const MappedFile = @import("MappedFile.zig");
5243const Module = @import("../Module.zig");5248const Module = @import("../Module.zig");
5244const std = @import("std");5249const std = @import("std");
5245const target_info = @import("../target.zig");5250const target_info = @import("../target.zig");
src/link/Elf.zig-1
...@@ -4410,7 +4410,6 @@ const Path = std.Build.Cache.Path;...@@ -4410,7 +4410,6 @@ const Path = std.Build.Cache.Path;
4410const Stat = std.Build.Cache.File.Stat;4410const Stat = std.Build.Cache.File.Stat;
44114411
4412const codegen = @import("../codegen.zig");4412const codegen = @import("../codegen.zig");
4413const dev = @import("../dev.zig");
4414const eh_frame = @import("Elf/eh_frame.zig");4413const eh_frame = @import("Elf/eh_frame.zig");
4415const gc = @import("Elf/gc.zig");4414const gc = @import("Elf/gc.zig");
4416const musl = @import("../libs/musl.zig");4415const musl = @import("../libs/musl.zig");
src/link/Elf/Atom.zig+17-11
...@@ -945,7 +945,7 @@ const x86_64 = struct {...@@ -945,7 +945,7 @@ const x86_64 = struct {
945 code: ?[]const u8,945 code: ?[]const u8,
946 it: *RelocsIterator,946 it: *RelocsIterator,
947 ) !void {947 ) !void {
948 dev.check(.x86_64_backend);948 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
949 const t = &elf_file.base.comp.root_mod.resolved_target.result;949 const t = &elf_file.base.comp.root_mod.resolved_target.result;
950 const is_static = elf_file.base.isStatic();950 const is_static = elf_file.base.isStatic();
951 const is_dyn_lib = elf_file.isEffectivelyDynLib();951 const is_dyn_lib = elf_file.isEffectivelyDynLib();
...@@ -1059,7 +1059,7 @@ const x86_64 = struct {...@@ -1059,7 +1059,7 @@ const x86_64 = struct {
1059 it: *RelocsIterator,1059 it: *RelocsIterator,
1060 code: []u8,1060 code: []u8,
1061 ) !void {1061 ) !void {
1062 dev.check(.x86_64_backend);1062 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1063 const t = &elf_file.base.comp.root_mod.resolved_target.result;1063 const t = &elf_file.base.comp.root_mod.resolved_target.result;
1064 const diags = &elf_file.base.comp.link_diags;1064 const diags = &elf_file.base.comp.link_diags;
1065 const r_type: elf.R_X86_64 = @fromBackingInt(@intCast(rel.r_type()));1065 const r_type: elf.R_X86_64 = @fromBackingInt(@intCast(rel.r_type()));
...@@ -1200,7 +1200,7 @@ const x86_64 = struct {...@@ -1200,7 +1200,7 @@ const x86_64 = struct {
1200 args: ResolveArgs,1200 args: ResolveArgs,
1201 code: []u8,1201 code: []u8,
1202 ) !void {1202 ) !void {
1203 dev.check(.x86_64_backend);1203 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1204 const r_type: elf.R_X86_64 = @fromBackingInt(@intCast(rel.r_type()));1204 const r_type: elf.R_X86_64 = @fromBackingInt(@intCast(rel.r_type()));
12051205
1206 _, const A, const S, const GOT, _, _, const DTP = args;1206 _, const A, const S, const GOT, _, _, const DTP = args;
...@@ -1240,7 +1240,7 @@ const x86_64 = struct {...@@ -1240,7 +1240,7 @@ const x86_64 = struct {
1240 }1240 }
12411241
1242 fn relaxGotpcrelx(code: []u8, t: *const std.Target) !void {1242 fn relaxGotpcrelx(code: []u8, t: *const std.Target) !void {
1243 dev.check(.x86_64_backend);1243 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1244 const old_inst = disassemble(code) orelse return error.RelaxFailure;1244 const old_inst = disassemble(code) orelse return error.RelaxFailure;
1245 const inst: Instruction = switch (old_inst.encoding.mnemonic) {1245 const inst: Instruction = switch (old_inst.encoding.mnemonic) {
1246 .call => try .new(old_inst.prefix, .call, &.{1246 .call => try .new(old_inst.prefix, .call, &.{
...@@ -1259,7 +1259,7 @@ const x86_64 = struct {...@@ -1259,7 +1259,7 @@ const x86_64 = struct {
1259 }1259 }
12601260
1261 fn relaxRexGotpcrelx(code: []u8, t: *const std.Target) !void {1261 fn relaxRexGotpcrelx(code: []u8, t: *const std.Target) !void {
1262 dev.check(.x86_64_backend);1262 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1263 const old_inst = disassemble(code) orelse return error.RelaxFailure;1263 const old_inst = disassemble(code) orelse return error.RelaxFailure;
1264 switch (old_inst.encoding.mnemonic) {1264 switch (old_inst.encoding.mnemonic) {
1265 .mov => {1265 .mov => {
...@@ -1279,7 +1279,7 @@ const x86_64 = struct {...@@ -1279,7 +1279,7 @@ const x86_64 = struct {
1279 code: []u8,1279 code: []u8,
1280 r_offset: usize,1280 r_offset: usize,
1281 ) !void {1281 ) !void {
1282 dev.check(.x86_64_backend);1282 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1283 assert(rels.len == 2);1283 assert(rels.len == 2);
1284 const diags = &elf_file.base.comp.link_diags;1284 const diags = &elf_file.base.comp.link_diags;
1285 const rel: elf.R_X86_64 = @fromBackingInt(@intCast(rels[1].r_type()));1285 const rel: elf.R_X86_64 = @fromBackingInt(@intCast(rels[1].r_type()));
...@@ -1319,7 +1319,7 @@ const x86_64 = struct {...@@ -1319,7 +1319,7 @@ const x86_64 = struct {
1319 code: []u8,1319 code: []u8,
1320 r_offset: usize,1320 r_offset: usize,
1321 ) !void {1321 ) !void {
1322 dev.check(.x86_64_backend);1322 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1323 assert(rels.len == 2);1323 assert(rels.len == 2);
1324 const diags = &elf_file.base.comp.link_diags;1324 const diags = &elf_file.base.comp.link_diags;
1325 const rel: elf.R_X86_64 = @fromBackingInt(@intCast(rels[1].r_type()));1325 const rel: elf.R_X86_64 = @fromBackingInt(@intCast(rels[1].r_type()));
...@@ -1366,7 +1366,7 @@ const x86_64 = struct {...@@ -1366,7 +1366,7 @@ const x86_64 = struct {
1366 }1366 }
13671367
1368 fn canRelaxGotTpOff(code: []const u8, t: *const std.Target) bool {1368 fn canRelaxGotTpOff(code: []const u8, t: *const std.Target) bool {
1369 dev.check(.x86_64_backend);1369 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1370 const old_inst = disassemble(code) orelse return false;1370 const old_inst = disassemble(code) orelse return false;
1371 switch (old_inst.encoding.mnemonic) {1371 switch (old_inst.encoding.mnemonic) {
1372 .mov => {1372 .mov => {
...@@ -1384,7 +1384,7 @@ const x86_64 = struct {...@@ -1384,7 +1384,7 @@ const x86_64 = struct {
1384 }1384 }
13851385
1386 fn relaxGotTpOff(code: []u8, t: *const std.Target) void {1386 fn relaxGotTpOff(code: []u8, t: *const std.Target) void {
1387 dev.check(.x86_64_backend);1387 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1388 const old_inst = disassemble(code) orelse unreachable;1388 const old_inst = disassemble(code) orelse unreachable;
1389 switch (old_inst.encoding.mnemonic) {1389 switch (old_inst.encoding.mnemonic) {
1390 .mov => {1390 .mov => {
...@@ -1401,7 +1401,7 @@ const x86_64 = struct {...@@ -1401,7 +1401,7 @@ const x86_64 = struct {
1401 }1401 }
14021402
1403 fn relaxGotPcTlsDesc(code: []u8, target: *const std.Target) !void {1403 fn relaxGotPcTlsDesc(code: []u8, target: *const std.Target) !void {
1404 dev.check(.x86_64_backend);1404 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1405 const old_inst = disassemble(code) orelse return error.RelaxFailure;1405 const old_inst = disassemble(code) orelse return error.RelaxFailure;
1406 switch (old_inst.encoding.mnemonic) {1406 switch (old_inst.encoding.mnemonic) {
1407 .lea => {1407 .lea => {
...@@ -1425,7 +1425,7 @@ const x86_64 = struct {...@@ -1425,7 +1425,7 @@ const x86_64 = struct {
1425 code: []u8,1425 code: []u8,
1426 r_offset: usize,1426 r_offset: usize,
1427 ) !void {1427 ) !void {
1428 dev.check(.x86_64_backend);1428 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1429 assert(rels.len == 2);1429 assert(rels.len == 2);
1430 const diags = &elf_file.base.comp.link_diags;1430 const diags = &elf_file.base.comp.link_diags;
1431 const rel: elf.R_X86_64 = @fromBackingInt(@intCast(rels[1].r_type()));1431 const rel: elf.R_X86_64 = @fromBackingInt(@intCast(rels[1].r_type()));
...@@ -1492,6 +1492,7 @@ const aarch64 = struct {...@@ -1492,6 +1492,7 @@ const aarch64 = struct {
1492 ) !void {1492 ) !void {
1493 _ = code;1493 _ = code;
1494 _ = it;1494 _ = it;
1495 dev.checkAny(&.{ .llvm_backend, .aarch64_backend });
14951496
1496 const r_type: elf.R_AARCH64 = @fromBackingInt(@intCast(rel.r_type()));1497 const r_type: elf.R_AARCH64 = @fromBackingInt(@intCast(rel.r_type()));
1497 const is_dyn_lib = elf_file.isEffectivelyDynLib();1498 const is_dyn_lib = elf_file.isEffectivelyDynLib();
...@@ -1569,6 +1570,7 @@ const aarch64 = struct {...@@ -1569,6 +1570,7 @@ const aarch64 = struct {
1569 code_buffer: []u8,1570 code_buffer: []u8,
1570 ) (error{ UnexpectedRemainder, DivisionByZero } || RelocError)!void {1571 ) (error{ UnexpectedRemainder, DivisionByZero } || RelocError)!void {
1571 _ = it;1572 _ = it;
1573 dev.checkAny(&.{ .llvm_backend, .aarch64_backend });
15721574
1573 const diags = &elf_file.base.comp.link_diags;1575 const diags = &elf_file.base.comp.link_diags;
1574 const r_type: elf.R_AARCH64 = @fromBackingInt(@intCast(rel.r_type()));1576 const r_type: elf.R_AARCH64 = @fromBackingInt(@intCast(rel.r_type()));
...@@ -1742,6 +1744,7 @@ const aarch64 = struct {...@@ -1742,6 +1744,7 @@ const aarch64 = struct {
1742 args: ResolveArgs,1744 args: ResolveArgs,
1743 code: []u8,1745 code: []u8,
1744 ) !void {1746 ) !void {
1747 dev.checkAny(&.{ .llvm_backend, .aarch64_backend });
1745 const r_type: elf.R_AARCH64 = @fromBackingInt(@intCast(rel.r_type()));1748 const r_type: elf.R_AARCH64 = @fromBackingInt(@intCast(rel.r_type()));
17461749
1747 _, const A, const S, _, _, _, _ = args;1750 _, const A, const S, _, _, _, _ = args;
...@@ -1772,6 +1775,7 @@ const riscv = struct {...@@ -1772,6 +1775,7 @@ const riscv = struct {
1772 ) !void {1775 ) !void {
1773 _ = code;1776 _ = code;
1774 _ = it;1777 _ = it;
1778 dev.checkAny(&.{ .llvm_backend, .riscv64_backend });
17751779
1776 const r_type: elf.R_RISCV = @fromBackingInt(@intCast(rel.r_type()));1780 const r_type: elf.R_RISCV = @fromBackingInt(@intCast(rel.r_type()));
17771781
...@@ -1815,6 +1819,7 @@ const riscv = struct {...@@ -1815,6 +1819,7 @@ const riscv = struct {
1815 it: *RelocsIterator,1819 it: *RelocsIterator,
1816 code: []u8,1820 code: []u8,
1817 ) !void {1821 ) !void {
1822 dev.checkAny(&.{ .llvm_backend, .riscv64_backend });
1818 const diags = &elf_file.base.comp.link_diags;1823 const diags = &elf_file.base.comp.link_diags;
1819 const r_type: elf.R_RISCV = @fromBackingInt(@intCast(rel.r_type()));1824 const r_type: elf.R_RISCV = @fromBackingInt(@intCast(rel.r_type()));
1820 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;1825 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;
...@@ -1951,6 +1956,7 @@ const riscv = struct {...@@ -1951,6 +1956,7 @@ const riscv = struct {
1951 args: ResolveArgs,1956 args: ResolveArgs,
1952 code: []u8,1957 code: []u8,
1953 ) !void {1958 ) !void {
1959 dev.checkAny(&.{ .llvm_backend, .riscv64_backend });
1954 const r_type: elf.R_RISCV = @fromBackingInt(@intCast(rel.r_type()));1960 const r_type: elf.R_RISCV = @fromBackingInt(@intCast(rel.r_type()));
19551961
1956 _, const A, const S, const GOT, _, _, const DTP = args;1962 _, const A, const S, const GOT, _, _, const DTP = args;
src/link/Elf/Thunk.zig+2
...@@ -91,6 +91,7 @@ pub const Index = u32;...@@ -91,6 +91,7 @@ pub const Index = u32;
9191
92const aarch64 = struct {92const aarch64 = struct {
93 fn write(thunk: Thunk, elf_file: *Elf, writer: anytype) !void {93 fn write(thunk: Thunk, elf_file: *Elf, writer: anytype) !void {
94 dev.checkAny(&.{ .llvm_backend, .aarch64_backend });
94 for (thunk.symbols.keys(), 0..) |ref, i| {95 for (thunk.symbols.keys(), 0..) |ref, i| {
95 const sym = elf_file.symbol(ref).?;96 const sym = elf_file.symbol(ref).?;
96 const saddr = thunk.address(elf_file) + @as(i64, @intCast(i * trampoline_size));97 const saddr = thunk.address(elf_file) + @as(i64, @intCast(i * trampoline_size));
...@@ -113,6 +114,7 @@ const aarch64 = struct {...@@ -113,6 +114,7 @@ const aarch64 = struct {
113};114};
114115
115const assert = std.debug.assert;116const assert = std.debug.assert;
117const dev = @import("../../dev.zig");
116const elf = std.elf;118const elf = std.elf;
117const log = std.log.scoped(.link);119const log = std.log.scoped(.link);
118const math = std.math;120const math = std.math;
src/link/Elf/ZigObject.zig+2
...@@ -2396,6 +2396,7 @@ const TlsTable = std.array_hash_map.Auto(Atom.Index, void);...@@ -2396,6 +2396,7 @@ const TlsTable = std.array_hash_map.Auto(Atom.Index, void);
23962396
2397const x86_64 = struct {2397const x86_64 = struct {
2398 fn writeTrampolineCode(source_addr: i64, target_addr: i64, buf: *[max_trampoline_len]u8) ![]u8 {2398 fn writeTrampolineCode(source_addr: i64, target_addr: i64, buf: *[max_trampoline_len]u8) ![]u8 {
2399 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
2399 const disp = @as(i64, @intCast(target_addr)) - source_addr - 5;2400 const disp = @as(i64, @intCast(target_addr)) - source_addr - 5;
2400 var bytes = [_]u8{2401 var bytes = [_]u8{
2401 0xe9, 0x00, 0x00, 0x00, 0x00, // jmp rel322402 0xe9, 0x00, 0x00, 0x00, 0x00, // jmp rel32
...@@ -2411,6 +2412,7 @@ const assert = std.debug.assert;...@@ -2411,6 +2412,7 @@ const assert = std.debug.assert;
2411const build_options = @import("build_options");2412const build_options = @import("build_options");
2412const builtin = @import("builtin");2413const builtin = @import("builtin");
2413const codegen = @import("../../codegen.zig");2414const codegen = @import("../../codegen.zig");
2415const dev = @import("../../dev.zig");
2414const elf = std.elf;2416const elf = std.elf;
2415const link = @import("../../link.zig");2417const link = @import("../../link.zig");
2416const log = std.log.scoped(.link);2418const log = std.log.scoped(.link);
src/link/Elf/eh_frame.zig+4
...@@ -535,6 +535,7 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {...@@ -535,6 +535,7 @@ pub fn writeEhFrameHdr(elf_file: *Elf, writer: anytype) !void {
535535
536const x86_64 = struct {536const x86_64 = struct {
537 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {537 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {
538 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
538 const r_type: elf.R_X86_64 = @fromBackingInt(@intCast(rel.r_type()));539 const r_type: elf.R_X86_64 = @fromBackingInt(@intCast(rel.r_type()));
539 switch (r_type) {540 switch (r_type) {
540 .NONE => {},541 .NONE => {},
...@@ -549,6 +550,7 @@ const x86_64 = struct {...@@ -549,6 +550,7 @@ const x86_64 = struct {
549550
550const aarch64 = struct {551const aarch64 = struct {
551 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {552 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {
553 dev.checkAny(&.{ .llvm_backend, .aarch64_backend });
552 const r_type: elf.R_AARCH64 = @fromBackingInt(@intCast(rel.r_type()));554 const r_type: elf.R_AARCH64 = @fromBackingInt(@intCast(rel.r_type()));
553 switch (r_type) {555 switch (r_type) {
554 .NONE => {},556 .NONE => {},
...@@ -562,6 +564,7 @@ const aarch64 = struct {...@@ -562,6 +564,7 @@ const aarch64 = struct {
562564
563const riscv = struct {565const riscv = struct {
564 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {566 fn resolveReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela, source: i64, target: i64, data: []u8) !void {
567 dev.checkAny(&.{ .llvm_backend, .riscv64_backend });
565 const r_type: elf.R_RISCV = @fromBackingInt(@intCast(rel.r_type()));568 const r_type: elf.R_RISCV = @fromBackingInt(@intCast(rel.r_type()));
566 switch (r_type) {569 switch (r_type) {
567 .NONE => {},570 .NONE => {},
...@@ -584,6 +587,7 @@ fn reportInvalidReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela) !void {...@@ -584,6 +587,7 @@ fn reportInvalidReloc(rec: anytype, elf_file: *Elf, rel: elf.Elf64_Rela) !void {
584587
585const std = @import("std");588const std = @import("std");
586const assert = std.debug.assert;589const assert = std.debug.assert;
590const dev = @import("../../dev.zig");
587const elf = std.elf;591const elf = std.elf;
588const math = std.math;592const math = std.math;
589const relocs_log = std.log.scoped(.link_relocs);593const relocs_log = std.log.scoped(.link_relocs);
src/link/Elf/synthetic_sections.zig+5
...@@ -772,6 +772,7 @@ pub const PltSection = struct {...@@ -772,6 +772,7 @@ pub const PltSection = struct {
772772
773 const x86_64 = struct {773 const x86_64 = struct {
774 fn write(plt: PltSection, elf_file: *Elf, writer: *std.Io.Writer) !void {774 fn write(plt: PltSection, elf_file: *Elf, writer: *std.Io.Writer) !void {
775 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
775 const shdrs = elf_file.sections.items(.shdr);776 const shdrs = elf_file.sections.items(.shdr);
776 const plt_addr = shdrs[elf_file.section_indexes.plt.?].sh_addr;777 const plt_addr = shdrs[elf_file.section_indexes.plt.?].sh_addr;
777 const got_plt_addr = shdrs[elf_file.section_indexes.got_plt.?].sh_addr;778 const got_plt_addr = shdrs[elf_file.section_indexes.got_plt.?].sh_addr;
...@@ -807,6 +808,7 @@ pub const PltSection = struct {...@@ -807,6 +808,7 @@ pub const PltSection = struct {
807808
808 const aarch64 = struct {809 const aarch64 = struct {
809 fn write(plt: PltSection, elf_file: *Elf, writer: *std.Io.Writer) !void {810 fn write(plt: PltSection, elf_file: *Elf, writer: *std.Io.Writer) !void {
811 dev.checkAny(&.{ .llvm_backend, .aarch64_backend });
810 {812 {
811 const shdrs = elf_file.sections.items(.shdr);813 const shdrs = elf_file.sections.items(.shdr);
812 const plt_addr: i64 = @intCast(shdrs[elf_file.section_indexes.plt.?].sh_addr);814 const plt_addr: i64 = @intCast(shdrs[elf_file.section_indexes.plt.?].sh_addr);
...@@ -949,6 +951,7 @@ pub const PltGotSection = struct {...@@ -949,6 +951,7 @@ pub const PltGotSection = struct {
949951
950 const x86_64 = struct {952 const x86_64 = struct {
951 pub fn write(plt_got: PltGotSection, elf_file: *Elf, writer: *std.Io.Writer) !void {953 pub fn write(plt_got: PltGotSection, elf_file: *Elf, writer: *std.Io.Writer) !void {
954 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
952 for (plt_got.symbols.items) |ref| {955 for (plt_got.symbols.items) |ref| {
953 const sym = elf_file.symbol(ref).?;956 const sym = elf_file.symbol(ref).?;
954 const target_addr = sym.gotAddress(elf_file);957 const target_addr = sym.gotAddress(elf_file);
...@@ -967,6 +970,7 @@ pub const PltGotSection = struct {...@@ -967,6 +970,7 @@ pub const PltGotSection = struct {
967970
968 const aarch64 = struct {971 const aarch64 = struct {
969 fn write(plt_got: PltGotSection, elf_file: *Elf, writer: *std.Io.Writer) !void {972 fn write(plt_got: PltGotSection, elf_file: *Elf, writer: *std.Io.Writer) !void {
973 dev.checkAny(&.{ .llvm_backend, .aarch64_backend });
970 for (plt_got.symbols.items) |ref| {974 for (plt_got.symbols.items) |ref| {
971 const sym = elf_file.symbol(ref).?;975 const sym = elf_file.symbol(ref).?;
972 const target_addr = sym.gotAddress(elf_file);976 const target_addr = sym.gotAddress(elf_file);
...@@ -1518,6 +1522,7 @@ fn writeInt(value: anytype, elf_file: *Elf, writer: *std.Io.Writer) !void {...@@ -1518,6 +1522,7 @@ fn writeInt(value: anytype, elf_file: *Elf, writer: *std.Io.Writer) !void {
15181522
1519const assert = std.debug.assert;1523const assert = std.debug.assert;
1520const builtin = @import("builtin");1524const builtin = @import("builtin");
1525const dev = @import("../../dev.zig");
1521const elf = std.elf;1526const elf = std.elf;
1522const math = std.math;1527const math = std.math;
1523const mem = std.mem;1528const mem = std.mem;
src/link/Elf2.zig+1-2
...@@ -7,11 +7,10 @@ const log = std.log.scoped(.link);...@@ -7,11 +7,10 @@ const log = std.log.scoped(.link);
77
8const codegen = @import("../codegen.zig");8const codegen = @import("../codegen.zig");
9const Compilation = @import("../Compilation.zig");9const Compilation = @import("../Compilation.zig");
10const dev = @import("../dev.zig");
11const Dwarf = @import("Dwarf2.zig");10const Dwarf = @import("Dwarf2.zig");
12const InternPool = @import("../InternPool.zig");11const InternPool = @import("../InternPool.zig");
13const link = @import("../link.zig");12const link = @import("../link.zig");
14const MappedFile = @import("MappedFile.zig");13const MappedFile = link.MappedFile;
15const target_util = @import("../target.zig");14const target_util = @import("../target.zig");
16const tracy = @import("../tracy.zig");15const tracy = @import("../tracy.zig");
17const Type = @import("../Type.zig");16const Type = @import("../Type.zig");
src/link/MachO.zig-1
...@@ -5503,4 +5503,3 @@ const Value = @import("../Value.zig");...@@ -5503,4 +5503,3 @@ const Value = @import("../Value.zig");
5503const UnwindInfo = @import("MachO/UnwindInfo.zig");5503const UnwindInfo = @import("MachO/UnwindInfo.zig");
5504const WeakBind = bind.WeakBind;5504const WeakBind = bind.WeakBind;
5505const ZigObject = @import("MachO/ZigObject.zig");5505const ZigObject = @import("MachO/ZigObject.zig");
5506const dev = @import("../dev.zig");
src/link/MachO/Atom.zig+2-2
...@@ -853,7 +853,7 @@ fn resolveRelocInner(...@@ -853,7 +853,7 @@ fn resolveRelocInner(
853853
854const x86_64 = struct {854const x86_64 = struct {
855 fn relaxGotLoad(self: Atom, code: []u8, rel: Relocation, macho_file: *MachO) ResolveError!void {855 fn relaxGotLoad(self: Atom, code: []u8, rel: Relocation, macho_file: *MachO) ResolveError!void {
856 dev.check(.x86_64_backend);856 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
857 const t = &macho_file.base.comp.root_mod.resolved_target.result;857 const t = &macho_file.base.comp.root_mod.resolved_target.result;
858 const diags = &macho_file.base.comp.link_diags;858 const diags = &macho_file.base.comp.link_diags;
859 const old_inst = disassemble(code) orelse return error.RelaxFail;859 const old_inst = disassemble(code) orelse return error.RelaxFail;
...@@ -879,7 +879,7 @@ const x86_64 = struct {...@@ -879,7 +879,7 @@ const x86_64 = struct {
879 }879 }
880880
881 fn relaxTlv(code: []u8, t: *const std.Target) error{RelaxFail}!void {881 fn relaxTlv(code: []u8, t: *const std.Target) error{RelaxFail}!void {
882 dev.check(.x86_64_backend);882 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
883 const old_inst = disassemble(code) orelse return error.RelaxFail;883 const old_inst = disassemble(code) orelse return error.RelaxFail;
884 switch (old_inst.encoding.mnemonic) {884 switch (old_inst.encoding.mnemonic) {
885 .mov => {885 .mov => {
src/link/MachO/Object.zig+5
...@@ -3,6 +3,7 @@ const Object = @This();...@@ -3,6 +3,7 @@ const Object = @This();
3const trace = @import("../../tracy.zig").trace;3const trace = @import("../../tracy.zig").trace;
4const Archive = @import("Archive.zig");4const Archive = @import("Archive.zig");
5const Atom = @import("Atom.zig");5const Atom = @import("Atom.zig");
6const dev = @import("../../dev.zig");
6const Dwarf = @import("Dwarf.zig");7const Dwarf = @import("Dwarf.zig");
7const File = @import("file.zig").File;8const File = @import("file.zig").File;
8const MachO = @import("../MachO.zig");9const MachO = @import("../MachO.zig");
...@@ -2826,6 +2827,7 @@ const x86_64 = struct {...@@ -2826,6 +2827,7 @@ const x86_64 = struct {
2826 handle: File.Handle,2827 handle: File.Handle,
2827 macho_file: *MachO,2828 macho_file: *MachO,
2828 ) !void {2829 ) !void {
2830 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
2829 const comp = macho_file.base.comp;2831 const comp = macho_file.base.comp;
2830 const io = comp.io;2832 const io = comp.io;
2831 const gpa = comp.gpa;2833 const gpa = comp.gpa;
...@@ -2938,6 +2940,7 @@ const x86_64 = struct {...@@ -2938,6 +2940,7 @@ const x86_64 = struct {
2938 }2940 }
29392941
2940 fn validateRelocType(rel: macho.relocation_info, rel_type: macho.reloc_type_x86_64, is_extern: bool) !Relocation.Type {2942 fn validateRelocType(rel: macho.relocation_info, rel_type: macho.reloc_type_x86_64, is_extern: bool) !Relocation.Type {
2943 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
2941 switch (rel_type) {2944 switch (rel_type) {
2942 .X86_64_RELOC_UNSIGNED => {2945 .X86_64_RELOC_UNSIGNED => {
2943 if (rel.r_pcrel == 1) return error.Pcrel;2946 if (rel.r_pcrel == 1) return error.Pcrel;
...@@ -2995,6 +2998,7 @@ const aarch64 = struct {...@@ -2995,6 +2998,7 @@ const aarch64 = struct {
2995 handle: File.Handle,2998 handle: File.Handle,
2996 macho_file: *MachO,2999 macho_file: *MachO,
2997 ) !void {3000 ) !void {
3001 dev.checkAny(&.{ .llvm_backend, .aarch64_backend });
2998 const comp = macho_file.base.comp;3002 const comp = macho_file.base.comp;
2999 const io = comp.io;3003 const io = comp.io;
3000 const gpa = comp.gpa;3004 const gpa = comp.gpa;
...@@ -3131,6 +3135,7 @@ const aarch64 = struct {...@@ -3131,6 +3135,7 @@ const aarch64 = struct {
3131 }3135 }
31323136
3133 fn validateRelocType(rel: macho.relocation_info, rel_type: macho.reloc_type_arm64, is_extern: bool) !Relocation.Type {3137 fn validateRelocType(rel: macho.relocation_info, rel_type: macho.reloc_type_arm64, is_extern: bool) !Relocation.Type {
3138 dev.checkAny(&.{ .llvm_backend, .aarch64_backend });
3134 switch (rel_type) {3139 switch (rel_type) {
3135 .ARM64_RELOC_UNSIGNED => {3140 .ARM64_RELOC_UNSIGNED => {
3136 if (rel.r_pcrel == 1) return error.Pcrel;3141 if (rel.r_pcrel == 1) return error.Pcrel;
src/link/MachO/ZigObject.zig+2
...@@ -1744,6 +1744,7 @@ const TlvInitializerTable = std.array_hash_map.Auto(Atom.Index, TlvInitializer);...@@ -1744,6 +1744,7 @@ const TlvInitializerTable = std.array_hash_map.Auto(Atom.Index, TlvInitializer);
17441744
1745const x86_64 = struct {1745const x86_64 = struct {
1746 fn writeTrampolineCode(source_addr: u64, target_addr: u64, buf: *[max_trampoline_len]u8) ![]u8 {1746 fn writeTrampolineCode(source_addr: u64, target_addr: u64, buf: *[max_trampoline_len]u8) ![]u8 {
1747 dev.checkAny(&.{ .llvm_backend, .x86_64_backend });
1747 const disp = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)) - 5;1748 const disp = @as(i64, @intCast(target_addr)) - @as(i64, @intCast(source_addr)) - 5;
1748 var bytes = [_]u8{1749 var bytes = [_]u8{
1749 0xe9, 0x00, 0x00, 0x00, 0x00, // jmp rel321750 0xe9, 0x00, 0x00, 0x00, 0x00, // jmp rel32
...@@ -1758,6 +1759,7 @@ const x86_64 = struct {...@@ -1758,6 +1759,7 @@ const x86_64 = struct {
1758const assert = std.debug.assert;1759const assert = std.debug.assert;
1759const builtin = @import("builtin");1760const builtin = @import("builtin");
1760const codegen = @import("../../codegen.zig");1761const codegen = @import("../../codegen.zig");
1762const dev = @import("../../dev.zig");
1761const link = @import("../../link.zig");1763const link = @import("../../link.zig");
1762const log = std.log.scoped(.link);1764const log = std.log.scoped(.link);
1763const macho = std.macho;1765const macho = std.macho;
src/link/Spork8.zig-2
...@@ -18,7 +18,6 @@ const Mir = @import("../codegen/spork8/Mir.zig");...@@ -18,7 +18,6 @@ const Mir = @import("../codegen/spork8/Mir.zig");
18const link = @import("../link.zig");18const link = @import("../link.zig");
19const Compilation = @import("../Compilation.zig");19const Compilation = @import("../Compilation.zig");
20const Liveness = @import("../Air/Liveness.zig");20const Liveness = @import("../Air/Liveness.zig");
21const dev = @import("../dev.zig");
22const Value = @import("../Value.zig");21const Value = @import("../Value.zig");
2322
24base: link.File,23base: link.File,
...@@ -89,7 +88,6 @@ pub fn updateFunc(...@@ -89,7 +88,6 @@ pub fn updateFunc(
89 func_index: InternPool.Index,88 func_index: InternPool.Index,
90 any_mir: *const codegen.AnyMir,89 any_mir: *const codegen.AnyMir,
91) !void {90) !void {
92 dev.check(.spork8_backend);
93 // This linker implementation only works with `std.lang.CompilerBackend.zsf_spork8`.91 // This linker implementation only works with `std.lang.CompilerBackend.zsf_spork8`.
94 const mir = &any_mir.spork8;92 const mir = &any_mir.spork8;
95 const zcu = pt.zcu;93 const zcu = pt.zcu;
src/link/Wasm.zig-3
...@@ -38,7 +38,6 @@ const Dwarf = @import("Dwarf.zig");...@@ -38,7 +38,6 @@ const Dwarf = @import("Dwarf.zig");
38const InternPool = @import("../InternPool.zig");38const InternPool = @import("../InternPool.zig");
39const Zcu = @import("../Zcu.zig");39const Zcu = @import("../Zcu.zig");
40const codegen = @import("../codegen.zig");40const codegen = @import("../codegen.zig");
41const dev = @import("../dev.zig");
42const link = @import("../link.zig");41const link = @import("../link.zig");
43const trace = @import("../tracy.zig").trace;42const trace = @import("../tracy.zig").trace;
44const wasi_libc = @import("../libs/wasi_libc.zig");43const wasi_libc = @import("../libs/wasi_libc.zig");
...@@ -3575,8 +3574,6 @@ pub fn updateFunc(...@@ -3575,8 +3574,6 @@ pub fn updateFunc(
3575 func_index: InternPool.Index,3574 func_index: InternPool.Index,
3576 any_mir: *const codegen.AnyMir,3575 any_mir: *const codegen.AnyMir,
3577) !void {3576) !void {
3578 dev.check(.wasm_backend);
3579
3580 // This linker implementation only works with codegen backend `.stage2_wasm`.3577 // This linker implementation only works with codegen backend `.stage2_wasm`.
3581 const mir = &any_mir.wasm;3578 const mir = &any_mir.wasm;
3582 const zcu = pt.zcu;3579 const zcu = pt.zcu;
src/main.zig+1-1
...@@ -36,7 +36,7 @@ const Module = @import("Module.zig");...@@ -36,7 +36,7 @@ const Module = @import("Module.zig");
3636
37test {37test {
38 _ = @import("codegen.zig");38 _ = @import("codegen.zig");
39 _ = @import("link/MappedFile.zig");39 _ = link.MappedFile;
40}40}
4141
42const thread_stack_size = 60 << 20;42const thread_stack_size = 60 << 20;
src/target.zig+5-1
...@@ -2,6 +2,7 @@ const builtin = @import("builtin");...@@ -2,6 +2,7 @@ const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const assert = std.debug.assert;3const assert = std.debug.assert;
44
5const dev = @import("dev.zig");
5const Type = @import("Type.zig");6const Type = @import("Type.zig");
6const AddressSpace = std.lang.AddressSpace;7const AddressSpace = std.lang.AddressSpace;
7const Alignment = @import("InternPool.zig").Alignment;8const Alignment = @import("InternPool.zig").Alignment;
...@@ -855,7 +856,10 @@ pub fn functionPointerMask(target: *const std.Target) ?u64 {...@@ -855,7 +856,10 @@ pub fn functionPointerMask(target: *const std.Target) ?u64 {
855856
856pub fn supportsTailCall(target: *const std.Target, backend: std.lang.CompilerBackend) bool {857pub fn supportsTailCall(target: *const std.Target, backend: std.lang.CompilerBackend) bool {
857 switch (backend) {858 switch (backend) {
858 .stage2_llvm => return @import("codegen/llvm.zig").supportsTailCall(target),859 .stage2_llvm => {
860 dev.check(.llvm_backend);
861 return @import("codegen/llvm.zig").supportsTailCall(target);
862 },
859 .stage2_c => return true,863 .stage2_c => return true,
860 else => return false,864 else => return false,
861 }865 }