Skip to content

[Bug]: sp_int.c MIPS assembly fails to build on MIPS Release 6 ('$hi' cannot be clobbered) #11953

Closed

Description

@yegorich

Version

5.9.4 (also current master, b1038ee)

Description

The SP math MIPS assembly in wolfcrypt/src/sp_int.c (the WOLFSSL_SP_MIPS64 and WOLFSSL_SP_MIPS blocks) multiplies with multu/dmultu, reads the result with mflo/mfhi, and lists $hi/$lo as clobbers. MIPS Release 6 removed these instructions and the hi/lo registers, so the build fails for any r6 CPU (mips32r6, mips64r6, I6400, P6600, ...).

configure selects WOLFSSL_SP_MIPS64/WOLFSSL_SP_MIPS from the host triplet alone (*mips64* / *mips*), so this happens with the default options; the only workaround is --disable-asm.

Target and build environment: cross builds on x86_64 Linux with GCC 15 and glibc (Bootlin toolchains, as used by Buildroot), both MIPS64 r6 (n32 and n64) and MIPS32 r6. Found by the Buildroot autobuilders: https://autobuild.buildroot.org/results/10c901b8c57f6322b127f1b14c78f73dbb7f28b2

Suggested fix: only build the MIPS/MIPS64 assembly when the compiler's __mips_isa_rev is undefined or less than 6, and use the existing generic C code otherwise. I tested this locally on master with --enable-all. The r6 builds then succeed, with GCC emitting the r6 multiply instructions (mulu/muhu, dmulu/dmuhu). wolfcrypt/test/testwolfcrypt passes under qemu-user on mips64r6el n32 (-cpu I6400) and mips32r6el (-cpu mips32r6-generic). A pre-r6 mips64el build still uses the assembly and also passes. I'm not able to sign the contributor agreement, so I'm reporting this as an issue as described in CONTRIBUTING.md rather than opening a PR.

This report was prepared with the help of an AI assistant (Claude); I reviewed and tested it.

Reproduction steps

  1. Get a MIPS r6 cross toolchain, e.g. Bootlin's mips64r6el-n32 glibc or mips32r6el glibc toolchain.
  2. ./configure --host=mips64el-linux-gnu CC=<r6 toolchain gcc> (or --host=mipsel-linux-gnu for MIPS32 r6); --enable-all also fails.
  3. make

Relevant log output

wolfcrypt/src/sp_int.c:4217:5: error: the register '$hi' cannot be clobbered in 'asm' for the current target
 4217 |     __asm__ __volatile__ (                               \
      |     ^~~~~~~
wolfcrypt/src/sp_int.c:18081:13: note: in expansion of macro 'SP_ASM_MUL_ADD'

MIPS32 r6:
wolfcrypt/src/sp_int.c:4418:5: error: the register '%hi' cannot be clobbered in 'asm' for the current target

Activity

  1. SparkiDev commented on Nov 3, 2026

    @SparkiDev
    Contributor

    Hi @yegorich

    I've update sp_int.c in PR: #11966
    Let me know if this works for you.

    Thanks,
    Sean

  2. yegorich commented on Nov 3, 2026

    @yegorich
    Author

    Thanks Sean! I tested PR #11966 (83f0f88) with GCC (Bootlin toolchains, as used by Buildroot), --enable-all --disable-shared, running wolfcrypt/test/testwolfcrypt under qemu-user:

    • mips64r6el, n32 ABI (WOLFSSL_SP_MIPS64, qemu -cpu I6400): builds; sp_int.o uses dmulu/dmuhu, no dmultu/mflo/mfhi; all tests pass.
    • mips32r6el (WOLFSSL_SP_MIPS, qemu -cpu mips32r6-generic): builds; uses mulu/muhu; all tests pass.
    • mips64r2el, n32 ABI (qemu -cpu 5KEf, regression check): code unchanged (dmultu/mflo/mfhi); all tests pass.

    So it works for me. Once it's in a release, Buildroot can enable the assembly on R6 again.

  3. SparkiDev commented on Nov 4, 2026

    @SparkiDev
    Contributor

    Thanks @yegorich,

    I'll try to get the PR merged as quickly as possible!

    Sean

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

Metadata

Metadata

Assignees

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