Skip to content

[ORC] Loosen __objc_imageinfo flag merging to match ld #91767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions compiler-rt/test/orc/TestCases/Darwin/arm64/objc-imageinfo.S
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@

// Check error conditions.

// RUN: not %llvm_jitlink %t/main.o %t/objc_old.o %t/objc_new.o 2>&1 | FileCheck %s -check-prefix=CATEGORY
// CATEGORY: ObjC category class property support in {{.*}} does not match first registered flags

// RUN: not %llvm_jitlink %t/main.o %t/swift_4.o %t/swift_5.o 2>&1 | FileCheck %s -check-prefix=SWIFT_ABI
// SWIFT_ABI: Swift ABI version in {{.*}} does not match first registered flags

Expand All @@ -47,6 +44,14 @@
// 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
// SWIFT_MIX3: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x5000740

// Disable categories.
// 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
// SWIFT_MIX4: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x0000

// Disable signed class_ro.
// 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
// SWIFT_MIX5: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x0040

//--- main.S
.section __TEXT,__text,regular,pure_instructions
.globl _main
Expand Down Expand Up @@ -76,6 +81,17 @@ L_OBJC_IMAGE_INFO:
.long 0
.long 64

//--- objc_new_signed_ro.S
.section __TEXT,__text,regular,pure_instructions
.globl _objc3
_objc3:
ret

.section __DATA,__objc_imageinfo,regular,no_dead_strip
L_OBJC_IMAGE_INFO:
.long 0
.long 80

//--- swift_4.S
.section __TEXT,__text,regular,pure_instructions
.globl _swift4
Expand Down
22 changes: 19 additions & 3 deletions compiler-rt/test/orc/TestCases/Darwin/x86-64/objc-imageinfo.S
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@

// Check error conditions.

// RUN: not %llvm_jitlink %t/main.o %t/objc_old.o %t/objc_new.o 2>&1 | FileCheck %s -check-prefix=CATEGORY
// CATEGORY: ObjC category class property support in {{.*}} does not match first registered flags

// RUN: not %llvm_jitlink %t/main.o %t/swift_4.o %t/swift_5.o 2>&1 | FileCheck %s -check-prefix=SWIFT_ABI
// SWIFT_ABI: Swift ABI version in {{.*}} does not match first registered flags

Expand All @@ -47,6 +44,14 @@
// 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
// SWIFT_MIX3: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x5000740

// Disable categories.
// 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
// SWIFT_MIX4: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x0000

// Disable signed class_ro.
// 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
// SWIFT_MIX5: MachOPlatform: Merging __objc_imageinfo flags for main {{.*}} -> 0x0040

//--- main.S
.section __TEXT,__text,regular,pure_instructions
.globl _main
Expand Down Expand Up @@ -76,6 +81,17 @@ L_OBJC_IMAGE_INFO:
.long 0
.long 64

//--- objc_new_signed_ro.S
.section __TEXT,__text,regular,pure_instructions
.globl _objc3
_objc3:
ret

.section __DATA,__objc_imageinfo,regular,no_dead_strip
L_OBJC_IMAGE_INFO:
.long 0
.long 80

//--- swift_4.S
.section __TEXT,__text,regular,pure_instructions
.globl _swift4
Expand Down
14 changes: 12 additions & 2 deletions llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,12 +1134,16 @@ Error MachOPlatform::MachOPlatformPlugin::mergeImageInfoFlags(
" does not match first registered flags",
inconvertibleErrorCode());

if (Old.HasCategoryClassProperties != New.HasCategoryClassProperties)
// HasCategoryClassProperties and HasSignedObjCClassROs can be disabled before
// they are registered, if necessary, but once they are in use must be
// supported by subsequent objects.
if (Info.Finalized && Old.HasCategoryClassProperties &&
!New.HasCategoryClassProperties)
return make_error<StringError>("ObjC category class property support in " +
G.getName() +
" does not match first registered flags",
inconvertibleErrorCode());
if (Old.HasSignedObjCClassROs != New.HasSignedObjCClassROs)
if (Info.Finalized && Old.HasSignedObjCClassROs && !New.HasSignedObjCClassROs)
return make_error<StringError>("ObjC class_ro_t pointer signing in " +
G.getName() +
" does not match first registered flags",
Expand All @@ -1158,6 +1162,12 @@ Error MachOPlatform::MachOPlatformPlugin::mergeImageInfoFlags(
// Add a Swift ABI version if it was pure objc before.
if (!New.SwiftABIVersion)
New.SwiftABIVersion = Old.SwiftABIVersion;
// Disable class properties if any object does not support it.
if (Old.HasCategoryClassProperties != New.HasCategoryClassProperties)
New.HasCategoryClassProperties = false;
// Disable signed class ro data if any object does not support it.
if (Old.HasSignedObjCClassROs != New.HasSignedObjCClassROs)
New.HasSignedObjCClassROs = false;

LLVM_DEBUG({
dbgs() << "MachOPlatform: Merging __objc_imageinfo flags for "
Expand Down