Fallback to uname for detecting ARM CPU architecture

Currently running official dart `linux/arm/v7` container image on x86_64 with QEMU results in `Unrecognized ARM CPU architecture`.

This is due to QEMU reporting host `/proc/cpuinfo` instead of the emulated architecture.

Checking `uname` in addition to `/proc/cpuinfo` would make `linux/arm/v7` build work consistently regardless of whether `--use-qemu` is supplied during SDK build time.

TEST=running the qemu bot
TEST=ran the ffi/hardfp_test.dart locally both in AOT and JIT mode.

Closes https://github.com/dart-lang/sdk/pull/48665
https://github.com/dart-lang/sdk/pull/48665

GitOrigin-RevId: d1414d747152d048f3ecaadfd0cd3356ce7a2205
Change-Id: If8b42a700d55e83fea0ee0035848308a3211ec43
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238841
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
This commit is contained in:
なつき 2022-04-13 07:54:02 +00:00 committed by Commit Bot
parent 2ed65e2a13
commit c50940b56b
2 changed files with 16 additions and 9 deletions

View file

@ -35,10 +35,6 @@ config("sdk") {
]
}
}
if (is_qemu) {
cflags += [ "-DDART_RUN_IN_QEMU_ARMv7" ]
}
}
config("executable_config") {

View file

@ -20,6 +20,10 @@
#elif defined(DART_HOST_OS_WINDOWS)
#include <processthreadsapi.h>
#endif
#if !defined(DART_HOST_OS_WINDOWS)
#include <string.h> /* NOLINT */
#include <sys/utsname.h> /* NOLINT */
#endif
#endif
// ARM version differences.
@ -145,20 +149,27 @@ void HostCPUFeatures::Init() {
CpuInfo::Init();
hardware_ = CpuInfo::GetCpuModel();
// QEMU may report host cpuinfo instead of emulated cpuinfo, use uname as a
// fallback for checking if CPU is AArch64 or ARMv7.
struct utsname uname_;
int ret_ = uname(&uname_);
// Check for ARMv7, or aarch64.
// It can be in either the Processor or Model information fields.
if (CpuInfo::FieldContains(kCpuInfoProcessor, "aarch64") ||
CpuInfo::FieldContains(kCpuInfoModel, "aarch64") ||
CpuInfo::FieldContains(kCpuInfoArchitecture, "8") ||
CpuInfo::FieldContains(kCpuInfoArchitecture, "AArch64")) {
CpuInfo::FieldContains(kCpuInfoArchitecture, "AArch64") ||
(ret_ == 0 && (strstr(uname_.machine, "aarch64") != NULL ||
strstr(uname_.machine, "arm64") != NULL ||
strstr(uname_.machine, "armv8") != NULL))) {
// pretend that this arm64 cpu is really an ARMv7
is_arm64 = true;
} else if (!CpuInfo::FieldContains(kCpuInfoProcessor, "ARMv7") &&
!CpuInfo::FieldContains(kCpuInfoModel, "ARMv7") &&
!CpuInfo::FieldContains(kCpuInfoArchitecture, "7")) {
#if !defined(DART_RUN_IN_QEMU_ARMv7)
!CpuInfo::FieldContains(kCpuInfoArchitecture, "7") &&
!(ret_ == 0 && strstr(uname_.machine, "armv7") != NULL)) {
FATAL("Unrecognized ARM CPU architecture.");
#endif
}
// Has integer division.
@ -203,7 +214,7 @@ void HostCPUFeatures::Init() {
// Use the cross-compiler's predefined macros to determine whether we should
// use the hard or soft float ABI.
#if defined(__ARM_PCS_VFP) || defined(DART_RUN_IN_QEMU_ARMv7)
#if defined(__ARM_PCS_VFP)
hardfp_supported_ = true;
#else
hardfp_supported_ = false;