Skip to content

Support defining C variadic functions #1677

Open

Description

@bjorn3

Will be stabilized by rust-lang/rust#155697. Requires Cranelift support first.

Activity

  1. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    S-blockedStatus: marked as blocked ❌ on something else such as an RFC or other implementation work.
    A-abiArea: ABI handling
    on Jul 22, 2026
  2. 0xmuon commented on Aug 11, 2026

    @0xmuon
    Contributor

    Hi @bjorn3 , now that c_variadic is stable in rustc,I am looking at unblocking this in cg_clif and wanted to check the approach before a big diff. The plan is to stop fatal ing on variadic function definitions and wire the ... parameter in the function prelude the same way LLVM does by allocating a VaList and running va_start, implement va_arg by porting the arch specific logic from rustc_codegen_llvm/src/va_arg.rs, and implement va_start ourselves since we can't use llvm.va_start while va_end and va_copy can keep using the existing Rust fallback bodies. The hard part is the variadic callee prologue because Cranelift doesnot save incoming argument registers into a reg save area the way LLVM does, so on targets like x86_64 Linux we probably need to spill GP and SSE arg regs at function entry likely via the same inline asm path cg_clif already uses before va_arg can read register passed variadic args. I would start with x86_64 unknown-linux-gnu then expand to ptr fallback targets and AArch64. Does that match what you had in mind or is there a preferred order or something you would rather see done differently like waiting on 'Cranelift variadic' support?

  3. bjorn3 commented on Aug 11, 2026

    @bjorn3
    MemberAuthor

    I would strongly prefer proper Cranelift side support. The inline asm call path doesn't handle many important parts of the C ABI like struct arguments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-abiArea: ABI handlingC-enhancementCategory: An issue proposing an enhancement or a PR with one.S-blockedStatus: marked as blocked ❌ on something else such as an RFC or other implementation work.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions