authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-01-24 04:27:00+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-01-25 14:56:59+01:00
logcd8c92fc40993d307e891be27bfd86574c2ce85d
tree229694a27eee7f0579ce69d6b7de20609f25af07
parentb95081209a83be39b52b3f304387f75cfab22e9e
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler: Explicitly specify ABI for arm, mips, and powerpc when talking to LLVM.

See 652c5151429e279f70396ee601416c87a70c1bec. Better to avoid relying on default LLVM behavior going forward.

1 files changed, 15 insertions(+), 10 deletions(-)

src/target.zig+15-10
...@@ -482,16 +482,6 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {...@@ -482,16 +482,6 @@ pub fn arePointersLogical(target: std.Target, as: AddressSpace) bool {
482}482}
483483
484pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {484pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
485 // This special-casing should be removed with LLVM 20.
486 switch (target.cpu.arch) {
487 .mips, .mipsel => return "o32",
488 .mips64, .mips64el => return switch (target.abi) {
489 .gnuabin32, .muslabin32 => "n32",
490 else => "n64",
491 },
492 else => {},
493 }
494
495 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it485 // LLD does not support ELFv1. Rather than having LLVM produce ELFv1 code and then linking it
496 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc486 // into a broken ELFv2 binary, just force LLVM to use ELFv2 as well. This will break when glibc
497 // is linked as glibc only supports ELFv2 for little endian, but there's nothing we can do about487 // is linked as glibc only supports ELFv2 for little endian, but there's nothing we can do about
...@@ -501,6 +491,7 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {...@@ -501,6 +491,7 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
501 if (target.cpu.arch == .powerpc64) return "elfv2";491 if (target.cpu.arch == .powerpc64) return "elfv2";
502492
503 return switch (target.cpu.arch) {493 return switch (target.cpu.arch) {
494 .arm, .armeb, .thumb, .thumbeb => "aapcs",
504 // TODO: `muslsf` and `muslf32` in LLVM 20.495 // TODO: `muslsf` and `muslf32` in LLVM 20.
505 .loongarch64 => switch (target.abi) {496 .loongarch64 => switch (target.abi) {
506 .gnusf => "lp64s",497 .gnusf => "lp64s",
...@@ -512,6 +503,20 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {...@@ -512,6 +503,20 @@ pub fn llvmMachineAbi(target: std.Target) ?[:0]const u8 {
512 .gnuf32 => "ilp32f",503 .gnuf32 => "ilp32f",
513 else => "ilp32d",504 else => "ilp32d",
514 },505 },
506 .mips, .mipsel => "o32",
507 .mips64, .mips64el => switch (target.abi) {
508 .gnuabin32, .muslabin32 => "n32",
509 else => "n64",
510 },
511 .powerpc64 => switch (target.os.tag) {
512 .freebsd => if (target.os.version_range.semver.isAtLeast(.{ .major = 13, .minor = 0, .patch = 0 }) orelse false)
513 "elfv2"
514 else
515 "elfv1",
516 .openbsd => "elfv2",
517 else => if (target.abi.isMusl()) "elfv2" else "elfv1",
518 },
519 .powerpc64le => "elfv2",
515 .riscv64 => b: {520 .riscv64 => b: {
516 const featureSetHas = std.Target.riscv.featureSetHas;521 const featureSetHas = std.Target.riscv.featureSetHas;
517 break :b if (featureSetHas(target.cpu.features, .e))522 break :b if (featureSetHas(target.cpu.features, .e))