When bindgen infers the target triple from the Rust target (no explicit --target in clang args), it inserts --target= into clang_args in Bindings::generate() (lib.rs ~line 789). However, fallback_clang_args is populated from clang_args earlier in Builder::generate() (lib.rs ~line 345), before this insertion. The fallback translation unit therefore uses the host architecture instead of the target architecture.
Impact: For cross-compilation, sizeof-dependent macros evaluate with the host's struct layouts instead of the target's, producing silently wrong values. This affects any project that cross-compiles bindings and relies on clang_macro_fallback — for example, linux-raw-sys generates bindings for 22 architectures, and ioctl constants defined via _IOR/_IOW/_IOWR (which embed sizeof(struct)) would get wrong values for any arch where struct sizes differ from the host.
Note: this only affects the implicit target case. If the user explicitly passes --target= via .clang_arg(), it's already present in clang_args when fallback_clang_args is populated, so the bug doesn't manifest.
When bindgen infers the target triple from the Rust target (no explicit
--targetin clang args), it inserts--target=intoclang_argsinBindings::generate()(lib.rs ~line 789). However,fallback_clang_argsis populated fromclang_argsearlier inBuilder::generate()(lib.rs ~line 345), before this insertion. The fallback translation unit therefore uses the host architecture instead of the target architecture.Impact: For cross-compilation,
sizeof-dependent macros evaluate with the host's struct layouts instead of the target's, producing silently wrong values. This affects any project that cross-compiles bindings and relies onclang_macro_fallback— for example,linux-raw-sysgenerates bindings for 22 architectures, and ioctl constants defined via_IOR/_IOW/_IOWR(which embedsizeof(struct)) would get wrong values for any arch where struct sizes differ from the host.Note: this only affects the implicit target case. If the user explicitly passes
--target=via.clang_arg(), it's already present inclang_argswhenfallback_clang_argsis populated, so the bug doesn't manifest.