Re: C aggregate passing (Rust kernel policy)

Ventura Jack
2025-02-25T15:55:36Z

On Mon, Feb 24, 2025 at 9:42 AM Philip Herron
<herron.philip@googlemail.com> wrote:
> My 50 cents here is that gccrs is trying to follow rustc as a guide, and
> there are a lot of assumptions in libcore about the compiler, such as lang
> items, that we need to follow in order to compile Rust code. [Omitted]
>
> Thanks
>
> --Phil

Is this snippet from the Rust standard library an example of one
of the assumptions about the compiler that the Rust standard library
makes? The code explicitly assumes that LLVM is the backend of
the compiler.

https://github.com/rust-lang/rust/blob/master/library/core/src/ffi/va_list.rs#L292-L301

// FIXME: this should call `va_end`, but there's no clean way to
// guarantee that `drop` always gets inlined into its caller,
// so the `va_end` would get directly called from the same function as
// the corresponding `va_copy`. `man va_end` states that C
requires this,
// and LLVM basically follows the C semantics, so we need to make sure
// that `va_end` is always called from the same function as `va_copy`.
// For more details, see https://github.com/rust-lang/rust/pull/59625
// and https://llvm.org/docs/LangRef.html#llvm-va-end-intrinsic.
//
// This works for now, since `va_end` is a no-op on all
current LLVM targets.

How do you approach, or plan to approach, code like the above in gccrs?
Maybe make a fork of the Rust standard library that only replaces the
LLVM-dependent parts of the code? I do not know how widespread
LLVM-dependent code is in the Rust standard library, nor how
well-documented the dependence on LLVM typically is. In the above
case, it is well-documented.

Best, VJ.