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: I8890a170467834b99b017f1aa3dc78f3f33cd13e
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>
This commit is contained in:
Mark Mentovai 2020-09-01 20:21:15 -04:00 committed by Commit Bot
parent 0bc3826129
commit df12d57e97
2 changed files with 24 additions and 1 deletions

View File

@ -95,9 +95,12 @@ ProcessReaderMac::ProcessReaderMac()
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 @@ bool ProcessReaderMac::Initialize(task_t task) {
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_);

View File

@ -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)
// Theres no 32-bit x86 environment on macOS 10.15 or later, and theres 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 @@ class ProcessReaderMac {
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 tasks process ID.
pid_t ProcessID() const { return process_info_.ProcessID(); }
@ -240,10 +253,12 @@ class ProcessReaderMac {
task_t task_; // weak
InitializationStateDcheck initialized_;
#if defined(CRASHPAD_MAC_32_BIT_SUPPORT)
// This shadows a method of process_info_, but its accessed so frequently
// that its 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_;