Skip to content

bindgen with explicit padding generates an array of size 18446744073709551608 #3068

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
qsr opened this issue Jan 6, 2025 · 1 comment · Fixed by #3173
Closed

bindgen with explicit padding generates an array of size 18446744073709551608 #3068

qsr opened this issue Jan 6, 2025 · 1 comment · Fixed by #3173

Comments

@qsr
Copy link

qsr commented Jan 6, 2025

When running bindgen with the --explicit-padding option on the following file:

struct Foo {
  union {
    char d0[2];
    char d1[1];
    char d2[0];
  };
};

it ends up generating the following struct:

#[repr(C)]
pub struct Foo__bindgen_ty_1 {
    pub d0: __BindgenUnionField<[::std::os::raw::c_char; 2usize]>,
    pub d1: __BindgenUnionField<[::std::os::raw::c_char; 1usize]>,
    pub d2: __BindgenUnionField<[::std::os::raw::c_char; 0usize]>,
    pub __bindgen_padding_0: [u8; 18446744073709551615usize],
    pub bindgen_union_field: [u8; 2usize],
}

The __bindgen_padding_0 field is a little bit extreme.

qsr pushed a commit to qsr/rust-bindgen that referenced this issue Mar 20, 2025
qsr pushed a commit to qsr/rust-bindgen that referenced this issue Mar 20, 2025
qsr pushed a commit to qsr/rust-bindgen that referenced this issue Mar 20, 2025
@qsr
Copy link
Author

qsr commented Mar 24, 2025

I proposed a fix for this, but I am not sure how I can have it reviewed. The documentation seems to not be up to date because the review bot is not setup.

@emilio ? @pvdrz ?

bherrera pushed a commit to misttech/fuchsia that referenced this issue Apr 1, 2025
This CL 1) updates the outputs of generate.py so that they match what the script does at ToT (outputs such as arm.rs at ToT haven't been updated/synced), and 2) makes sure fx build works after the update.

Steps:
1. Run `./src/starnix/lib/linux_uapi/generate.py` (no edits)
This results in some changes, notably, io_uring_sqe__bindgen_ty_6 updating to a struct and having 5 params.

2. Run `fx build`. This fails due to:
```
error[E0080]: evaluation of `std::mem::size_of::<io_uring_sqe>` failed
 --> /b/s/w/ir/x/w/fuchsia-third_party-rust/library/core/src/mem/mod.rs:1229:26
  |
  = note: values of the type `[u8; 18446744073709551608]` are too big for the target architecture
```
This is rust-lang/rust-bindgen#3068.

3. Patch in the generate.py edit. Run `./src/starnix/lib/linux_uapi/generate.py` (with edit). Note that generated files now do not have the `pub __bindgen_padding_0` line.

4. `fx build` completes.

Once's qsr's fix at rust-lang/rust-bindgen#3173 is merged and rolled in, we shouldn't need to do the regex replace.

Bug: 398914504
Change-Id: Ic6be5a14f4f00477795588a5ed52e5770c64955e
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1235157
Reviewed-by: Benjamin Lerman <[email protected]>
Commit-Queue: Mary Xia <[email protected]>
bherrera pushed a commit to misttech/integration that referenced this issue Apr 3, 2025
…_padding_0

This CL 1) updates the outputs of generate.py so that they match what the script does at ToT (outputs such as arm.rs at ToT haven't been updated/synced), and 2) makes sure fx build works after the update.

Steps:
1. Run `./src/starnix/lib/linux_uapi/generate.py` (no edits)
This results in some changes, notably, io_uring_sqe__bindgen_ty_6 updating to a struct and having 5 params.

2. Run `fx build`. This fails due to:
```
error[E0080]: evaluation of `std::mem::size_of::<io_uring_sqe>` failed
 --> /b/s/w/ir/x/w/fuchsia-third_party-rust/library/core/src/mem/mod.rs:1229:26
  |
  = note: values of the type `[u8; 18446744073709551608]` are too big for the target architecture
```
This is rust-lang/rust-bindgen#3068.

3. Patch in the generate.py edit. Run `./src/starnix/lib/linux_uapi/generate.py` (with edit). Note that generated files now do not have the `pub __bindgen_padding_0` line.

4. `fx build` completes.

Once's qsr's fix at rust-lang/rust-bindgen#3173 is merged and rolled in, we shouldn't need to do the regex replace.

Original-Bug: 398914504
Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1235157
Original-Revision: 3b130710ba6aac0d9130bc718184bfaf34abbfa8
GitOrigin-RevId: c1e0371e35ebae79d27ecaaac3fc16ae30461a38
Change-Id: I4169f94aa0c01a8be2ddcddb6b094e46b6c7108d
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

Successfully merging a pull request may close this issue.

1 participant