Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd powerpc64 and powerpc64le support #30776
Conversation
rust-highfive
assigned
pnkfelix
Jan 8, 2016
This comment has been minimized.
This comment has been minimized.
|
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. |
eefriedman
reviewed
Jan 8, 2016
| target_arch = "powerpc")))] | ||
| target_arch = "powerpc", | ||
| target_arch = "powerpc64", | ||
| target_arch = "powerpc64le")))] |
This comment has been minimized.
This comment has been minimized.
eefriedman
Jan 8, 2016
Contributor
This looks suspicious; are you sure this should be 8, and not 16?
This comment has been minimized.
This comment has been minimized.
antonblanchard
Jan 8, 2016
Author
Contributor
Good catch, jemalloc should align to 16B on ppc64. testing this change now.
eefriedman
reviewed
Jan 8, 2016
| @@ -205,7 +205,8 @@ mod arch { | |||
| } | |||
| } | |||
|
|
|||
| #[cfg(target_arch = "x86_64")] | |||
| #[cfg(any(target_arch = "x86_64", target_arch = "powerpc64", | |||
| target_arch = "powerpc64le"))] | |||
This comment has been minimized.
This comment has been minimized.
eefriedman
Jan 8, 2016
Contributor
Have you checked that the sizes of all these types are correct? (They probably are, but it's worth double-checking.)
This comment has been minimized.
This comment has been minimized.
antonblanchard
Jan 12, 2016
Author
Contributor
Yes, just to confirm:
blkcnt_t 64
blksize_t 64
ino_t 64
nlink_t 64
off_t 64
time_t 64
eefriedman
reviewed
Jan 8, 2016
| @@ -0,0 +1,245 @@ | |||
| // Copyright 2014-2016 The Rust Project Developers. See the COPYRIGHT | |||
This comment has been minimized.
This comment has been minimized.
eefriedman
Jan 8, 2016
Contributor
This file has a lot of duplicated code from cabi_powerpc64.rs; it needs to be refactored.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
mpe
Jan 8, 2016
The only difference I see is in classify_ret_ty(), where the LE version is doing more complicated logic. But I suspect BE should probably also do that logic, in which case the two files would actually be identical?
This comment has been minimized.
This comment has been minimized.
antonblanchard
Jan 8, 2016
Author
Contributor
There are differences between the BE and LE ABI when it comes to returning aggregates. As an example:
struct foo {
float a[8];
};
struct foo blah(struct foo x)
{
return x;
}
On big endian we pass the return value via a pointer in r3:
blah:
std 4, 0(3)
std 5, 8(3)
std 6, 16(3)
std 7, 24(3)
blr
On little endian we pass it via registers:
blah:
blr
This comment has been minimized.
This comment has been minimized.
eefriedman
reviewed
Jan 8, 2016
|
|
||
| fn align_up_to(off: usize, a: usize) -> usize { | ||
| return (off + a - 1) / a * a; | ||
| } |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
For reference, there's an associated PR against libc: rust-lang/libc#133 . |
eefriedman
reviewed
Jan 8, 2016
|
|
||
| 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 }; |
This comment has been minimized.
This comment has been minimized.
eefriedman
Jan 8, 2016
Contributor
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.
This comment has been minimized.
This comment has been minimized.
antonblanchard
Jan 8, 2016
Author
Contributor
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
This comment has been minimized.
This comment has been minimized.
eefriedman
Jan 8, 2016
Contributor
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) }).
This comment has been minimized.
This comment has been minimized.
antonblanchard
Jan 8, 2016
Author
Contributor
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?
This comment has been minimized.
This comment has been minimized.
eefriedman
Jan 10, 2016
Contributor
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 .
This comment has been minimized.
This comment has been minimized.
antonblanchard
Jan 11, 2016
Author
Contributor
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.
This comment has been minimized.
This comment has been minimized.
eefriedman
Jan 11, 2016
Contributor
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.
mpe
reviewed
Jan 8, 2016
| fn getrandom(buf: &mut [u8]) -> libc::c_long { | ||
| #[cfg(target_arch = "x86_64")] | ||
| const NR_GETRANDOM: libc::c_long = 318; | ||
| #[cfg(target_arch = "x86")] | ||
| const NR_GETRANDOM: libc::c_long = 355; | ||
| #[cfg(any(target_arch = "arm", target_arch = "powerpc"))] | ||
| #[cfg(any(target_arch = "arm", target_arch = "powerpc", | ||
| target_arch = "powerpc64", target_arch = "powerpc64le"))] | ||
| const NR_GETRANDOM: libc::c_long = 384; |
This comment has been minimized.
This comment has been minimized.
mpe
Jan 8, 2016
If I'm reading this right that's saying __NR_getrandom == 384, which is wrong. It's 359 for all powerpc kernels.
This comment has been minimized.
This comment has been minimized.
antonblanchard
Jan 8, 2016
Author
Contributor
Nice catch Michael, this looks like a bug introduced when powerpc32 support was added.
mpe
reviewed
Jan 8, 2016
| @@ -83,7 +83,8 @@ pub const unwinder_private_data_size: usize = 2; | |||
| #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] | |||
| pub const unwinder_private_data_size: usize = 2; | |||
|
|
|||
| #[cfg(target_arch = "powerpc")] | |||
| #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64", | |||
| target_arch = "powerpc64le"))] | |||
| pub const unwinder_private_data_size: usize = 2; | |||
This comment has been minimized.
This comment has been minimized.
mpe
Jan 8, 2016
I'm guessing this needs to match _Unwind_Exception from clang? If so that looks right.
alexcrichton
reviewed
Jan 12, 2016
| @@ -1337,7 +1342,8 @@ do | |||
| make_dir $t/rt/compiler-rt | |||
| for i in \ | |||
| isaac sync test \ | |||
| arch/i386 arch/x86_64 arch/arm arch/aarch64 arch/mips arch/powerpc | |||
| arch/i386 arch/x86_64 arch/arm arch/aarch64 arch/mips arch/powerpc \ | |||
| arch/powerpc64 arch/powerpc64le | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jan 12, 2016
Member
It should be fine to not update this, these are largely just all a bunch of old directories that aren't used any more
alexcrichton
reviewed
Jan 12, 2016
| @@ -15,7 +15,8 @@ fn target() { | |||
| assert_eq!(-1000 as usize >> 3_usize, 536870787_usize); | |||
| } | |||
|
|
|||
| #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] | |||
| #[cfg(any(target_arch = "x86_64", target_arch = "aarch64", | |||
| target_arch = "powerpc64", target_arch = "powerpc64le"))] | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
reviewed
Jan 12, 2016
| #[cfg(any(target_arch = "x86_64", target_arch = "arm", target_arch = "aarch64"))] | ||
| #[cfg(any(target_arch = "x86_64", target_arch = "arm", | ||
| target_arch = "aarch64", target_arch = "powerpc64", | ||
| target_arch = "powerpc64le"))] |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Looking good to me, thanks @antonblanchard! |
antonblanchard
force-pushed the
antonblanchard:powerpc64_merge
branch
from
5748cdc
to
8c213d3
Jan 13, 2016
antonblanchard
added some commits
Dec 28, 2015
antonblanchard
force-pushed the
antonblanchard:powerpc64_merge
branch
from
8c213d3
to
12aec07
Jan 13, 2016
This comment has been minimized.
This comment has been minimized.
|
Anything else that needs fixing? |
This comment has been minimized.
This comment has been minimized.
antonblanchard
referenced this pull request
Jan 15, 2016
Closed
librustc_trans: function parameters should be annotated with zeroext/signext #30841
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Jan 15, 2016
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Jan 15, 2016
This comment has been minimized.
This comment has been minimized.
|
|
antonblanchard commentedJan 8, 2016
This adds support for big endian and little endian PowerPC64.
make check runs clean apart from one big endian backtrace issue.