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 incomplete array alignment in struct #1360

Closed
wants to merge 1 commit into from

Conversation

photoszzt
Copy link
Contributor

Fix #1359

@highfive
Copy link

highfive commented Aug 6, 2018

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

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

Hmm, somehow github didn't save my review comments.

@@ -3658,17 +3658,23 @@ mod utils {
let incomplete_array_decl = quote! {
#[repr(C)]
#[derive(Default)]
pub struct __IncompleteArrayField<T>(
::#prefix::marker::PhantomData<T>);
pub struct __IncompleteArrayField<T>{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: there's a space missing here.

@@ -0,0 +1,3 @@
struct bpf_raw_tracepoint_args {
unsigned long long args[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a test with another struct with a smaller integer type (like short, maybe?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, good catch. The alignment is still 8 with the current code when I change to a smaller integer type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems the pointer alignment is always 8 on 64 bit platform. Ideally, the _alignment field should be [T; 0] but that would prevent automatically implementing Copy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see, for some reason I thought the should always have pointer alignment... I think [T; 0] is the right thing to do, these structs aren't safe to copy generally anyway.

@photoszzt
Copy link
Contributor Author

Hmm, not quite understand the error. Seems that fails at clang not the binding generation.

@bors-servo
Copy link

☔ The latest upstream changes (presumably #1477) made this pull request unmergeable. Please resolve the merge conflicts.

@emilio
Copy link
Contributor

emilio commented Aug 31, 2019

I think with repr(align) support and other fixes that have landed in the meantime like #1592 the issue should be fixed. This also is stale.

Thanks for the patch (and your other fixes) a lot @photoszzt!

@emilio emilio closed this Aug 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

incomplete array in struct alignment is wrong
4 participants