Skip to content

libmimalloc-sys2 0.1.55 fails to build on aarch64-pc-windows-msvc with clang: undeclared __ldar64 / __stlr64 #64

@shulaoda

Description

@shulaoda

Summary

Building libmimalloc-sys2 0.1.55 for the aarch64-pc-windows-msvc target with clang as the C compiler fails because the bundled mimalloc/include/mimalloc/atomic.h calls the MSVC ARM64 intrinsics __ldar64 and __stlr64 without a declaration that clang can see. The same setup worked on 0.1.54, so this is a regression introduced in 0.1.55.

The downstream mimalloc-safe crate, when resolved to a version whose libmimalloc-sys2 constraint admits 0.1.55, breaks the aarch64-pc-windows-msvc release build for any project using TARGET_CC=clang.

Environment

  • Crate: libmimalloc-sys2 = 0.1.55
  • Parent crate: mimalloc-safe (latest at the time of the failure; the failing project pinned mimalloc-safe = "=0.1.58" and still hit this because its libmimalloc-sys2 requirement allowed 0.1.55)
  • Target triple: aarch64-pc-windows-msvc
  • Host: GitHub Actions windows-2025 runner (Windows Server 2025 Datacenter, 10.0.26100)
  • TARGET_CC=clang
  • Rust: stable (release build via napi build --target aarch64-pc-windows-msvc --release)

Reproduction

In a workspace whose Cargo.toml depends on mimalloc-safe (any version that resolves libmimalloc-sys2 = 0.1.55):

# On a Windows runner with clang available
set TARGET_CC=clang
cargo build --release --target aarch64-pc-windows-msvc

Minimal reproduction is available in the rolldown CI failure log:

Error output

   Compiling libmimalloc-sys2 v0.1.55
warning: libmimalloc-sys2@0.1.55: In file included from ./c_src/mimalloc/src/static.c:17:
warning: libmimalloc-sys2@0.1.55: In file included from ./c_src/mimalloc/include\mimalloc/internal.h:16:
warning: libmimalloc-sys2@0.1.55: In file included from ./c_src/mimalloc/include\mimalloc\types.h:29:
warning: libmimalloc-sys2@0.1.55: ./c_src/mimalloc/include\mimalloc\atomic.h:230:14: error: call to undeclared function '__ldar64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
warning: libmimalloc-sys2@0.1.55:   230 |       return MI_MSC_XX(__ldar)((volatile const uintptr_t*)p);
warning: libmimalloc-sys2@0.1.55:       |              ^
warning: libmimalloc-sys2@0.1.55: ./c_src/mimalloc/include\mimalloc\atomic.h:164:23: note: expanded from macro 'MI_MSC_XX'
warning: libmimalloc-sys2@0.1.55:   164 | #define MI_MSC_XX(f)  f##64
warning: libmimalloc-sys2@0.1.55:       |                       ^
warning: libmimalloc-sys2@0.1.55: <scratch space>:9:1: note: expanded from here
warning: libmimalloc-sys2@0.1.55:     9 | __ldar64
warning: libmimalloc-sys2@0.1.55:       | ^
warning: libmimalloc-sys2@0.1.55: ./c_src/mimalloc/include\mimalloc\atomic.h:252:7: error: call to undeclared function '__stlr64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
warning: libmimalloc-sys2@0.1.55:   252 |       MI_MSC_XX(__stlr)((volatile uintptr_t*)p,x);
warning: libmimalloc-sys2@0.1.55:       |       ^
warning: libmimalloc-sys2@0.1.55: ./c_src/mimalloc/include\mimalloc\atomic.h:273:14: error: call to undeclared function '__ldar64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
warning: libmimalloc-sys2@0.1.55:   273 |       return __ldar64((volatile const uintptr_t*)p);
warning: libmimalloc-sys2@0.1.55:       |              ^
warning: libmimalloc-sys2@0.1.55: ./c_src/mimalloc/include\mimalloc\atomic.h:298:7: error: call to undeclared function '__stlr64'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
warning: libmimalloc-sys2@0.1.55:   298 |       __stlr64((volatile uint64_t*)p, (uint64_t)x);
warning: libmimalloc-sys2@0.1.55:       |       ^
warning: libmimalloc-sys2@0.1.55: 4 errors generated.
error: failed to run custom build command for `libmimalloc-sys2 v0.1.55`

Analysis

atomic.h in the bundled mimalloc sources uses __ldar64 / __stlr64 through the MI_MSC_XX macro. These are MSVC-specific ARM64 load-acquire / store-release intrinsics (declared in MSVC's <intrin.h> / <arm64intr.h>). When the file is compiled by clang targeting aarch64-pc-windows-msvc, these intrinsics are not visible, so clang reports call to undeclared function. Under newer clang defaults this is an error rather than a warning, which fails the build.

0.1.54 did not exhibit this, so the regression is in whatever change 0.1.55 made (likely a bump of the bundled mimalloc C source, or a change to the include/guard layout).

Possible fixes (one of):

  1. Guard the affected branches so they are only compiled under MSVC (#if defined(_MSC_VER) && !defined(__clang__)), and fall back to the __atomic_* / inline-asm path under clang on Windows-ARM64.
  2. Forward-declare or include the MSVC intrinsic headers (<intrin.h>) when targeting Windows-ARM64, including under clang-cl / clang.
  3. Yank 0.1.55 and re-release a fixed 0.1.56 so consumers that don't carry an explicit pin recover automatically.

Workaround for downstream users

Pin libmimalloc-sys2 to =0.1.54 in Cargo.lock:

cargo update -p libmimalloc-sys2 --precise 0.1.54

(Pinning mimalloc-safe alone is not sufficient — its version requirement still allows libmimalloc-sys2 0.1.55 to be resolved.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions