-
Notifications
You must be signed in to change notification settings - Fork 794
Description
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.