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] 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 bc2ba4c8316f4ee87b0886acdeaa42f7e444f1e9..221c2029baf9ea25e941df81ac7870bd004801e8 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, } } -- 2.54.0