Skip to content

Additional padding on windows #553

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

Closed
Dushistov opened this issue Mar 3, 2017 · 6 comments
Closed

Additional padding on windows #553

Dushistov opened this issue Mar 3, 2017 · 6 comments

Comments

@Dushistov
Copy link
Contributor

Versions

On both machines bindgen commit d57616c
On windows machine: clang 3.9.0
On linux machine: 3.8.1

Input C/C++ Header

union jvalue {
  float   f;
  double  d;
};

Bindgen Invokation

$ bindgen --no-unstable-rust input.h 

Actual Results

#[repr(C)]
#[derive(Debug, Copy)]
pub struct jvalue {
    pub f: __BindgenUnionField<f32>,
    pub __bindgen_padding_0: u32,
    pub d: __BindgenUnionField<f64>,
    pub bindgen_union_field: u64,
}
test bindgen_test_layout_jvalue ... FAILED

failures:

---- bindgen_test_layout_jvalue stdout ----
        thread 'bindgen_test_layout_jvalue' panicked at 'assertion failed: `(lef
t == right)` (left: `16`, right: `8`): Size of: jvalue', lib.rs:37
note: Run with `RUST_BACKTRACE=1` for a backtrace.

failures:
    bindgen_test_layout_jvalue

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

error: test failed

Expected Results

On linux machine bindgen not generate pub __bindgen_padding_0: u32,
and add

assert_eq! (::std::mem::align_of::<jvalue>() , 8usize , concat ! (
                "Alignment of " , stringify ! ( jvalue ) ));

to test code,

This is only difference between code generated by bindgen (d57616c) on both machines.

Dushistov added a commit to Dushistov/flapigen-rs that referenced this issue Mar 3, 2017
because of bindgen still can not handle
jvalue, see:
rust-lang/rust-bindgen#553

plus remove not used run_tests.sh
@emilio
Copy link
Contributor

emilio commented Mar 3, 2017

huh, why are we padding unions anyway?

Thanks for the report.

@emilio
Copy link
Contributor

emilio commented Mar 3, 2017

Can you paste your log with RUST_LOG=codegen::struct_layout on windows? A fix is disabling padding for unions, but I wonder what offset are we getting from clang anyway, given I can't reproduce with -target x86_64-pc-windows-msvc nor -target i386-pc-windows-msvc?

emilio added a commit to emilio/rust-bindgen that referenced this issue Mar 3, 2017
@emilio
Copy link
Contributor

emilio commented Mar 3, 2017

Can you verify #554 fixes it?

@Dushistov
Copy link
Contributor Author

Can you paste your log with RUST_LOG=codegen::struct_layout on windows? A fix is disabling padding for unions, but I wonder what offset are we getting from clang anyway, given I can't reproduce with -target x86_64-pc-windows-msvc nor -target i386-pc-windows-msvc?

: Offset: <padding>: 0 -> 0
: align field f to 0/0 with 0 padding bytes Layout { size: 4, align: 4, packed: false }
: Offset: f: 0 -> 4
: align_to_bitfield? false: Layout { size: 4, align: 4, packed: false } Layout { size: 8, align: 8, packed: false }
: Offset: <padding>: 4 -> 8
: align field d to 8/0 with 4 padding bytes Layout { size: 8, align: 8, packed: false }
: Offset: d: 8 -> 16
: align_to_bitfield? false: Layout { size: 8, align: 8, packed: false } Layout { size: 8, align: 8, packed: false }

@Dushistov
Copy link
Contributor Author

Can you verify #554 fixes it?

At now generated code passed generated tests.

I also add assert_eq!(8, ::std::mem::align_of::<jvalue>()); and it also passed this tests,
so I close this bug?

@emilio
Copy link
Contributor

emilio commented Mar 3, 2017

Let's close this when #554 lands :)

bors-servo pushed a commit that referenced this issue Mar 3, 2017
codegen: Don't pad union fields.

Fixes #553
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants