Skip to content

AArch64 Linux va_list not FFI-safe #2845

@stevecapperarm

Description

@stevecapperarm

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],
}

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

    Issue actions