Skip to content

Commit 3a31cf8

Browse files
committed
Revert "[builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685)"
And its follow up "fixup! [builtins][arm64] Build __init_cpu_features_resolver on Apple platforms (#73685)". This reverts commit 5b47052 and 212a5e1. Due to build failures on Windows: ``` C:\Users\Tcwg\llvm-worker\clang-arm64-windows-msvc-2stage\llvm\compiler-rt\lib\builtins\cpu_model.c(1571,2): error: No support for checking hwcap on this platform yet. 1571 | #error No support for checking hwcap on this platform yet. | ^ ``` https://lab.llvm.org/buildbot/#/builders/120/builds/5990
1 parent 5879162 commit 3a31cf8

File tree

1 file changed

+6
-88
lines changed

1 file changed

+6
-88
lines changed

compiler-rt/lib/builtins/cpu_model.c

Lines changed: 6 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -948,8 +948,6 @@ _Bool __aarch64_have_lse_atomics
948948
#if defined(__has_include)
949949
#if __has_include(<sys/auxv.h>)
950950
#include <sys/auxv.h>
951-
#define HAVE_SYS_AUXV
952-
#endif
953951

954952
#if __has_include(<sys/ifunc.h>)
955953
#include <sys/ifunc.h>
@@ -963,8 +961,6 @@ typedef struct __ifunc_arg_t {
963961

964962
#if __has_include(<asm/hwcap.h>)
965963
#include <asm/hwcap.h>
966-
#define HAVE_SYS_HWCAP
967-
#endif
968964

969965
#if defined(__ANDROID__)
970966
#include <string.h>
@@ -1001,9 +997,6 @@ typedef struct __ifunc_arg_t {
1001997
#ifndef HWCAP_SHA2
1002998
#define HWCAP_SHA2 (1 << 6)
1003999
#endif
1004-
#ifndef HWCAP_CRC32
1005-
#define HWCAP_CRC32 (1 << 7)
1006-
#endif
10071000
#ifndef HWCAP_ATOMICS
10081001
#define HWCAP_ATOMICS (1 << 8)
10091002
#endif
@@ -1156,7 +1149,6 @@ typedef struct __ifunc_arg_t {
11561149
if (__system_property_get("ro.arch", arch) > 0 && \
11571150
strncmp(arch, "exynos9810", sizeof("exynos9810") - 1) == 0)
11581151

1159-
#if !defined(__APPLE__)
11601152
static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) {
11611153
#if defined(__FreeBSD__)
11621154
unsigned long hwcap;
@@ -1170,7 +1162,7 @@ static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) {
11701162
zx_status_t status = _zx_system_get_features(ZX_FEATURE_KIND_CPU, &features);
11711163
__aarch64_have_lse_atomics =
11721164
status == ZX_OK && (features & ZX_ARM64_FEATURE_ISA_ATOMICS) != 0;
1173-
#elif defined(HAVE_SYS_AUXV)
1165+
#else
11741166
unsigned long hwcap = getauxval(AT_HWCAP);
11751167
_Bool result = (hwcap & HWCAP_ATOMICS) != 0;
11761168
#if defined(__ANDROID__)
@@ -1188,11 +1180,8 @@ static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics(void) {
11881180
}
11891181
#endif // defined(__ANDROID__)
11901182
__aarch64_have_lse_atomics = result;
1191-
#else
1192-
#error No support for checking for lse atomics on this platfrom yet.
11931183
#endif // defined(__FreeBSD__)
11941184
}
1195-
#endif // !defined(__APPLE__)
11961185

11971186
#if !defined(DISABLE_AARCH64_FMV)
11981187
// CPUFeatures must correspond to the same AArch64 features in
@@ -1270,76 +1259,6 @@ struct {
12701259
// As features grows new fields could be added
12711260
} __aarch64_cpu_features __attribute__((visibility("hidden"), nocommon));
12721261

1273-
#if defined(__APPLE__)
1274-
#include <TargetConditionals.h>
1275-
#if TARGET_OS_OSX || TARGET_OS_IPHONE
1276-
#include <dispatch/dispatch.h>
1277-
#include <sys/sysctl.h>
1278-
1279-
static bool isKnownAndSupported(const char *name) {
1280-
int32_t val = 0;
1281-
size_t size = sizeof(val);
1282-
if (sysctlbyname(name, &val, &size, NULL, 0))
1283-
return false;
1284-
return val;
1285-
}
1286-
1287-
void __init_cpu_features_resolver(void) {
1288-
// On Darwin platforms, this may be called concurrently by multiple threads
1289-
// because the resolvers that use it are called lazily at runtime (unlike on
1290-
// ELF platforms, where IFuncs are resolved serially at load time). This
1291-
// function's effect on __aarch64_cpu_features should be idempotent, but even
1292-
// so we need dispatch_once to resolve the race condition. Dispatch is
1293-
// available through libSystem, which we need anyway for the sysctl, so this
1294-
// does not add a new dependency.
1295-
1296-
static dispatch_once_t onceToken = 0;
1297-
dispatch_once(&onceToken, ^{
1298-
// https://developer.apple.com/documentation/kernel/1387446-sysctlbyname/determining_instruction_set_characteristics
1299-
static struct {
1300-
const char *sysctl_name;
1301-
enum CPUFeatures feature;
1302-
} features[] = {
1303-
{"hw.optional.arm.FEAT_FlagM", FEAT_FLAGM},
1304-
{"hw.optional.arm.FEAT_FlagM2", FEAT_FLAGM2},
1305-
{"hw.optional.arm.FEAT_FHM", FEAT_FP16FML},
1306-
{"hw.optional.arm.FEAT_DotProd", FEAT_DOTPROD},
1307-
{"hw.optional.arm.FEAT_RDM", FEAT_RDM},
1308-
{"hw.optional.arm.FEAT_LSE", FEAT_LSE},
1309-
{"hw.optional.floatingpoint", FEAT_FP},
1310-
{"hw.optional.AdvSIMD", FEAT_SIMD},
1311-
{"hw.optional.armv8_crc32", FEAT_CRC},
1312-
{"hw.optional.arm.FEAT_SHA1", FEAT_SHA1},
1313-
{"hw.optional.arm.FEAT_SHA256", FEAT_SHA2},
1314-
{"hw.optional.arm.FEAT_SHA3", FEAT_SHA3},
1315-
{"hw.optional.arm.FEAT_AES", FEAT_AES},
1316-
{"hw.optional.arm.FEAT_PMULL", FEAT_PMULL},
1317-
{"hw.optional.arm.FEAT_FP16", FEAT_FP16},
1318-
{"hw.optional.arm.FEAT_DIT", FEAT_DIT},
1319-
{"hw.optional.arm.FEAT_DPB", FEAT_DPB},
1320-
{"hw.optional.arm.FEAT_DPB2", FEAT_DPB2},
1321-
{"hw.optional.arm.FEAT_JSCVT", FEAT_JSCVT},
1322-
{"hw.optional.arm.FEAT_FCMA", FEAT_FCMA},
1323-
{"hw.optional.arm.FEAT_LRCPC", FEAT_RCPC},
1324-
{"hw.optional.arm.FEAT_LRCPC2", FEAT_RCPC2},
1325-
{"hw.optional.arm.FEAT_FRINTTS", FEAT_FRINTTS},
1326-
{"hw.optional.arm.FEAT_I8MM", FEAT_I8MM},
1327-
{"hw.optional.arm.FEAT_BF16", FEAT_BF16},
1328-
{"hw.optional.arm.FEAT_SB", FEAT_SB},
1329-
{"hw.optional.arm.FEAT_SPECRES", FEAT_PREDRES},
1330-
{"hw.optional.arm.FEAT_SSBS", FEAT_SSBS2},
1331-
{"hw.optional.arm.FEAT_BTI", FEAT_BTI},
1332-
};
1333-
1334-
for (size_t I = 0, E = sizeof(features) / sizeof(features[0]); I != E; ++I)
1335-
if (isKnownAndSupported(features[I].sysctl_name))
1336-
__aarch64_cpu_features.features |= (1ULL << features[I].feature);
1337-
1338-
__aarch64_cpu_features.features |= (1ULL << FEAT_INIT);
1339-
});
1340-
}
1341-
#endif // TARGET_OS_OSX || TARGET_OS_IPHONE
1342-
#else // defined(__APPLE__)
13431262
static void __init_cpu_features_constructor(unsigned long hwcap,
13441263
const __ifunc_arg_t *arg) {
13451264
#define setCPUFeature(F) __aarch64_cpu_features.features |= 1ULL << F
@@ -1548,8 +1467,8 @@ void __init_cpu_features_resolver(unsigned long hwcap,
15481467
}
15491468

15501469
void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
1551-
unsigned long hwcap = 0;
1552-
unsigned long hwcap2 = 0;
1470+
unsigned long hwcap;
1471+
unsigned long hwcap2;
15531472
// CPU features already initialized.
15541473
if (__aarch64_cpu_features.features)
15551474
return;
@@ -1559,16 +1478,14 @@ void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
15591478
res |= elf_aux_info(AT_HWCAP2, &hwcap2, sizeof hwcap2);
15601479
if (res)
15611480
return;
1562-
#elif defined(HAVE_SYS_AUXV)
1481+
#else
15631482
#if defined(__ANDROID__)
15641483
// Don't set any CPU features,
15651484
// detection could be wrong on Exynos 9810.
15661485
IF_EXYNOS9810 return;
15671486
#endif // defined(__ANDROID__)
15681487
hwcap = getauxval(AT_HWCAP);
15691488
hwcap2 = getauxval(AT_HWCAP2);
1570-
#else
1571-
#error No support for checking hwcap on this platform yet.
15721489
#endif // defined(__FreeBSD__)
15731490
__ifunc_arg_t arg;
15741491
arg._size = sizeof(__ifunc_arg_t);
@@ -1580,7 +1497,8 @@ void CONSTRUCTOR_ATTRIBUTE __init_cpu_features(void) {
15801497
#undef setCPUFeature
15811498
#undef IF_EXYNOS9810
15821499
}
1583-
#endif // defined(__APPLE__)
15841500
#endif // !defined(DISABLE_AARCH64_FMV)
15851501
#endif // defined(__has_include)
1502+
#endif // __has_include(<sys/auxv.h>)
1503+
#endif // __has_include(<asm/hwcap.h>)
15861504
#endif // defined(__aarch64__)

0 commit comments

Comments
 (0)