Skip to content

Add powerpc64-unknown-linux-gnuelfv2 target #144220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
shallow = true
[submodule "src/llvm-project"]
path = src/llvm-project
url = https://github.com/rust-lang/llvm-project.git
branch = rustc/20.1-2025-07-13
url = https://github.com/Gelbpunkt/llvm-project.git
branch = rust-ppc64-gnu-elfv2
Comment on lines +27 to +28
Copy link
Member

@jieyouxu jieyouxu Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: this is fine for experimenting, but we can't land it in master with a fork. (I assume this is blocked on the upstream LLVM fix?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's blocked on the fix, but I'm not sure what to do afterwards. I guess it could be included in the Rust LLVM fork, but it still won't be included in some of the builders that use the old system LLVM. Those will fail CI like the aarch64-gnu-llvm-19-1 job above

shallow = true
[submodule "src/doc/embedded-book"]
path = src/doc/embedded-book
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,7 @@ supported_targets! {
("powerpc-unknown-linux-muslspe", powerpc_unknown_linux_muslspe),
("powerpc64-ibm-aix", powerpc64_ibm_aix),
("powerpc64-unknown-linux-gnu", powerpc64_unknown_linux_gnu),
("powerpc64-unknown-linux-gnuelfv2", powerpc64_unknown_linux_gnuelfv2),
("powerpc64-unknown-linux-musl", powerpc64_unknown_linux_musl),
("powerpc64le-unknown-linux-gnu", powerpc64le_unknown_linux_gnu),
("powerpc64le-unknown-linux-musl", powerpc64le_unknown_linux_musl),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use rustc_abi::Endian;

use crate::spec::{
Cc, LinkerFlavor, Lld, StackProbeType, Target, TargetMetadata, TargetOptions, base,
};

pub(crate) fn target() -> Target {
let mut base = base::linux_gnu::opts();
base.cpu = "ppc64".into();
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::Inline;
base.abi = "elfv2".into();
base.llvm_abiname = "elfv2".into();

Target {
llvm_target: "powerpc64-unknown-linux-gnu".into(),
metadata: TargetMetadata {
description: Some("PPC64 Linux (ELFv2 ABI, kernel 3.2, glibc 2.17)".into()),
tier: Some(3),
host_tools: Some(false),
std: Some(true),
},
pointer_width: 64,
data_layout: "E-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512".into(),
arch: "powerpc64".into(),
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base },
}
}
1 change: 1 addition & 0 deletions src/bootstrap/src/core/sanity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub struct Finder {
// Targets can be removed from this list once they are present in the stage0 compiler (usually by updating the beta compiler of the bootstrap).
const STAGE0_MISSING_TARGETS: &[&str] = &[
// just a dummy comment so the list doesn't get onelined
"powerpc64-unknown-linux-gnuelfv2",
];

/// Minimum version threshold for libstdc++ required when using prebuilt LLVM
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
- [powerpc-unknown-linux-gnuspe](platform-support/powerpc-unknown-linux-gnuspe.md)
- [powerpc-unknown-linux-muslspe](platform-support/powerpc-unknown-linux-muslspe.md)
- [powerpc64-ibm-aix](platform-support/aix.md)
- [powerpc64-unknown-linux-gnuelfv2](platform-support/powerpc64-unknown-linux-gnuelfv2.md)
- [powerpc64-unknown-linux-musl](platform-support/powerpc64-unknown-linux-musl.md)
- [powerpc64le-unknown-linux-gnu](platform-support/powerpc64le-unknown-linux-gnu.md)
- [powerpc64le-unknown-linux-musl](platform-support/powerpc64le-unknown-linux-musl.md)
Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ target | std | host | notes
[`powerpc-wrs-vxworks-spe`](platform-support/vxworks.md) | ✓ | |
[`powerpc64-ibm-aix`](platform-support/aix.md) | ? | | 64-bit AIX (7.2 and newer)
[`powerpc64-unknown-freebsd`](platform-support/freebsd.md) | ✓ | ✓ | PPC64 FreeBSD (ELFv2)
[`powerpc64-unknown-linux-gnuelfv2`](platform-support/powerpc64-unknown-linux-gnuelfv2.md) | ✓ | ✓ | PPC64 Linux (ELFv2 ABI, kernel 3.2, glibc 2.17)
[`powerpc64-unknown-linux-musl`](platform-support/powerpc64-unknown-linux-musl.md) | ✓ | ✓ | PPC64 Linux (kernel 4.19, musl 1.2.3)
[`powerpc64-unknown-openbsd`](platform-support/openbsd.md) | ✓ | ✓ | OpenBSD/powerpc64
[`powerpc64-wrs-vxworks`](platform-support/vxworks.md) | ✓ | |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# powerpc64-unknown-linux-gnuelfv2

**Tier: 3**

Target for 64-bit big endian PowerPC Linux programs using the ELFv2 ABI and
the GNU C library.

## Target maintainers

[@Gelbpunkt](https://github.com/Gelbpunkt)

## Requirements

Building the target itself requires a 64-bit big endian PowerPC compiler that
uses the ELFv2 ABI and is supported by `cc-rs`.

## Building the target

The target can be built by enabling it for a `rustc` build.

```toml
[build]
target = ["powerpc64-unknown-linux-gnuelfv2"]
```

Make sure your C compiler is included in `$PATH`, then add it to the
`bootstrap.toml`:

```toml
[target.powerpc64-unknown-linux-gnuelfv2]
cc = "powerpc64-linux-gnu-gcc"
cxx = "powerpc64-linux-gnu-g++"
ar = "powerpc64-linux-gnu-ar"
linker = "powerpc64-linux-gnu-gcc"
```

## Building Rust programs

Rust does not yet ship pre-compiled artifacts for this target. To compile for
this target, you will first need to build Rust with the target enabled (see
"Building the target" above).

## Cross-compilation

This target can be cross-compiled from any host.

## Testing

This target can be tested as normal with `x.py` on a 64-bit big endian PowerPC
host or via QEMU emulation.
3 changes: 3 additions & 0 deletions tests/assembly/targets/targets-elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@
//@ revisions: powerpc64_unknown_linux_gnu
//@ [powerpc64_unknown_linux_gnu] compile-flags: --target powerpc64-unknown-linux-gnu
//@ [powerpc64_unknown_linux_gnu] needs-llvm-components: powerpc
//@ revisions: powerpc64_unknown_linux_gnuelfv2
//@ [powerpc64_unknown_linux_gnuelfv2] compile-flags: --target powerpc64-unknown-linux-gnuelfv2
//@ [powerpc64_unknown_linux_gnuelfv2] needs-llvm-components: powerpc
//@ revisions: powerpc64_unknown_linux_musl
//@ [powerpc64_unknown_linux_musl] compile-flags: --target powerpc64-unknown-linux-musl
//@ [powerpc64_unknown_linux_musl] needs-llvm-components: powerpc
Expand Down
Loading