@@ -838,6 +838,66 @@ int CONSTRUCTOR_ATTRIBUTE __cpu_indicator_init(void) {
838
838
return 0 ;
839
839
}
840
840
#elif defined(__aarch64__ )
841
+ // LSE support detection for out-of-line atomics
842
+ // using HWCAP and Auxiliary vector
843
+ _Bool __aarch64_have_lse_atomics
844
+ __attribute__((visibility ("hidden" ), nocommon ));
845
+
846
+ #if defined(__has_include )
847
+ #if __has_include (< sys /auxv .h > )
848
+ #include <sys/auxv.h>
849
+ #if __has_include (< asm /hwcap .h > )
850
+ #include <asm/hwcap.h>
851
+
852
+ #if defined(__ANDROID__ )
853
+ #include <string.h>
854
+ #include <sys/system_properties.h>
855
+ #elif defined(__Fuchsia__ )
856
+ #include <zircon/features.h>
857
+ #include <zircon/syscalls.h>
858
+ #endif
859
+
860
+ // Detect Exynos 9810 CPU
861
+ #define IF_EXYNOS9810 \
862
+ char arch[PROP_VALUE_MAX]; \
863
+ if (__system_property_get("ro.arch", arch) > 0 && \
864
+ strncmp(arch, "exynos9810", sizeof("exynos9810") - 1) == 0)
865
+
866
+ static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics (void ) {
867
+ #if defined(__FreeBSD__ )
868
+ unsigned long hwcap ;
869
+ int result = elf_aux_info (AT_HWCAP , & hwcap , sizeof hwcap );
870
+ __aarch64_have_lse_atomics = result == 0 && (hwcap & HWCAP_ATOMICS ) != 0 ;
871
+ #elif defined(__Fuchsia__ )
872
+ // This ensures the vDSO is a direct link-time dependency of anything that
873
+ // needs this initializer code.
874
+ #pragma comment(lib, "zircon")
875
+ uint32_t features ;
876
+ zx_status_t status = _zx_system_get_features (ZX_FEATURE_KIND_CPU , & features );
877
+ __aarch64_have_lse_atomics =
878
+ status == ZX_OK && (features & ZX_ARM64_FEATURE_ISA_ATOMICS ) != 0 ;
879
+ #else
880
+ unsigned long hwcap = getauxval (AT_HWCAP );
881
+ _Bool result = (hwcap & HWCAP_ATOMICS ) != 0 ;
882
+ #if defined(__ANDROID__ )
883
+ if (result ) {
884
+ // Some cores in the Exynos 9810 CPU are ARMv8.2 and others are ARMv8.0;
885
+ // only the former support LSE atomics. However, the kernel in the
886
+ // initial Android 8.0 release of Galaxy S9/S9+ devices incorrectly
887
+ // reported the feature as being supported.
888
+ //
889
+ // The kernel appears to have been corrected to mark it unsupported as of
890
+ // the Android 9.0 release on those devices, and this issue has not been
891
+ // observed anywhere else. Thus, this workaround may be removed if
892
+ // compiler-rt ever drops support for Android 8.0.
893
+ IF_EXYNOS9810 result = false;
894
+ }
895
+ #endif // defined(__ANDROID__)
896
+ __aarch64_have_lse_atomics = result ;
897
+ #endif // defined(__FreeBSD__)
898
+ }
899
+
900
+ #if !defined(DISABLE_AARCH64_FMV )
841
901
// CPUFeatures must correspond to the same AArch64 features in
842
902
// AArch64TargetParser.h
843
903
enum CPUFeatures {
@@ -901,27 +961,17 @@ enum CPUFeatures {
901
961
FEAT_SME2 ,
902
962
FEAT_MAX
903
963
};
964
+
904
965
// Architecture features used
905
966
// in Function Multi Versioning
906
967
struct {
907
968
unsigned long long features ;
908
969
// As features grows new fields could be added
909
970
} __aarch64_cpu_features __attribute__((visibility ("hidden" ), nocommon ));
910
971
911
- // LSE support detection for out-of-line atomics
912
- // using HWCAP and Auxiliary vector
913
- _Bool __aarch64_have_lse_atomics
914
- __attribute__((visibility ("hidden" ), nocommon ));
915
- #if defined(__has_include )
916
- #if __has_include (< sys /auxv .h > )
917
- #include <sys/auxv.h>
918
- #if __has_include (< asm /hwcap .h > )
919
- #include <asm/hwcap.h>
920
-
921
972
#ifndef AT_HWCAP
922
973
#define AT_HWCAP 16
923
974
#endif
924
-
925
975
#ifndef HWCAP_CPUID
926
976
#define HWCAP_CPUID (1 << 11)
927
977
#endif
@@ -1086,54 +1136,6 @@ _Bool __aarch64_have_lse_atomics
1086
1136
#define HWCAP2_SVE_EBF16 (1UL << 33)
1087
1137
#endif
1088
1138
1089
- #if defined(__ANDROID__ )
1090
- #include <string.h>
1091
- #include <sys/system_properties.h>
1092
- #elif defined(__Fuchsia__ )
1093
- #include <zircon/features.h>
1094
- #include <zircon/syscalls.h>
1095
- #endif
1096
-
1097
- // Detect Exynos 9810 CPU
1098
- #define IF_EXYNOS9810 \
1099
- char arch[PROP_VALUE_MAX]; \
1100
- if (__system_property_get("ro.arch", arch) > 0 && \
1101
- strncmp(arch, "exynos9810", sizeof("exynos9810") - 1) == 0)
1102
-
1103
- static void CONSTRUCTOR_ATTRIBUTE init_have_lse_atomics (void ) {
1104
- #if defined(__FreeBSD__ )
1105
- unsigned long hwcap ;
1106
- int result = elf_aux_info (AT_HWCAP , & hwcap , sizeof hwcap );
1107
- __aarch64_have_lse_atomics = result == 0 && (hwcap & HWCAP_ATOMICS ) != 0 ;
1108
- #elif defined(__Fuchsia__ )
1109
- // This ensures the vDSO is a direct link-time dependency of anything that
1110
- // needs this initializer code.
1111
- #pragma comment(lib, "zircon")
1112
- uint32_t features ;
1113
- zx_status_t status = _zx_system_get_features (ZX_FEATURE_KIND_CPU , & features );
1114
- __aarch64_have_lse_atomics =
1115
- status == ZX_OK && (features & ZX_ARM64_FEATURE_ISA_ATOMICS ) != 0 ;
1116
- #else
1117
- unsigned long hwcap = getauxval (AT_HWCAP );
1118
- _Bool result = (hwcap & HWCAP_ATOMICS ) != 0 ;
1119
- #if defined(__ANDROID__ )
1120
- if (result ) {
1121
- // Some cores in the Exynos 9810 CPU are ARMv8.2 and others are ARMv8.0;
1122
- // only the former support LSE atomics. However, the kernel in the
1123
- // initial Android 8.0 release of Galaxy S9/S9+ devices incorrectly
1124
- // reported the feature as being supported.
1125
- //
1126
- // The kernel appears to have been corrected to mark it unsupported as of
1127
- // the Android 9.0 release on those devices, and this issue has not been
1128
- // observed anywhere else. Thus, this workaround may be removed if
1129
- // compiler-rt ever drops support for Android 8.0.
1130
- IF_EXYNOS9810 result = false;
1131
- }
1132
- #endif // defined(__ANDROID__)
1133
- __aarch64_have_lse_atomics = result ;
1134
- #endif // defined(__FreeBSD__)
1135
- }
1136
-
1137
1139
void init_cpu_features_resolver (unsigned long hwcap , unsigned long hwcap2 ) {
1138
1140
#define setCPUFeature (F ) __aarch64_cpu_features.features |= 1ULL << F
1139
1141
#define getCPUFeature (id , ftr ) __asm__("mrs %0, " #id : "=r"(ftr))
@@ -1344,6 +1346,7 @@ void CONSTRUCTOR_ATTRIBUTE init_cpu_features(void) {
1344
1346
#undef setCPUFeature
1345
1347
#undef IF_EXYNOS9810
1346
1348
}
1349
+ #endif // !defined(DISABLE_AARCH64_FMV)
1347
1350
#endif // defined(__has_include)
1348
1351
#endif // __has_include(<sys/auxv.h>)
1349
1352
#endif // __has_include(<asm/hwcap.h>)
0 commit comments