Skip to content

Commit 19c1b15

Browse files
[Crashlytics] update deprecated kernel api for visionPro (#11515)
* [Crashlytics] Fix build issues on visionOS Fixed Firebase Crashlytics SDK build issues for visionOS, along with corresponding unit test changes. This also resolves build issues with the underlying Firebase Sessions SDK. * Allow pod-lib-lint warnings for Firebase Sessions * VisionOS deprecated kernel api update * Moved `swift(>=5.9)` check to separate `#if` statement * Move swift(>=5.9) check in SessionStartEventTests * adding comment, declear and use internal macro --------- Co-authored-by: Andrew Heard <[email protected]>
1 parent cc3ed01 commit 19c1b15

File tree

8 files changed

+549
-227
lines changed

8 files changed

+549
-227
lines changed

.github/workflows/sessions.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ jobs:
3333
run: scripts/setup_bundler.sh
3434
- name: Build and test
3535
run: |
36-
scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseSessions.podspec --platforms=${{ matrix.target }}
36+
scripts/third_party/travis/retry.sh scripts/pod_lib_lint.rb FirebaseSessions.podspec \
37+
--platforms=${{ matrix.target }} \
3738
3839
spm:
3940
# Don't run on private repo unless it is a PR.

Crashlytics/Crashlytics/Components/FIRCLSBinaryImage.m

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "Crashlytics/Crashlytics/Components/FIRCLSGlobals.h"
2525
#include "Crashlytics/Crashlytics/Components/FIRCLSHost.h"
26+
#include "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
2627
#include "Crashlytics/Crashlytics/Helpers/FIRCLSFeatures.h"
2728
#include "Crashlytics/Crashlytics/Helpers/FIRCLSFile.h"
2829
#include "Crashlytics/Crashlytics/Helpers/FIRCLSUtility.h"
@@ -241,7 +242,7 @@ static FIRCLSMachOSegmentCommand FIRCLSBinaryImageMachOGetSegmentCommand(
241242

242243
return segmentCommand;
243244
}
244-
245+
#if !CLS_TARGET_OS_XR
245246
static bool FIRCLSBinaryImageMachOSliceInitSectionByName(FIRCLSMachOSliceRef slice,
246247
const char* segName,
247248
const char* sectionName,
@@ -279,6 +280,7 @@ static bool FIRCLSBinaryImageMachOSliceInitSectionByName(FIRCLSMachOSliceRef sli
279280

280281
return true;
281282
}
283+
#endif
282284

283285
static void FIRCLSPopulateImageDetailWithLoadCommand(uint32_t type,
284286
uint32_t size,
@@ -343,23 +345,41 @@ static bool FIRCLSBinaryImageFillInImageDetails(FIRCLSBinaryImageDetails* detail
343345
FIRCLSMachOSection section;
344346

345347
#if CLS_COMPACT_UNWINDING_SUPPORTED
348+
#if !CLS_TARGET_OS_XR
346349
if (FIRCLSBinaryImageMachOSliceInitSectionByName(&details->slice, SEG_TEXT, "__unwind_info",
347350
&section)) {
348351
details->node.unwindInfo = (void*)(section.addr + details->vmaddr_slide);
349352
}
353+
#else
354+
unsigned long unwindInfoSize;
355+
details->node.unwindInfo = (void*)getsectiondata(details->slice.startAddress, "__TEXT",
356+
"__unwind_info", &unwindInfoSize);
357+
#endif
350358
#endif
351359

352360
#if CLS_DWARF_UNWINDING_SUPPORTED
361+
#if !CLS_TARGET_OS_XR
353362
if (FIRCLSBinaryImageMachOSliceInitSectionByName(&details->slice, SEG_TEXT, "__eh_frame",
354363
&section)) {
355364
details->node.ehFrame = (void*)(section.addr + details->vmaddr_slide);
356365
}
366+
#else
367+
unsigned long ehFrameSize;
368+
details->node.ehFrame =
369+
(void*)getsectiondata(details->slice.startAddress, "__TEXT", "__eh_frame", &ehFrameSize);
370+
#endif
357371
#endif
358372

373+
#if !CLS_TARGET_OS_XR
359374
if (FIRCLSBinaryImageMachOSliceInitSectionByName(&details->slice, SEG_DATA, "__crash_info",
360375
&section)) {
361376
details->node.crashInfo = (void*)(section.addr + details->vmaddr_slide);
362377
}
378+
#else
379+
unsigned long crashInfoSize;
380+
details->node.crashInfo =
381+
(void*)getsectiondata(details->slice.startAddress, "__TEXT", "__crash_info", &crashInfoSize);
382+
#endif
363383

364384
return true;
365385
}

Crashlytics/Crashlytics/Controllers/FIRCLSNotificationManager.m

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#import "Crashlytics/Crashlytics/Components/FIRCLSApplication.h"
1818
#import "Crashlytics/Crashlytics/Components/FIRCLSGlobals.h"
1919
#import "Crashlytics/Crashlytics/Components/FIRCLSUserLogging.h"
20+
#include "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
2021

2122
#if TARGET_OS_IPHONE
2223
#import <UIKit/UIKit.h>
@@ -38,6 +39,7 @@ - (void)registerNotificationListener {
3839
selector:@selector(didBecomeInactive:)
3940
name:UIApplicationDidEnterBackgroundNotification
4041
object:nil];
42+
#if !CLS_TARGET_OS_XR
4143
[[NSNotificationCenter defaultCenter] addObserver:self
4244
selector:@selector(didChangeOrientation:)
4345
name:UIDeviceOrientationDidChangeNotification
@@ -51,6 +53,7 @@ - (void)registerNotificationListener {
5153
name:UIApplicationDidChangeStatusBarOrientationNotification
5254
object:nil];
5355
#pragma clang diagnostic pop
56+
#endif // !CLS_TARGET_OS_XR
5457

5558
#elif CLS_TARGET_OS_OSX
5659
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -65,22 +68,22 @@ - (void)registerNotificationListener {
6568
}
6669

6770
- (void)captureInitialNotificationStates {
68-
#if TARGET_OS_IOS
71+
#if TARGET_OS_IOS && (!CLS_TARGET_OS_XR)
6972
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
7073
UIInterfaceOrientation statusBarOrientation =
7174
[FIRCLSApplicationSharedInstance() statusBarOrientation];
72-
#endif
75+
#endif // TARGET_OS_IOS && (!CLS_TARGET_OS_XR)
7376

7477
// It's nice to do this async, so we don't hold up the main thread while doing three
7578
// consecutive IOs here.
7679
dispatch_async(FIRCLSGetLoggingQueue(), ^{
7780
FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSInBackgroundKey, @"0");
78-
#if TARGET_OS_IOS
81+
#if TARGET_OS_IOS && (!CLS_TARGET_OS_XR)
7982
FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSDeviceOrientationKey,
8083
[@(orientation) description]);
8184
FIRCLSUserLoggingWriteInternalKeyValue(FIRCLSUIOrientationKey,
8285
[@(statusBarOrientation) description]);
83-
#endif
86+
#endif // TARGET_OS_IOS && (!CLS_TARGET_OS_XR)
8487
});
8588
}
8689

@@ -92,7 +95,7 @@ - (void)didBecomeInactive:(NSNotification *)notification {
9295
FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSInBackgroundKey, @YES);
9396
}
9497

95-
#if TARGET_OS_IOS
98+
#if TARGET_OS_IOS && (!CLS_TARGET_OS_XR)
9699
- (void)didChangeOrientation:(NSNotification *)notification {
97100
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
98101

@@ -105,6 +108,6 @@ - (void)didChangeUIOrientation:(NSNotification *)notification {
105108

106109
FIRCLSUserLoggingRecordInternalKeyValue(FIRCLSUIOrientationKey, @(statusBarOrientation));
107110
}
108-
#endif
111+
#endif // TARGET_OS_IOS && (!CLS_TARGET_OS_XR)
109112

110113
@end

Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@
5757
#include <arm/arch.h>
5858
#endif
5959

60+
// VisionOS support
61+
#if defined(TARGET_OS_XR) && TARGET_OS_XR
62+
#define CLS_TARGET_OS_XR 1
63+
#else
64+
#define CLS_TARGET_OS_XR 0
65+
#endif
66+
6067
#if defined(__arm__)
6168
#define CLS_CPU_ARM 1
6269
#endif

Crashlytics/Shared/FIRCLSMachO/FIRCLSMachO.m

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
// limitations under the License.
1414

1515
#include "Crashlytics/Shared/FIRCLSMachO/FIRCLSMachO.h"
16+
#include "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
1617

1718
#include <Foundation/Foundation.h>
1819

1920
#include <mach-o/dyld.h>
2021
#include <mach-o/fat.h>
2122
#include <mach-o/getsect.h>
2223
#include <mach-o/ldsyms.h>
24+
#include <mach-o/utils.h>
2325

2426
#include <sys/mman.h>
2527
#include <sys/stat.h>
@@ -261,16 +263,28 @@ void FIRCLSMachOSliceEnumerateLoadCommands(FIRCLSMachOSliceRef slice,
261263
}
262264

263265
struct FIRCLSMachOSlice FIRCLSMachOSliceGetCurrent(void) {
264-
const NXArchInfo* archInfo;
265266
struct FIRCLSMachOSlice slice;
266267
void* executableSymbol;
267268
Dl_info dlinfo;
268269

270+
#if !CLS_TARGET_OS_XR
271+
const NXArchInfo* archInfo;
269272
archInfo = NXGetLocalArchInfo();
273+
270274
if (archInfo) {
271275
slice.cputype = archInfo->cputype;
272276
slice.cpusubtype = archInfo->cpusubtype;
273277
}
278+
#else
279+
cpu_type_t cputype;
280+
cpu_subtype_t cpusubtype;
281+
const char* archname = macho_arch_name_for_mach_header(NULL);
282+
bool hasArchInfo = macho_cpu_type_for_arch_name(archname, &cputype, &cpusubtype);
283+
if (hasArchInfo) {
284+
slice.cputype = cputype;
285+
slice.cpusubtype = cpusubtype;
286+
}
287+
#endif
274288

275289
slice.startAddress = NULL;
276290

@@ -311,8 +325,6 @@ struct FIRCLSMachOSlice FIRCLSMachOSliceWithHeader(void* machHeader) {
311325
}
312326

313327
const char* FIRCLSMachOSliceGetArchitectureName(FIRCLSMachOSliceRef slice) {
314-
const NXArchInfo* archInfo;
315-
316328
// there are some special cases here for types not handled by earlier OSes
317329
if (slice->cputype == CPU_TYPE_ARM && slice->cpusubtype == CPU_SUBTYPE_ARM_V7S) {
318330
return "armv7s";
@@ -330,19 +342,31 @@ struct FIRCLSMachOSlice FIRCLSMachOSliceWithHeader(void* machHeader) {
330342
return "armv7k";
331343
}
332344

345+
#if !CLS_TARGET_OS_XR
346+
const NXArchInfo* archInfo;
347+
333348
archInfo = NXGetArchInfoFromCpuType(slice->cputype, slice->cpusubtype);
334349
if (!archInfo) {
335350
return "unknown";
336351
}
337352

338353
return archInfo->name;
354+
#else
355+
const char* archname = macho_arch_name_for_mach_header(NULL);
356+
357+
if (!archname) {
358+
return "unknown";
359+
}
360+
return archname;
361+
#endif
339362
}
340363

341364
bool FIRCLSMachOSliceIs64Bit(FIRCLSMachOSliceRef slice) {
342365
// I'm pretty sure this is sufficient...
343366
return (slice->cputype & CPU_ARCH_ABI64) == CPU_ARCH_ABI64;
344367
}
345368

369+
// deprecated
346370
bool FIRCLSMachOSliceGetSectionByName(FIRCLSMachOSliceRef slice,
347371
const char* segName,
348372
const char* sectionName,
@@ -381,6 +405,9 @@ bool FIRCLSMachOSliceInitSectionByName(FIRCLSMachOSliceRef slice,
381405

382406
memset(section, 0, sizeof(FIRCLSMachOSection));
383407

408+
// Deprecated code for vision OS, entire function is not used anywhere
409+
#pragma clang diagnostic push
410+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
384411
if (FIRCLSMachOSliceIs64Bit(slice)) {
385412
const struct section_64* sect =
386413
getsectbynamefromheader_64(slice->startAddress, segName, sectionName);
@@ -401,7 +428,7 @@ bool FIRCLSMachOSliceInitSectionByName(FIRCLSMachOSliceRef slice,
401428
section->size = sect->size;
402429
section->offset = sect->offset;
403430
}
404-
431+
#pragma clang diagnostic pop
405432
return true;
406433
}
407434

Crashlytics/UnitTests/FIRCLSMachO/FIRCLSMachOTests.m

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
// limitations under the License.
1414

1515
#import "Crashlytics/UnitTests/FIRCLSMachO/FIRCLSMachOTests.h"
16+
#include <mach-o/dyld.h>
17+
#include <mach-o/getsect.h>
18+
#include <mach-o/utils.h>
1619

17-
#import "Crashlytics/Shared/FIRCLSMachO/FIRCLSMachO.h"
20+
#include "Crashlytics/Crashlytics/Helpers/FIRCLSDefines.h"
1821

22+
#import "Crashlytics/Shared/FIRCLSMachO/FIRCLSMachO.h"
1923
#import "Crashlytics/Shared/FIRCLSMachO/FIRCLSMachOBinary.h"
2024
#import "Crashlytics/Shared/FIRCLSMachO/FIRCLSMachOSlice.h"
2125
#import "Crashlytics/Shared/FIRCLSMachO/FIRCLSdSYM.h"
@@ -313,6 +317,7 @@ - (void)testReadArmv7kSection {
313317
XCTAssert(ptr != NULL);
314318
}
315319

320+
#if !CLS_TARGET_OS_XR
316321
- (void)testReadArm64Section {
317322
NSString* path = [[self resourcePath] stringByAppendingPathComponent:@"armv7-armv7s-arm64.dylib"];
318323
struct FIRCLSMachOFile file;
@@ -333,5 +338,17 @@ - (void)testReadArm64Section {
333338
XCTAssert(FIRCLSMachOSliceGetSectionByName(&slice, SEG_TEXT, "__unwind_info", &ptr));
334339
XCTAssert(ptr != NULL);
335340
}
341+
#endif
342+
343+
#if CLS_TARGET_OS_XR
344+
345+
- (void)testVisionProGetSlice {
346+
struct FIRCLSMachOSlice slice = FIRCLSMachOSliceGetCurrent();
347+
XCTAssertEqual(slice.cputype, CPU_TYPE_ARM64);
348+
349+
const char* archname = macho_arch_name_for_mach_header(NULL);
350+
XCTAssertEqualObjects(@(archname), @"arm64");
351+
}
352+
#endif
336353

337354
@end

0 commit comments

Comments
 (0)