-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add powerpc64 and powerpc64le support #30776
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
target_arch = "powerpc")))] | ||
target_arch = "powerpc", | ||
target_arch = "powerpc64", | ||
target_arch = "powerpc64le")))] |
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.
This looks suspicious; are you sure this should be 8, and not 16?
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.
Good catch, jemalloc should align to 16B on ppc64. testing this change now.
For reference, there's an associated PR against libc: rust-lang/libc#133 . |
|
||
fn classify_arg_ty(ccx: &CrateContext, ty: Type) -> ArgType { | ||
if is_reg_ty(ty) { | ||
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None }; |
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.
Are you sure this is correct? I think you're supposed to zero/sign-extend all integers less than 64 bits.
More generally, tests would be nice; there aren't any target-specific tests at the moment in rust/src/test/codegen/, but they would be good to have.
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.
This came straight from the cabi_powerpc32.rs version. You are right both powerpc32 and powerpc64 do need to sign extend smaller signed arguments.
I am somewhat confused by what the cabi code is required to do. It isn't modelling the ABI completely, because it would have to track actual GPR and FPR allocations to know when we are out of GPRs/FPRs and have to start using stack slots.
This small example appears to show powerpc64 rust sign extending as expected:
extern {
fn one_arg(a: i64);
}
pub fn blah(x: i32)
{
unsafe {
one_arg(x as i64)
}
}
14: b4 07 63 7c extsw r3,r3
18: 01 00 00 48 bl 18 <_ZN4blah20heddc57cb357ff834kaaE+0x18>
18: R_PPC64_REL24 one_arg
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.
That isn't the right testcase; try something like this:
#![crate_type="lib"]
extern {
fn one_arg(a: i32);
}
pub fn blah(x: u64)
{
unsafe {
one_arg(x as i32)
}
}
I think this should sign-extend (compare to the equivalent C void f(int); void g(unsigned long long x) { f(x) }
).
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.
Thanks @eefriedman, that does show us zero extending incorrectly. I'm still uncertain as to how much of the ABI we need to model here. How does rust know when we run out of GPRs for parameters and it has to go to the stack for example?
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.
LLVM's handling of the C calling convention is kind of awkward. Basically, you can expect it to handle scalars parameters correctly (int, void*, float, etc.), but it tends to get weird with other types (structs, arrays, complex types, etc). Lowering them correctly gets tricky in cases where you can't use "byval". The best resource is generally https://github.com/llvm-mirror/clang/blob/master/lib/CodeGen/TargetInfo.cpp .
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.
Thanks @eefriedman, that helps a lot. Unfortunately it looks like we lose signedness info before calling target code. We convert to LLVM types (type_of -> Type::uint_from_ty/Type::int_from_ty) which have no distinction between signed and unsigned, and pass these to target code.
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.
Oh. Long-term, the ABI code obviously needs the Rust types as input, not LLVM types... but it's probably okay to just file an issue report and put in a FIXME here referring to it.
Looking good to me, thanks @antonblanchard! |
5748cdc
to
8c213d3
Compare
This adds support for big endian and little endian PowerPC64. make check runs clean apart from one big endian backtrace issue.
Michael Ellerman pointed out that the system call for getrandom() on PowerPC Linux is incorrect. This bug was in the powerpc32 port, and was carried over to the powerpc64 port too.
While adding PowerPC64 support it was noticed that some testcases should just use target_pointer_width, and others should select between x86 and !x86.
8c213d3
to
12aec07
Compare
Anything else that needs fixing? |
⌛ Testing commit 12aec07 with merge 28bf907... |
…lexcrichton This adds support for big endian and little endian PowerPC64. make check runs clean apart from one big endian backtrace issue.
⛄ The build was interrupted to prioritize another pull request. |
This adds support for big endian and little endian PowerPC64.
make check runs clean apart from one big endian backtrace issue.