From: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
To: Thomas Bertschinger <tahbertschinger@gmail.com>,
Kent Overstreet <kent.overstreet@linux.dev>,
linux-bcachefs@vger.kernel.org, Brian Foster <bfoster@redhat.com>,
rust-for-linux@vger.kernel.org
Subject: Re: [PATCH BCACHEFS-TOOLS] use upstream bindgen; fix packed and aligned types
Date: Mon, 22 Jan 2024 11:52:19 -0300 [thread overview]
Message-ID: <39e77d5d-d29e-4f4c-a678-78b6e562eaae@gmail.com> (raw)
In-Reply-To: <20240122143643.201936-1-tahbertschinger@gmail.com>
On 1/22/24 11:36, Thomas Bertschinger wrote:
> bcachefs-tools has been using a patched bindgen to work around a
> limitation of rustc that prevents compiling structs with
> both #[repr(packed(N)] and #[repr(align(N)] attributes. The patch:
> e8168ceda507 "codegen: Don't generate conflicting packed() and align()
> representation hints." discards the "align" attribute in cases where
> bindgen produces a type with both.
>
> This may be correct for some types, but it turns out that for each
> bcachefs type with this problem, keeping the "align" attribute and
> discarding the "packed" attribute generates a type with the same ABI as
> the original C type.
>
> This can be tested automatically by running:
> $ cargo test --manifest-path bch_bindgen/Cargo.toml
> in the bcachefs-tools tree.
>
> There has been pressure recently to start using upstream bindgen; both
> externally, from distribution maintainers who want to build
> bcachefs-tools with standard dependencies, and internally, in order to
> enable using Rust for bcachefs in-kernel.
>
> This patch updates bcachefs-tools to use upstream bindgen. It works
> around the rustc limitation with a post-processing step in the bindgen
> build that adjusts the attributes to include "#[repr(C, align(N))]" and
> exclude #[repr(packed(N)] only for the 4 types that need it.
>
> Some types that had been manually implemented in
> bch_bindgen/src/bcachefs.rs are now automatically generated by bindgen,
> so that they will be covered by the ABI compatibility testing mentioned
> above.
>
> I intentionally targeted the post-processing to the exact 4 types with
> the issue currently, so that any changes to bcachefs that result in this
> issue appearing for a new type will require manual intervention. I
> figured any such changes should require careful consideration.
>
> Ideally, bindgen can be updated to handle situations where "align(N)"
> is needed and "packed(N)" can be safely discarded. If a patch for this
> is accepted into bindgen, the post-processing hack can be removed.
>
> Signed-off-by: Thomas Bertschinger <tahbertschinger@gmail.com>
> ---
> [...]
You really got lucky that those types didn't require packing in
Rust. LGTM.
Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
next prev parent reply other threads:[~2024-01-22 14:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-22 14:36 [PATCH BCACHEFS-TOOLS] use upstream bindgen; fix packed and aligned types Thomas Bertschinger
2024-01-22 14:52 ` Martin Rodriguez Reboredo [this message]
2024-01-22 19:22 ` Kent Overstreet
2024-01-22 20:19 ` Thomas Bertschinger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=39e77d5d-d29e-4f4c-a678-78b6e562eaae@gmail.com \
--to=yakoyoku@gmail.com \
--cc=bfoster@redhat.com \
--cc=kent.overstreet@linux.dev \
--cc=linux-bcachefs@vger.kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=tahbertschinger@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox