From 19895834b9c00caff29ad8b9173d1845314104c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 5 Sep 2024 01:12:53 +0200 Subject: [PATCH 1/4] compiler: Force ELFv2 for powerpc64. LLD does not support ELFv1. By forcing ELFv2, we can at least build working binaries for triples like `powerpc64-linux-none`. --- src/target.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/target.zig b/src/target.zig index bc2ba4c8316f..221c2029baf9 100644 --- a/src/target.zig +++ b/src/target.zig @@ -381,6 +381,14 @@ pub fn addrSpaceCastIsValid( } pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 { + // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it + // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc + // is linked as glibc only supports ELFv2 for little endian, but there's nothing we can do about + // that. With this hack, `powerpc64-linux-none` will at least work. + // + // Once our self-hosted linker can handle both ABIs, this hack should go away. + if (target.cpu.arch == .powerpc64) return "elfv2"; + const have_float = switch (target.abi) { .gnueabihf, .musleabihf, .eabihf => true, else => false, @@ -409,7 +417,6 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 { return "ilp32"; } }, - //TODO add ARM, Mips, and PowerPC else => return null, } } From 2a6eecff3e218015bb425737dabc27760f29fb2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 5 Sep 2024 01:14:03 +0200 Subject: [PATCH 2/4] test: Disable `reinterpret packed union` for powerpc64 too. https://github.com/ziglang/zig/issues/21050 --- test/behavior/union.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/behavior/union.zig b/test/behavior/union.zig index a952e9b9d31a..9938c3c04578 100644 --- a/test/behavior/union.zig +++ b/test/behavior/union.zig @@ -1891,7 +1891,7 @@ test "reinterpret packed union" { try comptime S.doTheTest(); if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO - if (builtin.cpu.arch.isPowerPC32()) return error.SkipZigTest; // TODO + if (builtin.cpu.arch.isPowerPC()) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21050 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest; // https://github.com/ziglang/zig/issues/21050 if (builtin.cpu.arch.isWasm()) return error.SkipZigTest; // TODO try S.doTheTest(); From 40ee6825170ed52ebd707262d1a88f237de54d6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 5 Sep 2024 01:14:38 +0200 Subject: [PATCH 3/4] test: Disable `store vector with memset` on powerpc64. This will be re-enabled with LLVM 19. --- test/behavior/vector.zig | 1 + 1 file changed, 1 insertion(+) diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index 08c81fd28bb0..cee9f168f193 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -1450,6 +1450,7 @@ test "store vector with memset" { .mips64el, .riscv64, .powerpc, + .powerpc64, => { // LLVM 16 ERROR: "Converting bits to bytes lost precision" // https://github.com/ziglang/zig/issues/16177 From ee3efe8007402c496a6e589fc279e07578e8280f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 5 Sep 2024 01:15:04 +0200 Subject: [PATCH 4/4] test: Add `powerpc64-linux-(none,musl)` triples to module tests. --- test/tests.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/tests.zig b/test/tests.zig index 73934950db34..7d5be7bbf74c 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -438,6 +438,30 @@ const test_targets = blk: { // .link_libc = true, //}, + .{ + .target = .{ + .cpu_arch = .powerpc64, + .os_tag = .linux, + .abi = .none, + }, + }, + .{ + .target = .{ + .cpu_arch = .powerpc64, + .os_tag = .linux, + .abi = .musl, + }, + .link_libc = true, + }, + // Requires ELFv1 linker support. + // .{ + // .target = .{ + // .cpu_arch = .powerpc64, + // .os_tag = .linux, + // .abi = .gnu, + // }, + // .link_libc = true, + // }, .{ .target = .{ .cpu_arch = .powerpc64le,