mac: Don’t build 32-bit ProcessReaderMac support where it’s unusable
There is no possibility to run 32-bit processes on macOS 10.15 or later.
There is never any possibility to run 32-bit processes on macOS on
arm64.
This transforms ProcessReaderMac::Is64Bit into a compile-time constant
“yes” when building for a system that will never see a 32-bit process.
This is a lightweight way to get much 32-bit support code removed from
optimized compiled output, including all of process_types. In an
optimized build of crashpad_handler for arm64, this is a 3% reduction
from 569kB to 552kB (-17kB).
Change-Id: Ib93eaa6d1bc7f19067889dd8ef261d1ef1966573
Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/2389010
Commit-Queue: Mark Mentovai <mark@chromium.org>
Reviewed-by: Robert Sesek <rsesek@chromium.org>
GitOrigin-RevId: df12d57e97b42e25f7ebde2e4ff3429e9c34a3d8
diff --git a/snapshot/mac/process_reader_mac.cc b/snapshot/mac/process_reader_mac.cc
index fafa615..821fe3c 100644
--- a/snapshot/mac/process_reader_mac.cc
+++ b/snapshot/mac/process_reader_mac.cc
@@ -95,9 +95,12 @@
process_memory_(),
task_(TASK_NULL),
initialized_(),
+#if defined(CRASHPAD_MAC_32_BIT_SUPPORT)
is_64_bit_(false),
+#endif // CRASHPAD_MAC_32_BIT_SUPPORT
initialized_threads_(false),
- initialized_modules_(false) {}
+ initialized_modules_(false) {
+}
ProcessReaderMac::~ProcessReaderMac() {
for (const Thread& thread : threads_) {
@@ -117,7 +120,12 @@
return false;
}
+#if defined(CRASHPAD_MAC_32_BIT_SUPPORT)
is_64_bit_ = process_info_.Is64Bit();
+#else // CRASHPAD_MAC_32_BIT_SUPPORT
+ DCHECK(process_info_.Is64Bit());
+#endif // CRASHPAD_MAC_32_BIT_SUPPORT
+
task_ = task;
INITIALIZATION_STATE_SET_VALID(initialized_);
diff --git a/snapshot/mac/process_reader_mac.h b/snapshot/mac/process_reader_mac.h
index ac57a06..2f8ea9d 100644
--- a/snapshot/mac/process_reader_mac.h
+++ b/snapshot/mac/process_reader_mac.h
@@ -15,6 +15,7 @@
#ifndef CRASHPAD_SNAPSHOT_MAC_PROCESS_READER_MAC_H_
#define CRASHPAD_SNAPSHOT_MAC_PROCESS_READER_MAC_H_
+#include <Availability.h>
#include <mach/mach.h>
#include <stdint.h>
#include <sys/time.h>
@@ -31,6 +32,14 @@
#include "util/posix/process_info.h"
#include "util/process/process_memory_mac.h"
+#if defined(ARCH_CPU_32_BIT) || \
+ (!defined(ARCH_CPU_ARM64) && \
+ __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_15)
+// There’s no 32-bit x86 environment on macOS 10.15 or later, and there’s no
+// 32-bit ARM environment for macOS at all.
+#define CRASHPAD_MAC_32_BIT_SUPPORT 1
+#endif // ARCH_CPU_32_BIT || (!ARCH_CPU_ARM64 && DT < 10.15)
+
namespace crashpad {
class MachOImageReader;
@@ -116,7 +125,11 @@
bool Initialize(task_t task);
//! \return `true` if the target task is a 64-bit process.
+#if defined(CRASHPAD_MAC_32_BIT_SUPPORT) || DOXYGEN
bool Is64Bit() const { return is_64_bit_; }
+#else // CRASHPAD_MAC_32_BIT_SUPPORT
+ bool Is64Bit() const { return true; }
+#endif // CRASHPAD_MAC_32_BIT_SUPPORT
//! \return The target task’s process ID.
pid_t ProcessID() const { return process_info_.ProcessID(); }
@@ -240,10 +253,12 @@
task_t task_; // weak
InitializationStateDcheck initialized_;
+#if defined(CRASHPAD_MAC_32_BIT_SUPPORT)
// This shadows a method of process_info_, but it’s accessed so frequently
// that it’s given a first-class field to save a call and a few bit operations
// on each access.
bool is_64_bit_;
+#endif // CRASHPAD_MAC_32_BIT_SUPPORT
bool initialized_threads_;
bool initialized_modules_;