Skip to content

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

Not planned
@olivier-fs

Description

@olivier-fs

Hi!

I'm trying to build the bindgen tutorial example from :
https://rust-lang.github.io/rust-bindgen/tutorial-0.html
=> https://github.com/fitzgen/bindgen-tutorial-bzip2-sys
=> https://fitzgeraldnick.com/2016/12/14/using-libbindgen-in-build-rs.html

It's an exemple binding to bzip2 (just as an exemple ; the author knows about bzip2 and bzip2-sys crates).

I'm using :

  • rustc 1.64.0 (a55dd71d5 2022-09-19)
  • bindgen-0.60.1
  • Windows 10
  • MSYS2/Mingw64 : clang64/mingw-w64-clang-x86_64-bzip2 1.0.8-2 as the provider of C package bzip2

After adding some bindgen::Builder config in build.rs to set path to included <bzlib.h> :

.clang_arg("-IC:/dev/msys64/clang64/include")

I'm getting this error :

$ cargo build
   Compiling bindgen-tutorial-bzip2-sys v0.1.0 (C:\Users\olivier\dev\rust\www-sample\interop\c\bindgen-tutorial-bzip2-sys)
error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type
     --> C:\Users\olivier\dev\rust\www-sample\interop\c\bindgen-tutorial-bzip2-sys\target\debug\build\bindgen-tutorial-bzip2-sys-03a76bb986e88418\out/bind

ings.rs:64916:1
      |
64916 | pub struct _IMAGE_TLS_DIRECTORY64 {
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      |
note: `_IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1` has a `#[repr(align)]` attribute
     --> C:\Users\olivier\dev\rust\www-sample\interop\c\bindgen-tutorial-bzip2-sys\target\debug\build\bindgen-tutorial-bzip2-sys-03a76bb986e88418\out/bind

ings.rs:64933:1
      |
64933 | pub struct _IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1 {
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: `_IMAGE_TLS_DIRECTORY64` contains a field of type `_IMAGE_TLS_DIRECTORY64__bindgen_ty_1`
     --> C:\Users\olivier\dev\rust\www-sample\interop\c\bindgen-tutorial-bzip2-sys\target\debug\build\bindgen-tutorial-bzip2-sys-03a76bb986e88418\out/bind

ings.rs:64922:9
      |
64922 |     pub __bindgen_anon_1: _IMAGE_TLS_DIRECTORY64__bindgen_ty_1,
      |         ^^^^^^^^^^^^^^^^
note: ...which contains a field of type `_IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1`
     --> C:\Users\olivier\dev\rust\www-sample\interop\c\bindgen-tutorial-bzip2-sys\target\debug\build\bindgen-tutorial-bzip2-sys-03a76bb986e88418\out/bind

ings.rs:64928:9
      |
64928 |     pub __bindgen_anon_1: _IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1,
      |         ^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0588`.
error: could not compile `bindgen-tutorial-bzip2-sys` due to previous error

I tried with nightly toolchain (currently 1.66.0)

  • with cargo +nightly build
  • by adding some bindgen::Builder config in build.rs : .rust_target(bindgen::RustTarget::Nightly)
    but I get the same error.

I first submitted an issue to the rust-lang repo (rust-lang/rust#102733) where it was answered that rustc is correct in rejecting the bindgen generated code with error :

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

cf. https://doc.rust-lang.org/reference/type-layout.html#the-alignment-modifiers

Excerpt from bindgen generated bindings.rs :

#[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,
}
#[repr(C)]
#[derive(Copy, Clone)]
pub union _IMAGE_TLS_DIRECTORY64__bindgen_ty_1 {
    pub Characteristics: DWORD,
    pub __bindgen_anon_1: _IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1,
}
#[repr(C)]
#[repr(align(4))]   /* <============== THIS LINE */
#[derive(Debug, Copy, Clone)]
pub struct _IMAGE_TLS_DIRECTORY64__bindgen_ty_1__bindgen_ty_1 {
    pub _bitfield_align_1: [u32; 0],
    pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4usize]>,
}

Another issue rust-lang/rust#67383 with the same problem had been closed for the same kind of error, so maybe the error I'm getting comes from a different bindgen code path than the one fixed in the other issue.

If I manually remove the #[repr(align)] the build is OK.

Not sure if it is the right way to fix it, but 'cargo test' seems OK, so it may be sufficient.

Activity

pvdrz

pvdrz commented on Oct 11, 2022

@pvdrz
Contributor

Hi @olivier-fs thanks for your report. I'm closing this issue as this is a duplicate of #2179 and it would be better to keep this discussion in a single place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @pvdrz@olivier-fs

        Issue actions

          error[E0588]: packed type cannot transitively contain a #[repr(align)] type · Issue #2303 · rust-lang/rust-bindgen