Skip to content

mips64 ABI bug passing 16-byte aligned scalars #161679

Closed

Description

@folkertdev

16-byte aligned scalars (f128, i128, u128, probably also vectors) are passed in a way that is inconsistent with GCC/Clang. Aggregates seem fine.

E.g. C calling rust (but also rust calling C) fails:

// caller.c
#include <inttypes.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdarg.h>

void val_in_0_perturbed_small(uint8_t arg0, __int128_t arg1, __int128_t arg2, float arg3) {
    printf("%d", arg1);
}
// callee.rs

extern "C" {
    fn val_in_0_perturbed_small(arg0: u8, arg1: i128, arg2: i128, arg3: f32);
}

#[no_mangle]
pub extern "C" fn do_test() {
unsafe {
    let arg0 = 192u8;

    let arg1 = -42707334047547540181846984563639529008i128;

    println!("{:?}", {arg1});
    let arg2 = -21356283574076891493948969979685445152i128;

    let arg3 = f32::from_bits(4092785136);

    val_in_0_perturbed_small(arg0, arg1, arg2, arg3);

}
}

When running abi-cafe that prints

    func val_in_0_perturbed_small's values differed
      values (native-endian hex bytes):
        expect: D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
        caller: D0 D1 D2 D3 D4 D5 D6 D7 D8 D9 DA DB DC DD DE DF
        callee: D8 D9 DA DB DC DD DE DF E0 E1 E2 E3 E4 E5 E6 E7
      the value was arg1: i128
      whose arg was arg1: i128

So looks like the callee side is off by 8 bytes.

I used this abi-cafe command (on my fork that cross-compiles https://github.com/folkertdev/abi-cafe):

env RUSTUP_TOOLCHAIN=stage1 QEMU_LD_PREFIX=/usr/mips64el-linux-gnuabi64 ABI_CAFE_RUNNER= ./target/release/abi-cafe --target mips64el-unknown-linux-gnuabi64 --linker mips64el-linux-gnuabi64-gcc --conventions c --reprs c -t i128

Which requires a stage1 toolchain with the right std, e.g. something like this (also building the host is often convenient):

./x build library --target x86_64-unknown-linux-gnu,mips64-unknown-linux-gnuabi64,mips64el-unknown-linux-gnuabi64,mips-unknown-linux-gnu,mipsel-unknown-linux-gnu

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 24, 2026
  2. Gelbpunkt commented on Aug 24, 2026

    @Gelbpunkt
    Contributor

    I'd like to look into this and have fun with MIPS ABI specs again, so:

    @rustbot claim

  3. added
    O-MIPSTarget: MIPS processors
    A-ABIArea: Concerning the application binary interface (ABI)
    I-miscompileIssue: Correct Rust code lowers to incorrect machine code
    on Aug 24, 2026
  4. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 24, 2026
  5. workingjubilee commented on Aug 24, 2026

    @workingjubilee
    Member

    "fun"

  6. chenx97 commented on Sep 1, 2026

    @chenx97
    Contributor

    The bug likely comes from only handling pad_i32 for aggregates instead of all types.

  7. chenx97 commented on Sep 21, 2026

    @chenx97
    Contributor

    "fun"

    It's more fun when I see that Clang 22 makes the same mistake.

  8. added a commit that references this issue on Oct 4, 2026
    768814b
  9. added a commit that references this issue on Oct 4, 2026
    d7d462d
  10. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 4, 2026
  11. added a commit that references this issue on Oct 4, 2026
    7234ef0
  12. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-ABIArea: Concerning the application binary interface (ABI)I-miscompileIssue: Correct Rust code lowers to incorrect machine codeO-MIPSTarget: MIPS processorsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions