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

Fix oversized loads on x86_64 SysV FFI calls #47614

Merged
merged 1 commit into from
Feb 11, 2018

Conversation

dotdash
Copy link
Contributor

@dotdash dotdash commented Jan 20, 2018

The x86_64 SysV ABI should use exact sizes for small structs passed in
registers, i.e. a struct that occupies 3 bytes should use an i24,
instead of the i32 it currently uses.

Refs #45543

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb
Copy link
Member

eddyb commented Jan 20, 2018

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned petrochenkov Jan 20, 2018
@shepmaster shepmaster added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 20, 2018
@eddyb
Copy link
Member

eddyb commented Jan 21, 2018

Should casts ever cause oversized loads, or should we not create CastTargets larger than the type? Maybe we can redesign the CastTarget API to make sure the final size matches the original layout?

@dotdash
Copy link
Contributor Author

dotdash commented Jan 21, 2018 via email

@eddyb
Copy link
Member

eddyb commented Jan 21, 2018

I mean that either we should always be using i24 for 3-byte structs or handle the i32 correctly. Which one does clang do?

@dotdash
Copy link
Contributor Author

dotdash commented Jan 21, 2018 via email

@shepmaster
Copy link
Member

Ping from triage for you, @eddyb !

@eddyb
Copy link
Member

eddyb commented Jan 26, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Jan 26, 2018

📌 Commit a0aa101 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Jan 27, 2018

⌛ Testing commit a0aa101e458735d6282744801416dab4904592e4 with merge e8ece949ff4a8df4ca2ecc922b2c2816c0dbbb44...

@bors
Copy link
Contributor

bors commented Jan 27, 2018

💔 Test failed - status-travis

@kennytm
Copy link
Member

kennytm commented Jan 27, 2018

codegen/repr-transparent.rs needs to be updated...

--- a/src/test/codegen/repr-transparent.rs
+++ b/src/test/codegen/repr-transparent.rs
@@ -145,7 +145,7 @@ pub struct Rgb8 { r: u8, g: u8, b: u8 }
 pub struct Rgb8Wrap(Rgb8);
 
 // NB: closing parenthesis is missing because sometimes the argument has a name and sometimes not
-// CHECK: define i32 @test_Rgb8Wrap(i32
+// CHECK: define i24 @test_Rgb8Wrap(i32
 #[no_mangle]
 #[cfg(all(target_arch="x86_64", target_os="linux"))]
 pub extern fn test_Rgb8Wrap(_: Rgb8Wrap) -> Rgb8Wrap { loop {} }
[00:58:30] ---- [codegen] codegen/repr-transparent.rs stdout ----
[00:58:30] 	
[00:58:30] error: verification with 'FileCheck' failed
[00:58:30] status: exit code: 1
[00:58:30] command: "/usr/lib/llvm-3.9/bin/FileCheck" "--input-file" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/repr-transparent.ll" "/checkout/src/test/codegen/repr-transparent.rs"
[00:58:30] stdout:
[00:58:30] ------------------------------------------
[00:58:30] 
[00:58:30] ------------------------------------------
[00:58:30] stderr:
[00:58:30] ------------------------------------------
[00:58:30] /checkout/src/test/codegen/repr-transparent.rs:148:11: error: expected string not found in input
[00:58:30] // CHECK: define i32 @test_Rgb8Wrap(i32
[00:58:30]           ^
[00:58:30] /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/repr-transparent.ll:120:44: note: scanning from here
[00:58:30] define float @test_Projection(float %arg0) unnamed_addr #0 {
[00:58:30]                                            ^
[00:58:30] /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/repr-transparent.ll:129:1: note: possible intended match here
[00:58:30] define i24 @test_Rgb8Wrap(i24) unnamed_addr #0 {
[00:58:30] ^
[00:58:30] 
[00:58:30] ------------------------------------------
[00:58:30] 
[00:58:30] thread '[codegen] codegen/repr-transparent.rs' panicked at 'explicit panic', tools/compiletest/src/runtest.rs:2883:9
[00:58:30] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:58:30] 
[00:58:30] 
[00:58:30] failures:
[00:58:30]     [codegen] codegen/repr-transparent.rs
[00:58:30] 
[00:58:30] test result: �[31mFAILED�(B�[m. 50 passed; 1 failed; 16 ignored; 0 measured; 0 filtered out

@kennytm kennytm 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 Jan 27, 2018
@dotdash
Copy link
Contributor Author

dotdash commented Jan 28, 2018

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Jan 28, 2018

📌 Commit 8ecadd2 has been approved by eddyb

@@ -145,7 +145,7 @@ pub struct Rgb8 { r: u8, g: u8, b: u8 }
pub struct Rgb8Wrap(Rgb8);

// NB: closing parenthesis is missing because sometimes the argument has a name and sometimes not
// CHECK: define i32 @test_Rgb8Wrap(i32
// CHECK: define i24 @test_Rgb8Wrap(i32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail on non-x86_64 linux. Probably best to move this test into a separate file with appropriate only-*/ignore-* lines.

@hanna-kruppe
Copy link
Contributor

@bors r- The repr(transparent) test change will fail (see above).

@dotdash
Copy link
Contributor Author

dotdash commented Jan 28, 2018

Haha, I got the logic for the tests backwards, and wondered why the code already seemed prepared for this patch.

@pietroalbini
Copy link
Member

Hi @dotdash, just checking if the PR is still worked on! Could you fix the test as per #47614 (comment)?

@dotdash dotdash force-pushed the x86_64_sysv_ffi branch 2 times, most recently from 3771c77 to f08883e Compare February 6, 2018 10:31
@dotdash
Copy link
Contributor Author

dotdash commented Feb 6, 2018

@rkruppe Like that?

// option. This file may not be copied, modified, or distributed
// except according to those terms.

// only-x86_64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but this might need more restrictions, since not all x86_64 targets use the SysV ABI. Or alternatively, make the function below extern "sysv64" as in the other codegen test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I forgot to add the other only-XXX line that I meant to add, but I think forcing sysv ABI is even better here, so I'll go with that. Thanks for the suggestion

#[repr(transparent)]
pub struct Rgb8Wrap(Rgb8);

// NB: closing parenthesis is missing because sometimes the argument has a name and sometimes not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside: I think this was an artifact of the previous hack and shouldn't be necessary any more. Not that important, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That shouldn't have made a difference. The only thing that should make a difference here is whether e.g. --emit llvm-ir is given, making LLVM preserve names.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure the difference was due to declaring the function as taking an aggregate vs taking a primitive, and possibly also platform dependent. But whatever, it should definitely be consistent now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right, I botched my local test and passed the wrong struct.

#[cfg(not(all(target_arch="x86_64", target_os="linux")))]
#[no_mangle]
pub extern fn test_Rgb8Wrap(_: u32) -> u32 { loop {} }

// Same as with the small struct above: ABI-dependent, we only test the interesting case
Copy link
Contributor

@hanna-kruppe hanna-kruppe Feb 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment and the one above doesn't quite fit any more. I'd move the union FloatBits test below into repr-transparent-x86_64.rs (perhaps better called repr-transparent-sysv64.rs?) and replace everything from line 126 onwards with:

 // All that remains to be tested are aggregates. They are tested in separate files called repr-
 // transparent-*.rs  with `only-*` or `ignore-*` directives, because the expected LLVM IR
 // function signatures vary so much that it's not reasonably possible to cover all of them with a
 // single CHECK line.
 //
 // You may be wondering why we don't just compare the return types and argument types for equality
 // with FileCheck regex captures. Well, rustc doesn't perform newtype unwrapping on newtypes
 // containing aggregates. This is OK on all ABIs we support, but because LLVM has not gotten rid of
 // pointee types yet, the IR function signature will be syntactically different (%Foo* vs
 // %FooWrapper*).


// CHECK: define i32 @test_SmallUnion(i32)
#[no_mangle]
#[cfg(all(target_arch="x86_64", target_os="linux"))]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This cfg is not necessary any more, and in fact as written will fail the test on non-linux targets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sigh I shouldn't try to squeeze things in between other tasks.

The x86_64 SysV ABI should use exact sizes for small structs passed in
registers, i.e. a struct that occupies 3 bytes should use an i24,
instead of the i32 it currently uses.

Refs rust-lang#45543
@dotdash
Copy link
Contributor Author

dotdash commented Feb 8, 2018

I hope I didn't miss anything this time around...

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 8, 2018
@hanna-kruppe
Copy link
Contributor

Tests look good now. Let's wait for travis though, since these tests only run on the one target travis actually tests.

@hanna-kruppe
Copy link
Contributor

@bors r=eddyb

@bors
Copy link
Contributor

bors commented Feb 11, 2018

📌 Commit 5f3dc8b has been approved by eddyb

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 11, 2018
@bors
Copy link
Contributor

bors commented Feb 11, 2018

⌛ Testing commit 5f3dc8b with merge 2c77443...

bors added a commit that referenced this pull request Feb 11, 2018
Fix oversized loads on x86_64 SysV FFI calls

The x86_64 SysV ABI should use exact sizes for small structs passed in
registers, i.e. a struct that occupies 3 bytes should use an i24,
instead of the i32 it currently uses.

Refs #45543
@bors
Copy link
Contributor

bors commented Feb 11, 2018

💔 Test failed - status-travis

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 11, 2018
@kennytm
Copy link
Member

kennytm commented Feb 11, 2018

@bors retry #48116

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 11, 2018
@bors
Copy link
Contributor

bors commented Feb 11, 2018

⌛ Testing commit 5f3dc8b with merge 0196b20...

bors added a commit that referenced this pull request Feb 11, 2018
Fix oversized loads on x86_64 SysV FFI calls

The x86_64 SysV ABI should use exact sizes for small structs passed in
registers, i.e. a struct that occupies 3 bytes should use an i24,
instead of the i32 it currently uses.

Refs #45543
@bors
Copy link
Contributor

bors commented Feb 11, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing 0196b20 to master...

@bors bors merged commit 5f3dc8b into rust-lang:master Feb 11, 2018
@dotdash dotdash deleted the x86_64_sysv_ffi branch February 10, 2022 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants