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

bindgen produces an E0588 error when dealing with a packed struct with union. #1498

Closed
apanda opened this issue Jan 21, 2019 · 5 comments
Closed
Assignees
Labels

Comments

@apanda
Copy link

apanda commented Jan 21, 2019

Input C/C++ Header

struct rte_memseg {
    uint64_t phys_addr;      /**< Start physical address. */
    RTE_STD_C11
    union {
        void *addr;         /**< Start virtual address. */
        uint64_t addr_64;   /**< Makes sure addr is always 64 bits */
    };
    size_t len;               /**< Length of the segment. */
    uint64_t hugepage_sz;       /**< The pagesize of underlying memory */
    int32_t socket_id;          /**< NUMA socket ID. */
    uint32_t nchannel;          /**< Number of channels. */
    uint32_t nrank;             /**< Number of ranks. */
} __attribute__((__packed__));

Bindgen Invocation

    let bindings = bindgen::Builder::default()
        .header(header_path.to_str().unwrap())
        .rust_target(bindgen::RustTarget::Nightly)
        .generate()
        .expect("Unable to generate DPDK bindings");

Actual Results

// Insert the (incorrect/buggy) generated bindings here
error[E0588]: packed type cannot transitively contain a `[repr(align)]` type
    --> /home/apanda/NetBricks/target/release/build/e2d2-02e086d04d42e68f/out/dpdk_bindings.rs:8890:1
     |
8890 | / pub struct rte_memseg {
8891 | |     #[doc = "< Start physical address."]
8892 | |     pub phys_addr: phys_addr_t,
8893 | |     pub __bindgen_anon_1: rte_memseg__bindgen_ty_1,
...    |
8903 | |     pub nrank: u32,
8904 | | }
     | |_^

Expected Results

No Rust error.

@emilio
Copy link
Contributor

emilio commented Feb 4, 2019

I'm not sure how to really deal with this if rustc doesn't :(

Do you know if the C compiler ignores the aligned attribute or something?

@emilio emilio added the bug label Feb 4, 2019
@emilio
Copy link
Contributor

emilio commented Mar 4, 2019

Ah, this is slightly different, we shouldn't need #[repr(align)] in that case.

emilio added a commit to emilio/rust-bindgen that referenced this issue Mar 4, 2019
This makes us not unnecessarily add repr(align) to unions.

Closes rust-lang#1498.
@emilio emilio self-assigned this Mar 4, 2019
@emilio
Copy link
Contributor

emilio commented Mar 4, 2019

emilio@23d9229 has a fix.

@apanda
Copy link
Author

apanda commented Mar 4, 2019

Ah, excellent. Thank you 👍

@Jashwanth537
Copy link

Jashwanth537 commented Jul 4, 2023

Hey, i run into a similar issue, what is the fix, should i go about replacing .cargo\registry\src\index.crates.io-6f17d22bba15001f\bindgen-0.66.1\codegen\mod.rs ? as given above @emilio

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

No branches or pull requests

3 participants