Rollup merge of #149967 - folkertdev:va-list-hexagon, r=workingjubilee

custom `VaList` layout for Hexagon

I noticed while browsing LLVM source that we use an incorrect `VaList` definition for the musl hexagon target.

relevant links

- 0cdc1b6dd4/clang/include/clang/Basic/TargetInfo.h (L333)
- 0cdc1b6dd4/clang/lib/CodeGen/Targets/Hexagon.cpp (L407-L417)

cc target maintainer `@androm3da` can you confirm that this looks OK? In particular the `#[rustc_pass_indirectly_in_non_rustic_abis]` attribute is used to simulate pointer decay (like if the struct were wrapped in a 1-element array in C). The clang comment suggests that the Tag is wrapped in such a single-element array, but I haven't actually been able to confirm it.

For stabilizing `c_variadic` (on the hexagon targets) we will also need a custom `va_arg` implementation to mirror the one in `clang` in [va_arg.rs](https://github.com/rust-lang/rust/blob/main/compiler/rustc_codegen_llvm/src/va_arg.rs). Would you be able to contribute one?

r? `@workingjubilee`
This commit is contained in:
Jonathan Brouwer 2025-12-16 20:21:08 +01:00 committed by GitHub
commit ef2c71c3cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -31,6 +31,9 @@ use crate::marker::PhantomCovariantLifetime;
// the pointer decay behavior in Rust, while otherwise matching Rust semantics.
// This attribute ensures that the compiler uses the correct ABI for functions
// like `extern "C" fn takes_va_list(va: VaList<'_>)` by passing `va` indirectly.
//
// The Clang `BuiltinVaListKind` enumerates the `va_list` variations that Clang supports,
// and we mirror these here.
crate::cfg_select! {
all(
target_arch = "aarch64",
@ -124,6 +127,23 @@ crate::cfg_select! {
}
}
all(target_arch = "hexagon", target_env = "musl") => {
/// Hexagon Musl implementation of a `va_list`.
///
/// See the [LLVM source] for more details. On bare metal Hexagon uses an opaque pointer.
///
/// [LLVM source]:
/// https://github.com/llvm/llvm-project/blob/0cdc1b6dd4a870fc41d4b15ad97e0001882aba58/clang/lib/CodeGen/Targets/Hexagon.cpp#L407-L417
#[repr(C)]
#[derive(Debug)]
#[rustc_pass_indirectly_in_non_rustic_abis]
struct VaListInner {
__current_saved_reg_area_pointer: *const c_void,
__saved_reg_area_end_pointer: *const c_void,
__overflow_area_pointer: *const c_void,
}
}
// The fallback implementation, used for:
//
// - apple aarch64 (see https://github.com/rust-lang/rust/pull/56599)