rust-lang / rust-lang/rust-bindgen

error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type

Open
#2,569 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
typedef struct _IMAGE_TLS_DIRECTORY64 {
    ULONGLONG StartAddressOfRawData;
    ULONGLONG EndAddressOfRawData;
    ULONGLONG AddressOfIndex;         // PDWORD
    ULONGLONG AddressOfCallBacks;     // PIMAGE_TLS_CALLBACK *;
    DWORD SizeOfZeroFill;
    union {
        DWORD Characteristics;
        struct {
            DWORD Reserved0 : 20;
            DWORD Alignment : 4;
            DWORD Reserved1 : 8;
        } DUMMYSTRUCTNAME;
    } DUMMYUNIONNAME;

} IMAGE_TLS_DIRECTORY64;

typedef IMAGE_TLS_DIRECTORY64 * PIMAGE_TLS_DIRECTORY64;cases
Bindgen Invocation
    // Configure and generate bindings.
    let bindings = bindgen::builder()
        .header("../inc/libnet.h")
        //.clang_arg("-x").clang_arg("c++")
        .generate()
        .expect("Couldn't write bindings!");

    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());

    // Write the generated bindings to an output file.
    bindings
        .write_to_file(out_path.join("bindings.rs"))
        .expect("Couldn't write bindings!");

or

$ bindgen input.h --whatever --flags
Actual Results
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type

#[repr(C, packed(4))]
#[derive(Copy, Clone)]
pub struct _IMAGE_TLS_DIRECTORY64 {
    pub StartAddressOfRawData: ULONGLONG,
    pub EndAddressOfRawData: ULONGLONG,
    pub AddressOfIndex: ULONGLONG,
    pub AddressOfCallBacks: ULONGLONG,
    pub SizeOfZeroFill: DWORD,
    pub __bindgen_anon_1: _IMAGE_TLS_DIRECTORY64__bindgen_ty_1,
}

and/or

// Insert the (incorrect/buggy) generated bindings here

and/or

Insert compilation errors generated when compiling the bindings with rustc here
Expected Results

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report using the shown bindgen invocation and the IMAGE_TLS_DIRECTORY64 definition, then inspect the generated bindings.rs output. Confirm that the generated packed struct triggers E0588 and that the completed fix produces bindings that compile while preserving the reported C/C++ layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.