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

AArch64 Linux va_list not FFI-safe #2845

Closed
stevecapperarm opened this issue Jun 6, 2024 · 1 comment · Fixed by #2880
Closed

AArch64 Linux va_list not FFI-safe #2845

stevecapperarm opened this issue Jun 6, 2024 · 1 comment · Fixed by #2880

Comments

@stevecapperarm
Copy link

Hello folks,
We noticed that for AArch64 Linux, va_list was being translated to a type that was not FFI-safe.
Whilst we aren't aware of any cases where va_list would be used by Rust, this does result in warnings appearing for some projects when built for Arm and not other architectures. Rather than try to block these functions from being translated in various crates, I thought it best to raise something here as a general solution may be better.

I suspect there is some subtle interaction with clang and the builtin va_list type for AArch64 Linux.

Input C/C++ Header

// typedefs below come from <stdarg.h>
typedef __builtin_va_list __gnuc_va_list;
typedef __builtin_va_list va_list;

int my_func(char *format, va_list args);

Bindgen Invocation

$ bindgen input.h

Actual Results

/* automatically generated by rust-bindgen 0.69.4 */

pub type __gnuc_va_list = [u64; 4usize];
pub type va_list = [u64; 4usize];
extern "C" {
    pub fn my_func(
        format: *mut ::std::os::raw::c_char,
        args: va_list,
    ) -> ::std::os::raw::c_int;
}

and/or

warning: `extern` block uses type `[u64; 4]`, which is not FFI-safe
 --> test.rs:8:15
  |
8 |         args: va_list,
  |               ^^^^^^^ not FFI-safe
  |
  = help: consider passing a pointer to the array
  = note: passing raw arrays by value is not FFI-safe
  = note: `#[warn(improper_ctypes)]` on by default

Expected Results

We don't expect the warning to appear. Maybe something like this would be better?

#[repr(C)]
#[repr(align(8))]
#[derive(Debug, Copy, Clone)]
pub struct va_list {
    pub _bindgen_opaque_blob: [u64; 4usize],
}
mulkieran added a commit to mulkieran/stratisd that referenced this issue Oct 17, 2024
rust-lang/rust-bindgen#2845

Signed-off-by: mulhern <amulhern@redhat.com>
mulkieran added a commit to mulkieran/stratisd that referenced this issue Oct 17, 2024
mulkieran added a commit to mulkieran/stratisd that referenced this issue Oct 17, 2024
mulkieran added a commit to mulkieran/stratisd that referenced this issue Oct 17, 2024
mulkieran added a commit to mulkieran/stratisd that referenced this issue Oct 17, 2024
mulkieran added a commit to mulkieran/stratisd that referenced this issue Oct 17, 2024
mulkieran added a commit to mulkieran/stratisd that referenced this issue Oct 18, 2024
rust-lang/rust-bindgen#2845

Signed-off-by: mulhern <amulhern@redhat.com>
(cherry picked from commit fb78ef7)
@stevecapperarm
Copy link
Author

Apologies for my late reply, and thank you! This does appear to fix the FFI-safe warnings for AArch64 Linux for me.

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

Successfully merging a pull request may close this issue.

1 participant