Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
olivier-fs opened this issue Oct 9, 2022 · 1 comment

Comments

@olivier-fs
Copy link

olivier-fs commented Oct 9, 2022

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.

@pvdrz
Copy link
Contributor

pvdrz commented Oct 11, 2022

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

@pvdrz pvdrz closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants