From fd42b25c4512913fd47a86826aecec7c9c3ee2b4 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 12 Jul 2022 07:11:32 -0700 Subject: Skip caches that have processor_count==0. Some crash reports on Android tell of segfaults at address (2^32 - 8) at the line below evaluating is_local, which I guess would happen if processor_count==0. PiperOrigin-RevId: 460454326 --- CMakeLists.txt | 6 +++++- ruy/cpuinfo.cc | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 262d704..e085ed0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ option(RUY_FIND_CPUINFO "Use find_package to find cpuinfo" OFF) # Skip cpuinfo if it was already generated, which can happen when ruy is # a subdirectory in a wider project that already uses cpuinfo. -if (NOT TARGET cpuinfo::cpuinfo) +if (NOT TARGET cpuinfo AND NOT TARGET cpuinfo::cpuinfo) if (RUY_FIND_CPUINFO) find_package(cpuinfo REQUIRED) else() @@ -82,6 +82,10 @@ if (NOT TARGET cpuinfo::cpuinfo) endif() endif() +if (TARGET cpuinfo AND NOT TARGET cpuinfo::cpuinfo) + add_library(cpuinfo::cpuinfo ALIAS cpuinfo) +endif() + # googletest is only needed for tests. Projects embedding ruy as a subdirectory # and not needing to build ruy tests may proceed without a local checkout of # third_party/googletest. diff --git a/ruy/cpuinfo.cc b/ruy/cpuinfo.cc index a3e75d7..8a0e912 100644 --- a/ruy/cpuinfo.cc +++ b/ruy/cpuinfo.cc @@ -56,6 +56,9 @@ void QueryCacheParams(CpuCacheParams* cache_params) { continue; // continue, not break, it is possible to have L1+L3 but no // L2. } + if (!cache->processor_count) { + continue; // crashes from Chrome on Android suggests that might happen? + } const bool is_local = cpuinfo_get_processor(cache->processor_start)->core == cpuinfo_get_processor(cache->processor_start + -- cgit v1.2.3