llvm / llvm/llvm-project

[Clang] CPU-related intrinsics don't work on Darwin 24.6.0 MACH-O arm64

Open
#213,863 1 comment 0 reactions 0 assignees View on GitHub
clang:codegen compiler-rt:builtins platform:macos
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Host environment: Darwin 24.6.0, latest Xcode tools installed, tried latest homebrew clang as well.
Built target is default Darwin MACH-O arm64.

First, using `__builtin_cpu_supports("aes")` returns `0` on this system, whereas is should return `1`.
Second, `__builtin_cpu_init()` cause a compilation error `"builtin is not supported on this target"`.

Looking at the generated binary, there was code present for "`__init_cpu_features_resolver()`", which indeed would initialize the `cpu_supports` to the proper values. However, that routine does not appear to be invoked.

Manually calling `__init_cpu_features_resolver()` causes subsequent `__builtin_cpu_supports()` calls to provide the correct values.

Simple test program below.

```c
// clang test.c -o test
#include

void __init_cpu_features_resolver(); // possibly wrong prototype

int main(void)
{
// __builtin_cpu_init(); // error: builtin is not supported on this target : __builtin_cpu_init();
printf("aes=%u\n", __builtin_cpu_supports("aes")); // 0 -- should be 1

__init_cpu_features_resolver();

printf("aes=%u\n", __builtin_cpu_supports("aes")); // now 1

return 0;
// tried with both:
// Homebrew clang version 21.1.0 Target: arm64-apple-darwin24.6.0
// Apple clang version 17.0.0 (clang-1700.0.13.5) Target: arm64-apple-darwin24.6.0
}
```

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided test.c on Darwin 24.6.0 arm64 with the listed Apple and Homebrew Clang versions, then inspect the generated binary and the behavior of __init_cpu_features_resolver(). Compare the results of __builtin_cpu_supports("aes") with and without the manual resolver call, and determine why __builtin_cpu_init() is rejected. Done means the built-in initialization works for this target and the test reports the expected AES support without a manual call.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.