rust-lang / rust-lang/rust-bindgen

Layout error with struct that includes __attribute__((aligned(8)))

Open
#2,101 0 comments 0 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

I encountered this error when trying to generate bindings for Fio.

Input C/C++ Header
typedef long a;
typedef b;
typedef a c;
typedef struct {
  union {
    c d
  };
} e;
struct thread_stat {
  b f;
  e g;
  c h __attribute__((aligned(8)))
} __attribute__((packed));
Bindgen Invocation
bindgen --whitelist-type=thread_stat isolated-test-case.h
Actual Results
---- ffi::bindgen_test_layout_thread_stat stdout ----
thread 'ffi::bindgen_test_layout_thread_stat' panicked at 'assertion failed: `(left == right)`
  left: `8`,
 right: `4`: Offset of field: thread_stat::g', src/ffi.rs:81:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    ffi::bindgen_test_layout_thread_stat

and/or

Expected Results

No errors from the layout tests

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 issue with the header in isolated-test-case.h and the shown bindgen invocation, then inspect the generated layout test and the assertion in src/ffi.rs. The work is done when the thread_stat layout test passes without offset errors for the aligned field.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, cpp, rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.