Skip to content
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

Merged
merged 3 commits into from Jan 15, 2016

Conversation

Projects
None yet
7 participants
@antonblanchard
Copy link
Contributor

antonblanchard commented Jan 8, 2016

This adds support for big endian and little endian PowerPC64.
make check runs clean apart from one big endian backtrace issue.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 8, 2016

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")))]

This comment has been minimized.

@eefriedman

eefriedman Jan 8, 2016

Contributor

This looks suspicious; are you sure this should be 8, and not 16?

This comment has been minimized.

@antonblanchard

antonblanchard Jan 8, 2016

Author Contributor

Good catch, jemalloc should align to 16B on ppc64. testing this change now.

@@ -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.

@eefriedman

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.

@antonblanchard

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
@@ -0,0 +1,245 @@
// Copyright 2014-2016 The Rust Project Developers. See the COPYRIGHT

This comment has been minimized.

@eefriedman

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.

@antonblanchard

antonblanchard Jan 8, 2016

Author Contributor

Thanks, will do

This comment has been minimized.

@mpe

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.

@antonblanchard

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.

@mpe

mpe Jan 11, 2016

Oh sorry, I skimmed the ABI doc but obviously too lightly.


fn align_up_to(off: usize, a: usize) -> usize {
return (off + a - 1) / a * a;
}

This comment has been minimized.

@eefriedman

eefriedman Jan 8, 2016

Contributor

Err, wait, nevermind.

@eefriedman

This comment has been minimized.

Copy link
Contributor

eefriedman commented Jan 8, 2016

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 };

This comment has been minimized.

@eefriedman

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.

@antonblanchard

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.

@eefriedman

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.

@antonblanchard

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.

@eefriedman

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.

@antonblanchard

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.

@eefriedman

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.

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.

@mpe

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.

@antonblanchard

antonblanchard Jan 8, 2016

Author Contributor

Nice catch Michael, this looks like a bug introduced when powerpc32 support was added.

@@ -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.

@mpe

mpe Jan 8, 2016

I'm guessing this needs to match _Unwind_Exception from clang? If so that looks right.

configure Outdated
@@ -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.

@alexcrichton

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

@@ -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.

@alexcrichton

alexcrichton Jan 12, 2016

Member

Could you switch this to target_pointer_width?

#[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.

@alexcrichton

alexcrichton Jan 12, 2016

Member

Could you switch this to target_pointer_width as well?

This comment has been minimized.

@alexcrichton

alexcrichton Jan 12, 2016

Member

actually, similar to a bunch below as well

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 12, 2016

Looking good to me, thanks @antonblanchard!

@antonblanchard antonblanchard force-pushed the antonblanchard:powerpc64_merge branch from 5748cdc to 8c213d3 Jan 13, 2016

antonblanchard added some commits Dec 28, 2015

Add powerpc64 and powerpc64le support
This adds support for big endian and little endian PowerPC64.
make check runs clean apart from one big endian backtrace issue.
Incorrect getrandom() system call for PowerPC Linux
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.
Simplify some uses of cfg in test cases
While adding PowerPC64 support it was noticed that some testcases should
just use target_pointer_width, and others should select between
x86 and !x86.

@antonblanchard antonblanchard force-pushed the antonblanchard:powerpc64_merge branch from 8c213d3 to 12aec07 Jan 13, 2016

@antonblanchard

This comment has been minimized.

Copy link
Contributor Author

antonblanchard commented Jan 14, 2016

Anything else that needs fixing?

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Jan 14, 2016

@bors: r+ 12aec07

Looks good to me!

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 15, 2016

⌛️ Testing commit 12aec07 with merge 28bf907...

bors added a commit that referenced this pull request Jan 15, 2016

Auto merge of #30776 - antonblanchard:powerpc64_merge, r=alexcrichton
This adds support for big endian and little endian PowerPC64.
make check runs clean apart from one big endian backtrace issue.

Manishearth added a commit to Manishearth/rust that referenced this pull request Jan 15, 2016

Rollup merge of rust-lang#30776 - antonblanchard:powerpc64_merge, r=a…
…lexcrichton

This adds support for big endian and little endian PowerPC64.
make check runs clean apart from one big endian backtrace issue.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 15, 2016

⛄️ The build was interrupted to prioritize another pull request.

@bors bors merged commit 12aec07 into rust-lang:master Jan 15, 2016

1 of 2 checks passed

homu :snowman: The build was interrupted to prioritize another pull request.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.