Skip to content

Commit 2766f21

Browse files
authored
[ORC] Loosen __objc_imageinfo flag merging to match ld (#91767)
Allow mixing objects with/without signed class ro data and category class properties as long as it happens before we register the metadata. These combinations are a warning in ld, not a hard error. The only case that is ABI-breaking is if we already registered with the feature enabled but later try to load an object that doesn't support it. rdar://127336061
1 parent 736ffdc commit 2766f21

File tree

3 files changed

+50
-8
lines changed

3 files changed

+50
-8
lines changed

compiler-rt/test/orc/TestCases/Darwin/arm64/objc-imageinfo.S

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727

2828
// Check error conditions.
2929

30-
// RUN: not %llvm_jitlink %t/main.o %t/objc_old.o %t/objc_new.o 2>&1 | FileCheck %s -check-prefix=CATEGORY
31-
// CATEGORY: ObjC category class property support in {{.*}} does not match first registered flags
32-
3330
// RUN: not %llvm_jitlink %t/main.o %t/swift_4.o %t/swift_5.o 2>&1 | FileCheck %s -check-prefix=SWIFT_ABI
3431
// SWIFT_ABI: Swift ABI version in {{.*}} does not match first registered flags
3532

@@ -47,6 +44,14 @@
4744
// RUN: %llvm_jitlink -debug-only=orc %t/main.o %t/swift_59.o %t/swift_5.o %t/objc_new.o 2>&1 | FileCheck %s -check-prefix=SWIFT_MIX3
4845
// SWIFT_MIX3: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x5000740
4946

47+
// Disable categories.
48+
// RUN: %llvm_jitlink -debug-only=orc %t/main.o %t/objc_old.o %t/objc_new.o 2>&1 | FileCheck %s -check-prefix=SWIFT_MIX4
49+
// SWIFT_MIX4: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x0000
50+
51+
// Disable signed class_ro.
52+
// RUN: %llvm_jitlink -debug-only=orc %t/main.o %t/objc_new.o %t/objc_new_signed_ro.o 2>&1 | FileCheck %s -check-prefix=SWIFT_MIX5
53+
// SWIFT_MIX5: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x0040
54+
5055
//--- main.S
5156
.section __TEXT,__text,regular,pure_instructions
5257
.globl _main
@@ -76,6 +81,17 @@ L_OBJC_IMAGE_INFO:
7681
.long 0
7782
.long 64
7883

84+
//--- objc_new_signed_ro.S
85+
.section __TEXT,__text,regular,pure_instructions
86+
.globl _objc3
87+
_objc3:
88+
ret
89+
90+
.section __DATA,__objc_imageinfo,regular,no_dead_strip
91+
L_OBJC_IMAGE_INFO:
92+
.long 0
93+
.long 80
94+
7995
//--- swift_4.S
8096
.section __TEXT,__text,regular,pure_instructions
8197
.globl _swift4

compiler-rt/test/orc/TestCases/Darwin/x86-64/objc-imageinfo.S

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727

2828
// Check error conditions.
2929

30-
// RUN: not %llvm_jitlink %t/main.o %t/objc_old.o %t/objc_new.o 2>&1 | FileCheck %s -check-prefix=CATEGORY
31-
// CATEGORY: ObjC category class property support in {{.*}} does not match first registered flags
32-
3330
// RUN: not %llvm_jitlink %t/main.o %t/swift_4.o %t/swift_5.o 2>&1 | FileCheck %s -check-prefix=SWIFT_ABI
3431
// SWIFT_ABI: Swift ABI version in {{.*}} does not match first registered flags
3532

@@ -47,6 +44,14 @@
4744
// RUN: %llvm_jitlink -debug-only=orc %t/main.o %t/swift_59.o %t/swift_5.o %t/objc_new.o 2>&1 | FileCheck %s -check-prefix=SWIFT_MIX3
4845
// SWIFT_MIX3: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x5000740
4946

47+
// Disable categories.
48+
// RUN: %llvm_jitlink -debug-only=orc %t/main.o %t/objc_old.o %t/objc_new.o 2>&1 | FileCheck %s -check-prefix=SWIFT_MIX4
49+
// SWIFT_MIX4: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x0000
50+
51+
// Disable signed class_ro.
52+
// RUN: %llvm_jitlink -debug-only=orc %t/main.o %t/objc_new.o %t/objc_new_signed_ro.o 2>&1 | FileCheck %s -check-prefix=SWIFT_MIX5
53+
// SWIFT_MIX5: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x0040
54+
5055
//--- main.S
5156
.section __TEXT,__text,regular,pure_instructions
5257
.globl _main
@@ -76,6 +81,17 @@ L_OBJC_IMAGE_INFO:
7681
.long 0
7782
.long 64
7883

84+
//--- objc_new_signed_ro.S
85+
.section __TEXT,__text,regular,pure_instructions
86+
.globl _objc3
87+
_objc3:
88+
ret
89+
90+
.section __DATA,__objc_imageinfo,regular,no_dead_strip
91+
L_OBJC_IMAGE_INFO:
92+
.long 0
93+
.long 80
94+
7995
//--- swift_4.S
8096
.section __TEXT,__text,regular,pure_instructions
8197
.globl _swift4

llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,12 +1134,16 @@ Error MachOPlatform::MachOPlatformPlugin::mergeImageInfoFlags(
11341134
" does not match first registered flags",
11351135
inconvertibleErrorCode());
11361136

1137-
if (Old.HasCategoryClassProperties != New.HasCategoryClassProperties)
1137+
// HasCategoryClassProperties and HasSignedObjCClassROs can be disabled before
1138+
// they are registered, if necessary, but once they are in use must be
1139+
// supported by subsequent objects.
1140+
if (Info.Finalized && Old.HasCategoryClassProperties &&
1141+
!New.HasCategoryClassProperties)
11381142
return make_error<StringError>("ObjC category class property support in " +
11391143
G.getName() +
11401144
" does not match first registered flags",
11411145
inconvertibleErrorCode());
1142-
if (Old.HasSignedObjCClassROs != New.HasSignedObjCClassROs)
1146+
if (Info.Finalized && Old.HasSignedObjCClassROs && !New.HasSignedObjCClassROs)
11431147
return make_error<StringError>("ObjC class_ro_t pointer signing in " +
11441148
G.getName() +
11451149
" does not match first registered flags",
@@ -1158,6 +1162,12 @@ Error MachOPlatform::MachOPlatformPlugin::mergeImageInfoFlags(
11581162
// Add a Swift ABI version if it was pure objc before.
11591163
if (!New.SwiftABIVersion)
11601164
New.SwiftABIVersion = Old.SwiftABIVersion;
1165+
// Disable class properties if any object does not support it.
1166+
if (Old.HasCategoryClassProperties != New.HasCategoryClassProperties)
1167+
New.HasCategoryClassProperties = false;
1168+
// Disable signed class ro data if any object does not support it.
1169+
if (Old.HasSignedObjCClassROs != New.HasSignedObjCClassROs)
1170+
New.HasSignedObjCClassROs = false;
11611171

11621172
LLVM_DEBUG({
11631173
dbgs() << "MachOPlatform: Merging __objc_imageinfo flags for "

0 commit comments

Comments
 (0)