authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-07-20 10:44:49-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-20 10:44:49-04:00
logef3a746da1a85a8b4a653cb78e0464c71d35b64e
tree1399f8c2a1d523788b85c28e4230729b7d1380e3
parent4f742c4cfc3c3134a0d6ebfdfc354286ae97b2c1
parent542423915466c0e20b0947f745a1de276fbd8b03
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20691 from jacobly0/dev

dev: fix llvm backend checks

12 files changed, 30 insertions(+), 12 deletions(-)

src/Compilation.zig+1-2
......@@ -1729,7 +1729,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17291729 comp.emit_llvm_ir != null or
17301730 comp.emit_llvm_bc != null))
17311731 {
1732 dev.check(.llvm_backend);
17331732 if (opt_zcu) |zcu| zcu.llvm_object = try LlvmObject.create(arena, comp);
17341733 }
17351734
......@@ -2704,7 +2703,7 @@ pub fn emitLlvmObject(
27042703 arena: Allocator,
27052704 default_emit: Emit,
27062705 bin_emit_loc: ?EmitLoc,
2707 llvm_object: *LlvmObject,
2706 llvm_object: LlvmObject.Ptr,
27082707 prog_node: std.Progress.Node,
27092708) !void {
27102709 const sub_prog_node = prog_node.start("LLVM Emit Object", 0);
src/Zcu.zig+1-1
......@@ -58,7 +58,7 @@ comp: *Compilation,
5858/// Usually, the LlvmObject is managed by linker code, however, in the case
5959/// that -fno-emit-bin is specified, the linker code never executes, so we
6060/// store the LlvmObject here.
61llvm_object: if (dev.env.supports(.llvm_backend)) ?*LlvmObject else ?noreturn,
61llvm_object: ?LlvmObject.Ptr,
6262
6363/// Pointer to externally managed resource.
6464root_mod: *Package.Module,
src/codegen/llvm.zig+5-1
......@@ -26,6 +26,7 @@ const wasm_c_abi = @import("../arch/wasm/abi.zig");
2626const aarch64_c_abi = @import("../arch/aarch64/abi.zig");
2727const arm_c_abi = @import("../arch/arm/abi.zig");
2828const riscv_c_abi = @import("../arch/riscv64/abi.zig");
29const dev = @import("../dev.zig");
2930
3031const target_util = @import("../target.zig");
3132const libcFloatPrefix = target_util.libcFloatPrefix;
......@@ -865,9 +866,12 @@ pub const Object = struct {
865866 field_index: u32,
866867 };
867868
869 pub const Ptr = if (dev.env.supports(.llvm_backend)) *Object else noreturn;
870
868871 pub const TypeMap = std.AutoHashMapUnmanaged(InternPool.Index, Builder.Type);
869872
870 pub fn create(arena: Allocator, comp: *Compilation) !*Object {
873 pub fn create(arena: Allocator, comp: *Compilation) !Ptr {
874 dev.check(.llvm_backend);
871875 const gpa = comp.gpa;
872876 const target = comp.root_mod.resolved_target.result;
873877 const llvm_target_triple = try targetTriple(arena, target);
src/dev.zig-1
......@@ -23,7 +23,6 @@ pub const Env = enum {
2323 sema,
2424
2525 /// - sema
26 /// - jit command on x86_64-linux host
2726 /// - `zig build-* -fno-llvm -fno-lld -target x86_64-linux`
2827 @"x86_64-linux",
2928
src/link.zig+1-1
......@@ -968,7 +968,7 @@ pub const File = struct {
968968 pub fn emitLlvmObject(
969969 base: File,
970970 arena: Allocator,
971 llvm_object: *LlvmObject,
971 llvm_object: LlvmObject.Ptr,
972972 prog_node: std.Progress.Node,
973973 ) !void {
974974 return base.comp.emitLlvmObject(arena, base.emit, .{
src/link/Coff.zig+2-1
......@@ -4,7 +4,7 @@
44//! LLD is also the default linker for LLVM.
55
66/// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path.
7llvm_object: ?*LlvmObject = null,
7llvm_object: ?LlvmObject.Ptr = null,
88
99base: link.File,
1010image_base: u64,
......@@ -2765,6 +2765,7 @@ const StringTable = @import("StringTable.zig");
27652765const Type = @import("../Type.zig");
27662766const Value = @import("../Value.zig");
27672767const AnalUnit = InternPool.AnalUnit;
2768const dev = @import("../dev.zig");
27682769
27692770pub const base_tag: link.File.Tag = .coff;
27702771
src/link/Elf.zig+1-1
......@@ -30,7 +30,7 @@ entry_name: ?[]const u8,
3030ptr_width: PtrWidth,
3131
3232/// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path.
33llvm_object: ?*LlvmObject = null,
33llvm_object: ?LlvmObject.Ptr = null,
3434
3535/// A list of all input files.
3636/// Index of each input file also encodes the priority or precedence of one input file
src/link/Elf/Atom.zig+12
......@@ -1113,6 +1113,7 @@ const x86_64 = struct {
11131113 code: ?[]const u8,
11141114 it: *RelocsIterator,
11151115 ) !void {
1116 dev.check(.x86_64_backend);
11161117 const is_static = elf_file.base.isStatic();
11171118 const is_dyn_lib = elf_file.isEffectivelyDynLib();
11181119
......@@ -1235,6 +1236,7 @@ const x86_64 = struct {
12351236 code: []u8,
12361237 stream: anytype,
12371238 ) (error{ InvalidInstruction, CannotEncode } || RelocError)!void {
1239 dev.check(.x86_64_backend);
12381240 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
12391241 const r_offset = std.math.cast(usize, rel.r_offset) orelse return error.Overflow;
12401242
......@@ -1380,6 +1382,7 @@ const x86_64 = struct {
13801382 code: []u8,
13811383 stream: anytype,
13821384 ) !void {
1385 dev.check(.x86_64_backend);
13831386 _ = code;
13841387 _ = it;
13851388 const r_type: elf.R_X86_64 = @enumFromInt(rel.r_type());
......@@ -1420,6 +1423,7 @@ const x86_64 = struct {
14201423 }
14211424
14221425 fn relaxGotpcrelx(code: []u8) !void {
1426 dev.check(.x86_64_backend);
14231427 const old_inst = disassemble(code) orelse return error.RelaxFailure;
14241428 const inst = switch (old_inst.encoding.mnemonic) {
14251429 .call => try Instruction.new(old_inst.prefix, .call, &.{
......@@ -1438,6 +1442,7 @@ const x86_64 = struct {
14381442 }
14391443
14401444 fn relaxRexGotpcrelx(code: []u8) !void {
1445 dev.check(.x86_64_backend);
14411446 const old_inst = disassemble(code) orelse return error.RelaxFailure;
14421447 switch (old_inst.encoding.mnemonic) {
14431448 .mov => {
......@@ -1456,6 +1461,7 @@ const x86_64 = struct {
14561461 elf_file: *Elf,
14571462 stream: anytype,
14581463 ) !void {
1464 dev.check(.x86_64_backend);
14591465 assert(rels.len == 2);
14601466 const writer = stream.writer();
14611467 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());
......@@ -1495,6 +1501,7 @@ const x86_64 = struct {
14951501 elf_file: *Elf,
14961502 stream: anytype,
14971503 ) !void {
1504 dev.check(.x86_64_backend);
14981505 assert(rels.len == 2);
14991506 const writer = stream.writer();
15001507 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());
......@@ -1543,6 +1550,7 @@ const x86_64 = struct {
15431550 }
15441551
15451552 fn canRelaxGotTpOff(code: []const u8) bool {
1553 dev.check(.x86_64_backend);
15461554 const old_inst = disassemble(code) orelse return false;
15471555 switch (old_inst.encoding.mnemonic) {
15481556 .mov => if (Instruction.new(old_inst.prefix, .mov, &.{
......@@ -1558,6 +1566,7 @@ const x86_64 = struct {
15581566 }
15591567
15601568 fn relaxGotTpOff(code: []u8) void {
1569 dev.check(.x86_64_backend);
15611570 const old_inst = disassemble(code) orelse unreachable;
15621571 switch (old_inst.encoding.mnemonic) {
15631572 .mov => {
......@@ -1574,6 +1583,7 @@ const x86_64 = struct {
15741583 }
15751584
15761585 fn relaxGotPcTlsDesc(code: []u8) !void {
1586 dev.check(.x86_64_backend);
15771587 const old_inst = disassemble(code) orelse return error.RelaxFailure;
15781588 switch (old_inst.encoding.mnemonic) {
15791589 .lea => {
......@@ -1596,6 +1606,7 @@ const x86_64 = struct {
15961606 elf_file: *Elf,
15971607 stream: anytype,
15981608 ) !void {
1609 dev.check(.x86_64_backend);
15991610 assert(rels.len == 2);
16001611 const writer = stream.writer();
16011612 const rel: elf.R_X86_64 = @enumFromInt(rels[1].r_type());
......@@ -2312,3 +2323,4 @@ const File = @import("file.zig").File;
23122323const Object = @import("Object.zig");
23132324const Symbol = @import("Symbol.zig");
23142325const Thunk = @import("thunks.zig").Thunk;
2326const dev = @import("../../dev.zig");
src/link/MachO.zig+2-2
......@@ -1,7 +1,7 @@
11base: link.File,
22
33/// If this is not null, an object file is created by LLVM and emitted to zcu_object_sub_path.
4llvm_object: ?*LlvmObject = null,
4llvm_object: ?LlvmObject.Ptr = null,
55
66/// Debug symbols bundle (or dSym).
77d_sym: ?DebugSymbols = null,
......@@ -4510,7 +4510,6 @@ const dead_strip = @import("MachO/dead_strip.zig");
45104510const eh_frame = @import("MachO/eh_frame.zig");
45114511const fat = @import("MachO/fat.zig");
45124512const link = @import("../link.zig");
4513const llvm_backend = @import("../codegen/llvm.zig");
45144513const load_commands = @import("MachO/load_commands.zig");
45154514const relocatable = @import("MachO/relocatable.zig");
45164515const tapi = @import("tapi.zig");
......@@ -4562,6 +4561,7 @@ const UnwindInfo = @import("MachO/UnwindInfo.zig");
45624561const WeakBind = bind.WeakBind;
45634562const ZigGotSection = synthetic.ZigGotSection;
45644563const ZigObject = @import("MachO/ZigObject.zig");
4564const dev = @import("../dev.zig");
45654565
45664566pub const MachError = error{
45674567 /// Not enough permissions held to perform the requested kernel
src/link/MachO/Atom.zig+3
......@@ -897,6 +897,7 @@ fn resolveRelocInner(
897897
898898const x86_64 = struct {
899899 fn relaxGotLoad(self: Atom, code: []u8, rel: Relocation, macho_file: *MachO) ResolveError!void {
900 dev.check(.x86_64_backend);
900901 const old_inst = disassemble(code) orelse return error.RelaxFail;
901902 switch (old_inst.encoding.mnemonic) {
902903 .mov => {
......@@ -920,6 +921,7 @@ const x86_64 = struct {
920921 }
921922
922923 fn relaxTlv(code: []u8) error{RelaxFail}!void {
924 dev.check(.x86_64_backend);
923925 const old_inst = disassemble(code) orelse return error.RelaxFail;
924926 switch (old_inst.encoding.mnemonic) {
925927 .mov => {
......@@ -1214,3 +1216,4 @@ const Relocation = @import("Relocation.zig");
12141216const Symbol = @import("Symbol.zig");
12151217const Thunk = @import("thunks.zig").Thunk;
12161218const UnwindInfo = @import("UnwindInfo.zig");
1219const dev = @import("../../dev.zig");
src/link/NvPtx.zig+1-1
......@@ -23,7 +23,7 @@ const Liveness = @import("../Liveness.zig");
2323const LlvmObject = @import("../codegen/llvm.zig").Object;
2424
2525base: link.File,
26llvm_object: *LlvmObject,
26llvm_object: LlvmObject.Ptr,
2727
2828pub fn createEmpty(
2929 arena: Allocator,
src/link/Wasm.zig+1-1
......@@ -61,7 +61,7 @@ export_table: bool,
6161/// Output name of the file
6262name: []const u8,
6363/// If this is not null, an object file is created by LLVM and linked with LLD afterwards.
64llvm_object: ?*LlvmObject = null,
64llvm_object: ?LlvmObject.Ptr = null,
6565/// The file index of a `ZigObject`. This will only contain a valid index when a zcu exists,
6666/// and the chosen backend is the Wasm backend.
6767zig_object_index: File.Index = .null,