Skip to content

ABI: callable-type descriptors for va_list indirect calls and audits #1106

Closed

Description

@ehartford

Indirect calls do not consume a function-type ABI descriptor. This blocks non-scalar C c_va_list callbacks and SysV With function values while completing #1104.

pub unsafe fn indirect(cb: extern "C" fn(c_va_list) -> i32, args: c_va_list) -> i32: cb(args)

Before the missing MIR type mapping is repaired, ir ... --target=linux_aarch64 --no-prelude fails with wrong argument type actual=struct{i64,i64,i64,i64} expected=i32 fn=indirect; Darwin reports actual=ptr expected=i32.

LLDB observed Codegen.mir_sema_type_to_llvm(20) return zero to Codegen.mir_build_raw_fn_type+692 (PC 0x10097d750 in the current va-list stage2), which branches to type_fallback() and inserts i32. /tmp/with-va-indirect-type-lldb.txt records the call and branch. The snapshot type converter lacks TY_VA_LIST.

Adding that one mapping alone would make Linux calls silently use the wrong ABI. The remaining foundation is concrete:

  • src/CodegenDispatch.w, mir_build_raw_fn_type (~469–513), handles TY_FN and TY_EXTERN_FN identically and consults only the internal aggregate classifier. It does not encode SysV va_list array decay or the AAPCS64 foreign aggregate-copy convention.
  • mir_emit_call_term (~15180–15212) obtains ABI transform metadata only by a named callee symbol. A function-pointer operand has no such symbol, so its argument marshaller has no recorded source pass modes, byval/direct packing, or return transform to read.
  • The Sema/MIR function-type route also needs the same parameter-place verdict as named signatures for SysV array decay. A codegen-only type-name special case would violate FnAbi's single-source rule.

Required fix: compute/cache a complete ABI descriptor for a callable type and have both raw function-type construction and indirect-call marshalling consume it, sharing the same C classification as named extern declarations. Cover named/indirect calls, C-compatible returns, explicit pointers, all five targets, and caller-copy versus caller-place semantics. Do not merely replace i32 with an LLVM aggregate.

The #1104 branch will repair the MIR storage mapping and retain a loud diagnostic for the Linux va_list function-pointer path until that foundation exists; pointer-sized Darwin/Windows calls can use the existing direct pointer ABI. This limitation must remain visible in the ABI handoff and tests.

The same foundation is required for ordinary With function values on SysV:

pub fn probe(args: c_va_list) -> i32: 7
pub unsafe fn indirect(cb: fn(c_va_list) -> i32, args: c_va_list) -> i32: cb(args)
pub unsafe fn caller(args: c_va_list) -> i32: indirect(probe, args)

ir --target=linux_x86_64 --no-prelude succeeds but emits an indirect call
%2(ptr %env, { i64, i64, i64 } %args) to a thunk declared
__fn_thunk_0(ptr %env, ptr %args). LLDB observed
internal_abi_needs_indirect_param return w0=0 to
mir_build_closure_fn_type+556 (PC 0x10043077c), taking the aggregate-value
branch at +580. The builder independently re-derives a physical ABI and
misses the named signature's caller-place mode.

The audit also stays silent: 124 facts, zero violations, exit zero on this
incorrect IR (/tmp/with-va-with-callback-audit.txt). Callable-type ABI
verification must cover closure calls and named-function thunks as well as
C pointers. The #1104 branch adds an explicit diagnostic for this SysV
function-value parameter case and requires the audit to fail on the repro.
The other targets' ordinary With function values retain their existing
value convention. Debugger proof: /tmp/with-va-with-callback-branch-lldb.txt.

Activity

  1. changed the title [-]Function-pointer ABI needs a callable-type descriptor for non-scalar C va_list[/-] [+]ABI: callable-type descriptors for va_list indirect calls and audits[/+] on Sep 9, 2026
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions