-
Notifications
You must be signed in to change notification settings - Fork 23
Add powerpc64le Linux support #61
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did some testing on powerpc64 qemu (with 2b4700e to add the missing ucontext support). Currently this seems to crash even on the base smoke tests. The issue seems to be that function pointers on powerpc actually point to a 3-word descriptor with pc, r2 and r11 values. See https://rust.godbolt.org/z/c9enqqej7 for an example.
This is an initial review, I will do a more in-depth one once the initial problems are fixed.
Thanks for the review, @Amanieu! From the Compiler Explorer session (https://rust.godbolt.org/z/c9enqqej7, it looks like you compiled with The implementation runs 16 out of 21 unit tests successfully on RedHat. |
|
I see, powerpc64 uses the ELFv1 ABI while powerc64le uses the ELFv2 ABI. You should be able to explicitly handle these with rust-lang/rust#142321. Although for now if might be ok to just |
|
Right, disregard my previous comments on the stack layout, I need to re-read the ABI document in detail. |
|
I've tried to clean up the stack layout for the coroutine here: a783805 Let me know if you think this will work or if I missed anything. |
- change the stack layout as per suggestion, - save/restore the TOC register R2.
78efe8e to
576c081
Compare
|
I've updated the stack layout as you suggested. Thank you! |
This PR adds support for
powerpc64leLinux. With this implementation, 3 examples under theexamplesdirectory and 16 out of 21 unit tests have passed. The following test cases fail and are ignored for this target.backtrace_traces_to_hostincoroutine.rsandon_stack.rsThe nightly compiler initially failed to generate the
eh_frameconstruct. After updating to1.92.0-nightly (839222065 2025-10-05), it does generateeh_framebut the test hit a seg-fault in GCC’s unwinder. These tests are disabled for now.trap_handler,trap_handler_panic, andstack_overflowIt seems the problem is after
signal_handlerreturns, the control is routed totrap_handlerinstead of the location where the signal happened. In thepowerpc64ELF ABI, volatile registerr12is used for function linkage and is caller-saved. If a function call before the signal (e.g.,println!("Before trap");in testtrap_handler) overwritesr12, e.g. to0x0, thesigcontextrecord will also contain0x0forr12. When control goes from the signal handler totrap_handler,r12remains0x0, Whenstd::panic::catch_unwind, called indirectly bytrap_handler, constructs the function address for__rust_tryout ofr12, it ends up an invalid value, and trigger a seg-fault or illegal instruction.I'm not very familiar with Valgrind, so it’s currently unsupported on powerpc64 in this implementation. Any insights or guidance would be greatly appreciated.
Note: the test has dependency on the
ucontext_tstructure from thelibccrate. PR Add ucontext_t and {get,set,make,swap}context for powerpc64-linux (cont.) has been approved but not yet included in thelibcstable branch and release yet.