-
Notifications
You must be signed in to change notification settings - Fork 698
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
Wrong padding size generated from different arch #1284
Comments
Can you show the generated file generated in your raspberry PI? Wanna know what's the expected size / alignment. There are a couple of uses of |
generated codeThis is generated code in raspberrypi and it's command.
// generated code
pub type aligned = [::std::os::raw::c_int; 64usize];
pub type array = [::std::os::raw::c_int; 64usize];
#[repr(C)]
#[derive(Copy, Clone)]
pub struct a_record_t {
pub buf: aligned,
pub x: ::std::os::raw::c_int,
pub __bindgen_padding_0: u32,
}
#[test]
fn bindgen_test_layout_a_record_t() {
assert_eq!(
::std::mem::size_of::<a_record_t>(),
264usize,
concat!("Size of: ", stringify!(a_record_t))
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<a_record_t>())).buf as *const _ as usize },
0usize,
concat!(
"Offset of field: ",
stringify!(a_record_t),
"::",
stringify!(buf)
)
);
assert_eq!(
unsafe { &(*(::std::ptr::null::<a_record_t>())).x as *const _ as usize },
256usize,
concat!(
"Offset of field: ",
stringify!(a_record_t),
"::",
stringify!(x)
)
);
}
#[repr(C)]
#[derive(Copy, Clone)]
pub struct b_record_t {
pub buf: array,
pub x: ::std::os::raw::c_int,
}
...(snip test cases for b_record_t)... In the generated code for the same header on my (x86_64) linux environment, there is no expected resultsIn the above generated code, And the generated code on x86_64 linux expects same size ( For further experiments, I wrote the below C code. // test.c
#include <stdio.h>
typedef int aligned[64] __attribute__((__aligned__(8)));
typedef int array[64];
typedef struct
{
aligned buf;
int x;
} a_record_t;
typedef struct
{
array buf;
int x;
} b_record_t;
#define print_sizeof(ty) \
printf("sizeof %s: %zu\n", #ty, sizeof(ty))
int main (int argc, char * argv[]) {
print_sizeof(a_record_t);
print_sizeof(b_record_t);
return 0;
} This code outputs same result to native generated rust code.
So, I guess that cross-generating is wrong. |
codegen: Use target pointer size consistently for layout calculations Assuming new enough libclang, this PR makes cross-compilation do layout calculations properly. Fixes #1284
A generated code via cross compiling environment is difference from naitive generated code.
The cross compiling environment is x86_64 linux .
And a target environment is RaspberryPi(arm-unknown-linux-gnueabihf).
Input C/C++ Header
Bindgen Invocation
On x86_64 linux, I have generated code as gen_arm.rs, and send compiled binary to my raspberrypi.
On RaspberryPi, I have generated code ordinally and compile it using native rust compiler.
Actual Results
Below is the result of the layout test which is generated on x86_64 linux environment.
On the other hand, below is the result of the same test above.
But the test code have been generated on RaspberryPi.
Expected Results
What is expected of results of tests, both results are matching.
The text was updated successfully, but these errors were encountered: