From dd0ca9d70af2ded3cf6f561214284f3abdb26748 Mon Sep 17 00:00:00 2001 From: Leonard Grey Date: Wed, 18 Jan 2023 16:15:04 -0500 Subject: [PATCH] Mac dump_syms: work around NXFindBestFatArch bug On macOS 13 x86_64 machines, NXFindBestFatArch does not correctly find arm64e slices. This is filed as FB11955188. I was hoping manually masking the subtype with CPU_SUBTYPE_MASK would be sufficient to work around but no luck. So let's just fall through to doing an exact* match if NXFindBestFatArch fails. * "Exact" meaning with CPU_SUBTYPE_MASK now masked off. But libmacho/arch.c calls that exact too, so I'm just going to go with it. Bug: 1400770 Change-Id: Id497946d3c719285c5d7508e589e4a466da1ceca Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/4178621 Reviewed-by: Mark Mentovai --- src/common/mac/dump_syms.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/common/mac/dump_syms.cc b/src/common/mac/dump_syms.cc index 661cc89c..9658b2c6 100644 --- a/src/common/mac/dump_syms.cc +++ b/src/common/mac/dump_syms.cc @@ -268,7 +268,8 @@ SuperFatArch* DumpSymbols::FindBestMatchForArchitecture( return &object_files_[i]; } assert(best_match == NULL); - return NULL; + // Fall through since NXFindBestFatArch can't find arm slices on x86_64 + // macOS 13. See FB11955188. } // Check for an exact match with cpu_type and cpu_subtype. @@ -276,7 +277,8 @@ SuperFatArch* DumpSymbols::FindBestMatchForArchitecture( it != object_files_.end(); ++it) { if (static_cast(it->cputype) == cpu_type && - static_cast(it->cpusubtype) == cpu_subtype) + (static_cast(it->cpusubtype) & ~CPU_SUBTYPE_MASK) == + (cpu_subtype & ~CPU_SUBTYPE_MASK)) return &*it; } @@ -285,8 +287,11 @@ SuperFatArch* DumpSymbols::FindBestMatchForArchitecture( // NXFindBestFatArch, located at // http://web.mit.edu/darwin/src/modules/cctools/libmacho/arch.c. fprintf(stderr, "Failed to find an exact match for an object file with cpu " - "type: %d and cpu subtype: %d. Furthermore, at least one object file is " - "larger than 2**32.\n", cpu_type, cpu_subtype); + "type: %d and cpu subtype: %d.\n", cpu_type, cpu_subtype); + if (!can_convert_to_fat_arch) { + fprintf(stderr, "Furthermore, at least one object file is larger " + "than 2**32.\n"); + } return NULL; }