rust-lang / rust-lang/rust-bindgen
Extra padding added in Windows to packed struct with bitfields
Open
Nobody has claimed this yet.
bug
help wanted
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
Input C/C++ Header
#ifndef _PACKED_H_
#define _PACKED_H_
#include <stdint.h>
struct mystruct {
unsigned a : 2;
unsigned b : 4;
unsigned c : 3;
unsigned d : 5;
unsigned e : 2;
uint16_t f;
uint32_t g;
} __attribute__((packed));
#endif
Bindgen Invocation
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
Actual Results
In Windows:
#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct mystruct {
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>,
pub f: u16,
pub g: u32,
pub __bindgen_padding_0: [u8; 2usize],
}
Expected Results
In Linux:
#[repr(C, packed)]
#[derive(Debug, Copy, Clone)]
pub struct mystruct {
pub _bitfield_1: __BindgenBitfieldUnit<[u8; 2usize], u8>,
pub f: u16,
pub g: u32,
}
Link to repo
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the shown wrapper.h input and bindgen::Builder invocation on Windows and Linux. Compare the generated #[repr(C, packed)] mystruct definitions and trace why Windows emits __bindgen_padding_0; done means the unnecessary padding is absent while the bindings remain correct on both platforms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100