Skip to content

Add powerpc64-unknown-linux-gnuelfv2 target#144220

Open
Gelbpunkt wants to merge 1 commit into
rust-lang:mainfrom
Gelbpunkt:powerpc64-unknown-linux-gnuelfv2
Open

Add powerpc64-unknown-linux-gnuelfv2 target#144220
Gelbpunkt wants to merge 1 commit into
rust-lang:mainfrom
Gelbpunkt:powerpc64-unknown-linux-gnuelfv2

Conversation

@Gelbpunkt

@Gelbpunkt Gelbpunkt commented Jul 20, 2025

Copy link
Copy Markdown
Contributor

View all comments

This is virtually the same target as the existing -gnu target, but using the ELFv2 ABI instead of the ELFv1 ABI and made possible now that we expose target_abi = "elfv1" or "elfv2" on the 64-bit PowerPC targets.

The ELFv2 ABI is the preferred ABI for powerpc64 when compatibility with ELFv1 is not required and therefore used by e.g. distributions that were bootstrapped after the introduction of ELFv2.

Copying the target tier policy:

A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

That would be me.

Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.

This is an interesting one, because I'm not aware of any toolchain that has a target triple for ppc64 + glibc + ELFv2, even though it is a totally valid combination and actively in used by some distributions. Clang and GCC both simply use -target powerpc64-unknown-linux-gnu -mabi=elfv2 to my knowledge (and cross-toolchains should be using --with-abi=elfv2 when configuring GCC). However, the chosen name should be somewhat in line with the other existing targets with special ABIs. Renaming powerpc64-unknown-linux-gnu to powerpc64-unknown-linux-gnuelfv1 at the same time to avoid ambiguity would've been an interesting idea, but it'd be a breaking change to a tier 2 target.

Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.

This target isn't any different than the ELFv1 target in this regard.

Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.

Nothing to comment on here on my end.

Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

This target implements the entire standard library.

The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

Documentation can be found in the markdown document added by this PR.

Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via @) to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.

Roger that :)

Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

This PR doesn't touch any other targets.

Tier 3 targets must be able to produce assembly using at least one of rustc's supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)

The LLVM backend works.

r? compiler

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 20, 2025
@rustbot

rustbot commented Jul 20, 2025

Copy link
Copy Markdown
Collaborator

These commits modify compiler targets.
(See the Target Tier Policy.)

Some changes occurred in src/doc/rustc/src/platform-support

cc @Noratrieb

@rust-log-analyzer

This comment has been minimized.

@Gelbpunkt

Gelbpunkt commented Jul 20, 2025

Copy link
Copy Markdown
Contributor Author

Interesting, seems like a usecase like this one in particular is currently not intended, see here. The explicitly set ABI is processed in create_informational_target_machine, but apparently it doesn't make it through to the final data layout calculated.

EDIT: This is an LLVM bug, it doesn't reset the data layout when the ABI is explicitly set, while it does on ARM

@Gelbpunkt

Gelbpunkt commented Jul 20, 2025

Copy link
Copy Markdown
Contributor Author

LLVM side of the problem should hopefully get fixed by llvm/llvm-project#149725, I'll have to figure out how to get the bundled LLVM to use the patch in order to verify it it works!

@Gelbpunkt Gelbpunkt force-pushed the powerpc64-unknown-linux-gnuelfv2 branch from 255b058 to 755a1c9 Compare July 20, 2025 18:23
@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Jul 20, 2025
@rustbot

This comment has been minimized.

@Gelbpunkt Gelbpunkt force-pushed the powerpc64-unknown-linux-gnuelfv2 branch from 755a1c9 to ae5d567 Compare July 20, 2025 18:25
@rust-log-analyzer

This comment has been minimized.

@Gelbpunkt Gelbpunkt force-pushed the powerpc64-unknown-linux-gnuelfv2 branch from ae5d567 to d7200f0 Compare July 20, 2025 19:32
@rust-log-analyzer

This comment has been minimized.

Comment thread .gitmodules Outdated
@jieyouxu

Copy link
Copy Markdown
Member

@rustbot author
r? compiler_leads

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 21, 2025
@rustbot

rustbot commented Jul 21, 2025

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot assigned davidtwco and unassigned compiler-errors Jul 21, 2025
@bors

bors commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #144249) made this pull request unmergeable. Please resolve the merge conflicts.

@davidtwco davidtwco added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 24, 2025
@workingjubilee workingjubilee added the S-waiting-on-LLVM Status: the compiler-dragon is eepy, can someone get it some tea? label Oct 2, 2025
@Gelbpunkt Gelbpunkt force-pushed the powerpc64-unknown-linux-gnuelfv2 branch from d7200f0 to 23a159f Compare June 3, 2026 21:12
@rustbot

rustbot commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Gelbpunkt

Copy link
Copy Markdown
Contributor Author

This is no longer blocked since we now use LLVM 22.

@RalfJung

RalfJung commented Jun 4, 2026

Copy link
Copy Markdown
Member

We still support LLVM 21 AFAIK. Is that a problem?

@Gelbpunkt

Copy link
Copy Markdown
Contributor Author

We still support LLVM 21 AFAIK. Is that a problem?

I believe not, at least if I understand David's comment (#144220 (comment)) correctly. We only test that codegen works for the target if LLVM 22 is in use. I guess it would probably be worth documenting the LLVM 22 requirement on the target page as long as 21 is supported.

@RalfJung

RalfJung commented Jun 4, 2026

Copy link
Copy Markdown
Member

We only test that codegen works for the target if LLVM 22 is in use.

That just means we don't see the problem, but the problem still exists. ;)

@Gelbpunkt

Copy link
Copy Markdown
Contributor Author

Well, code compiled with LLVM 21 will still run fine. The datalayout difference between the two is Fi64 instead of Fn32, which means we'll be overaligning function entries, that's pretty harmless I think.

If I remember correctly, rustc does patch the data layouts for a few targets to match newer LLVM if present. We could put the ELFv1 datalayout here for now and patch it to use the correct one if LLVM 22 is in use. Both will build working binaries.

@RalfJung

RalfJung commented Jun 4, 2026

Copy link
Copy Markdown
Member

which means we'll be overaligning function entries,

Oh yeah if that's the only difference then that sounds entirely harmless (unless something more cursed than I can imagine is going on).

This is virtually the same target as the existing -gnu target, but using
the ELFv2 ABI instead of the ELFv1 ABI and made possible now that we
expose target_abi = "elfv1" or "elfv2" on the 64-bit PowerPC targets.
@Gelbpunkt Gelbpunkt force-pushed the powerpc64-unknown-linux-gnuelfv2 branch from 23a159f to a832c14 Compare June 4, 2026 22:43
@Gelbpunkt

Copy link
Copy Markdown
Contributor Author

Implemented that, so this now also works with LLVM 21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-LLVM Status: the compiler-dragon is eepy, can someone get it some tea? T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants