Skip to content
/ zig Public
forked from ziglang/zig

Commit

Permalink
test: Change llvm_targets to actually emit an object for each target.
Browse files Browse the repository at this point in the history
Without doing this, we don't actually test whether the data layout string we
generate matches LLVM's.

A number of targets had to be commented out due to this change:

* Some are using a non-working experimental LLVM backend (arc, csky, ...).
* Some don't have working LLD support (lanai, sparc, ...).
* Some don't have working self-hosted linker support (nvptx).
* Some are using ABIs that haven't been standardized (loongarch32).

Finally, all non-x86 uefi targets are hopelessly broken and can't really be
fixed until we change our emit logic to lower *-uefi-* verbatim rather than to
*-windows-*. See: ziglang#21630
  • Loading branch information
alexrp committed Nov 28, 2024
1 parent 078026a commit 5cc0412
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 65 deletions.
96 changes: 48 additions & 48 deletions test/llvm_targets.zig
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ const targets = [_]std.Target.Query{
.{ .cpu_arch = .aarch64_be, .os_tag = .netbsd, .abi = .none },

.{ .cpu_arch = .amdgcn, .os_tag = .amdhsa, .abi = .none },
.{ .cpu_arch = .amdgcn, .os_tag = .amdpal, .abi = .none },
.{ .cpu_arch = .amdgcn, .os_tag = .mesa3d, .abi = .none },
// .{ .cpu_arch = .amdgcn, .os_tag = .amdpal, .abi = .none },
// .{ .cpu_arch = .amdgcn, .os_tag = .mesa3d, .abi = .none },

.{ .cpu_arch = .arc, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .arc, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .arc, .os_tag = .linux, .abi = .none },
// .{ .cpu_arch = .arc, .os_tag = .freestanding, .abi = .none },
// .{ .cpu_arch = .arc, .os_tag = .linux, .abi = .gnu },
// .{ .cpu_arch = .arc, .os_tag = .linux, .abi = .none },

.{ .cpu_arch = .arm, .os_tag = .freebsd, .abi = .eabi },
.{ .cpu_arch = .arm, .os_tag = .freebsd, .abi = .eabihf },
Expand All @@ -69,8 +69,8 @@ const targets = [_]std.Target.Query{
.{ .cpu_arch = .arm, .os_tag = .openbsd, .abi = .eabihf },
.{ .cpu_arch = .arm, .os_tag = .rtems, .abi = .eabi },
.{ .cpu_arch = .arm, .os_tag = .rtems, .abi = .eabihf },
.{ .cpu_arch = .arm, .os_tag = .uefi, .abi = .eabi },
.{ .cpu_arch = .arm, .os_tag = .uefi, .abi = .eabihf },
// .{ .cpu_arch = .arm, .os_tag = .uefi, .abi = .eabi },
// .{ .cpu_arch = .arm, .os_tag = .uefi, .abi = .eabihf },

.{ .cpu_arch = .armeb, .os_tag = .freebsd, .abi = .eabi },
.{ .cpu_arch = .armeb, .os_tag = .freebsd, .abi = .eabihf },
Expand All @@ -94,37 +94,37 @@ const targets = [_]std.Target.Query{

.{ .cpu_arch = .bpfel, .os_tag = .freestanding, .abi = .none },

.{ .cpu_arch = .csky, .os_tag = .freestanding, .abi = .eabi },
.{ .cpu_arch = .csky, .os_tag = .freestanding, .abi = .eabihf },
.{ .cpu_arch = .csky, .os_tag = .linux, .abi = .eabi },
.{ .cpu_arch = .csky, .os_tag = .linux, .abi = .eabihf },
.{ .cpu_arch = .csky, .os_tag = .linux, .abi = .gnueabi },
.{ .cpu_arch = .csky, .os_tag = .linux, .abi = .gnueabihf },
// .{ .cpu_arch = .csky, .os_tag = .freestanding, .abi = .eabi },
// .{ .cpu_arch = .csky, .os_tag = .freestanding, .abi = .eabihf },
// .{ .cpu_arch = .csky, .os_tag = .linux, .abi = .eabi },
// .{ .cpu_arch = .csky, .os_tag = .linux, .abi = .eabihf },
// .{ .cpu_arch = .csky, .os_tag = .linux, .abi = .gnueabi },
// .{ .cpu_arch = .csky, .os_tag = .linux, .abi = .gnueabihf },

.{ .cpu_arch = .hexagon, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .hexagon, .os_tag = .linux, .abi = .none },

.{ .cpu_arch = .lanai, .os_tag = .freestanding, .abi = .none },
// .{ .cpu_arch = .lanai, .os_tag = .freestanding, .abi = .none },

.{ .cpu_arch = .loongarch32, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .loongarch32, .os_tag = .linux, .abi = .none },
.{ .cpu_arch = .loongarch32, .os_tag = .uefi, .abi = .none },
// .{ .cpu_arch = .loongarch32, .os_tag = .freestanding, .abi = .none },
// .{ .cpu_arch = .loongarch32, .os_tag = .linux, .abi = .none },
// .{ .cpu_arch = .loongarch32, .os_tag = .uefi, .abi = .none },

.{ .cpu_arch = .loongarch64, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .gnuf32 },
// .{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .gnuf32 },
.{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .gnusf },
.{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .musl },
.{ .cpu_arch = .loongarch64, .os_tag = .linux, .abi = .none },
.{ .cpu_arch = .loongarch64, .os_tag = .uefi, .abi = .none },
// .{ .cpu_arch = .loongarch64, .os_tag = .uefi, .abi = .none },

.{ .cpu_arch = .m68k, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .m68k, .os_tag = .haiku, .abi = .none },
.{ .cpu_arch = .m68k, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .m68k, .os_tag = .linux, .abi = .musl },
.{ .cpu_arch = .m68k, .os_tag = .linux, .abi = .none },
.{ .cpu_arch = .m68k, .os_tag = .netbsd, .abi = .none },
.{ .cpu_arch = .m68k, .os_tag = .rtems, .abi = .none },
// .{ .cpu_arch = .m68k, .os_tag = .freestanding, .abi = .none },
// .{ .cpu_arch = .m68k, .os_tag = .haiku, .abi = .none },
// .{ .cpu_arch = .m68k, .os_tag = .linux, .abi = .gnu },
// .{ .cpu_arch = .m68k, .os_tag = .linux, .abi = .musl },
// .{ .cpu_arch = .m68k, .os_tag = .linux, .abi = .none },
// .{ .cpu_arch = .m68k, .os_tag = .netbsd, .abi = .none },
// .{ .cpu_arch = .m68k, .os_tag = .rtems, .abi = .none },

.{ .cpu_arch = .mips, .os_tag = .freebsd, .abi = .eabi },
.{ .cpu_arch = .mips, .os_tag = .freebsd, .abi = .eabihf },
Expand Down Expand Up @@ -178,12 +178,12 @@ const targets = [_]std.Target.Query{

.{ .cpu_arch = .msp430, .os_tag = .freestanding, .abi = .none },

.{ .cpu_arch = .nvptx, .os_tag = .cuda, .abi = .none },
.{ .cpu_arch = .nvptx, .os_tag = .nvcl, .abi = .none },
.{ .cpu_arch = .nvptx64, .os_tag = .cuda, .abi = .none },
.{ .cpu_arch = .nvptx64, .os_tag = .nvcl, .abi = .none },
// .{ .cpu_arch = .nvptx, .os_tag = .cuda, .abi = .none },
// .{ .cpu_arch = .nvptx, .os_tag = .nvcl, .abi = .none },
// .{ .cpu_arch = .nvptx64, .os_tag = .cuda, .abi = .none },
// .{ .cpu_arch = .nvptx64, .os_tag = .nvcl, .abi = .none },

.{ .cpu_arch = .powerpc, .os_tag = .aix, .abi = .eabihf },
// .{ .cpu_arch = .powerpc, .os_tag = .aix, .abi = .eabihf },
.{ .cpu_arch = .powerpc, .os_tag = .freebsd, .abi = .eabi },
.{ .cpu_arch = .powerpc, .os_tag = .freebsd, .abi = .eabihf },
.{ .cpu_arch = .powerpc, .os_tag = .freestanding, .abi = .eabi },
Expand All @@ -206,7 +206,7 @@ const targets = [_]std.Target.Query{
.{ .cpu_arch = .powerpcle, .os_tag = .freestanding, .abi = .eabi },
.{ .cpu_arch = .powerpcle, .os_tag = .freestanding, .abi = .eabihf },

.{ .cpu_arch = .powerpc64, .os_tag = .aix, .abi = .none },
// .{ .cpu_arch = .powerpc64, .os_tag = .aix, .abi = .none },
.{ .cpu_arch = .powerpc64, .os_tag = .freebsd, .abi = .none },
.{ .cpu_arch = .powerpc64, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .powerpc64, .os_tag = .linux, .abi = .gnu },
Expand All @@ -226,7 +226,7 @@ const targets = [_]std.Target.Query{
.{ .cpu_arch = .riscv32, .os_tag = .linux, .abi = .musl },
.{ .cpu_arch = .riscv32, .os_tag = .linux, .abi = .none },
.{ .cpu_arch = .riscv32, .os_tag = .rtems, .abi = .none },
.{ .cpu_arch = .riscv32, .os_tag = .uefi, .abi = .none },
// .{ .cpu_arch = .riscv32, .os_tag = .uefi, .abi = .none },

.{ .cpu_arch = .riscv64, .os_tag = .freebsd, .abi = .none },
.{ .cpu_arch = .riscv64, .os_tag = .freestanding, .abi = .none },
Expand All @@ -241,20 +241,20 @@ const targets = [_]std.Target.Query{
.{ .cpu_arch = .riscv64, .os_tag = .openbsd, .abi = .none },
.{ .cpu_arch = .riscv64, .os_tag = .rtems, .abi = .none },
.{ .cpu_arch = .riscv64, .os_tag = .serenity, .abi = .none },
.{ .cpu_arch = .riscv64, .os_tag = .uefi, .abi = .none },
// .{ .cpu_arch = .riscv64, .os_tag = .uefi, .abi = .none },

.{ .cpu_arch = .s390x, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .s390x, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .s390x, .os_tag = .linux, .abi = .none },
.{ .cpu_arch = .s390x, .os_tag = .zos, .abi = .none },
// .{ .cpu_arch = .s390x, .os_tag = .zos, .abi = .none },

.{ .cpu_arch = .sparc, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .sparc, .os_tag = .illumos, .abi = .none },
.{ .cpu_arch = .sparc, .os_tag = .linux, .abi = .gnu },
.{ .cpu_arch = .sparc, .os_tag = .linux, .abi = .none },
.{ .cpu_arch = .sparc, .os_tag = .netbsd, .abi = .none },
.{ .cpu_arch = .sparc, .os_tag = .rtems, .abi = .none },
.{ .cpu_arch = .sparc, .os_tag = .solaris, .abi = .none },
// .{ .cpu_arch = .sparc, .os_tag = .freestanding, .abi = .none },
// .{ .cpu_arch = .sparc, .os_tag = .illumos, .abi = .none },
// .{ .cpu_arch = .sparc, .os_tag = .linux, .abi = .gnu },
// .{ .cpu_arch = .sparc, .os_tag = .linux, .abi = .none },
// .{ .cpu_arch = .sparc, .os_tag = .netbsd, .abi = .none },
// .{ .cpu_arch = .sparc, .os_tag = .rtems, .abi = .none },
// .{ .cpu_arch = .sparc, .os_tag = .solaris, .abi = .none },

.{ .cpu_arch = .sparc64, .os_tag = .freebsd, .abi = .none },
.{ .cpu_arch = .sparc64, .os_tag = .freestanding, .abi = .none },
Expand Down Expand Up @@ -301,8 +301,8 @@ const targets = [_]std.Target.Query{
.{ .cpu_arch = .thumbeb, .os_tag = .rtems, .abi = .eabi },
.{ .cpu_arch = .thumbeb, .os_tag = .rtems, .abi = .eabihf },

.{ .cpu_arch = .ve, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .ve, .os_tag = .linux, .abi = .none },
// .{ .cpu_arch = .ve, .os_tag = .freestanding, .abi = .none },
// .{ .cpu_arch = .ve, .os_tag = .linux, .abi = .none },

.{ .cpu_arch = .wasm32, .os_tag = .emscripten, .abi = .none },
.{ .cpu_arch = .wasm32, .os_tag = .freestanding, .abi = .none },
Expand Down Expand Up @@ -374,10 +374,10 @@ const targets = [_]std.Target.Query{
.{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .itanium },
.{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .msvc },

.{ .cpu_arch = .xcore, .os_tag = .freestanding, .abi = .none },
// .{ .cpu_arch = .xcore, .os_tag = .freestanding, .abi = .none },

.{ .cpu_arch = .xtensa, .os_tag = .freestanding, .abi = .none },
.{ .cpu_arch = .xtensa, .os_tag = .linux, .abi = .none },
// .{ .cpu_arch = .xtensa, .os_tag = .freestanding, .abi = .none },
// .{ .cpu_arch = .xtensa, .os_tag = .linux, .abi = .none },
};

pub fn addCases(
Expand All @@ -394,7 +394,7 @@ pub fn addCases(
.xtensa => if (!build_options.llvm_has_xtensa) continue,
else => {},
};
var case = ctx.noEmitUsingLlvmBackend("llvm_targets", b.resolveTargetQuery(target_query));
var case = ctx.addObjLlvm("llvm_targets", b.resolveTargetQuery(target_query));
case.addCompile("");
}
}
18 changes: 1 addition & 17 deletions test/src/Cases.zig
Original file line number Diff line number Diff line change
Expand Up @@ -204,34 +204,18 @@ pub fn exeFromCompiledC(ctx: *Cases, name: []const u8, target_query: std.Target.
return &ctx.cases.items[ctx.cases.items.len - 1];
}

pub fn noEmitUsingLlvmBackend(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case {
pub fn addObjLlvm(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case {
ctx.cases.append(Case{
.name = name,
.target = target,
.updates = std.ArrayList(Update).init(ctx.cases.allocator),
.output_mode = .Obj,
.emit_bin = false,
.deps = std.ArrayList(DepModule).init(ctx.arena),
.backend = .llvm,
}) catch @panic("out of memory");
return &ctx.cases.items[ctx.cases.items.len - 1];
}

/// Adds a test case that uses the LLVM backend to emit an executable.
/// Currently this implies linking libc, because only then we can generate a testable executable.
pub fn exeUsingLlvmBackend(ctx: *Cases, name: []const u8, target: std.Build.ResolvedTarget) *Case {
ctx.cases.append(Case{
.name = name,
.target = target,
.updates = std.ArrayList(Update).init(ctx.cases.allocator),
.output_mode = .Exe,
.deps = std.ArrayList(DepModule).init(ctx.arena),
.backend = .llvm,
.link_libc = true,
}) catch @panic("out of memory");
return &ctx.cases.items[ctx.cases.items.len - 1];
}

pub fn addObj(
ctx: *Cases,
name: []const u8,
Expand Down

0 comments on commit 5cc0412

Please sign in to comment.