[compiler-rt] [llvm] [ORC] Loosen __objc_imageinfo flag merging to match ld (PR #91767)
Ben Langmuir via llvm-commits
llvm-commits at lists.llvm.org
Fri May 10 09:48:43 PDT 2024
https://github.com/benlangmuir created https://github.com/llvm/llvm-project/pull/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
>From a7413395c91ae335eeebc16a4c624d18d61bfae0 Mon Sep 17 00:00:00 2001
From: Ben Langmuir <blangmuir at apple.com>
Date: Thu, 9 May 2024 16:09:00 -0700
Subject: [PATCH] [ORC] Loosen __objc_imageinfo flag merging to match ld
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
---
.../TestCases/Darwin/arm64/objc-imageinfo.S | 22 ++++++++++++++++---
.../TestCases/Darwin/x86-64/objc-imageinfo.S | 22 ++++++++++++++++---
.../lib/ExecutionEngine/Orc/MachOPlatform.cpp | 14 ++++++++++--
3 files changed, 50 insertions(+), 8 deletions(-)
diff --git a/compiler-rt/test/orc/TestCases/Darwin/arm64/objc-imageinfo.S b/compiler-rt/test/orc/TestCases/Darwin/arm64/objc-imageinfo.S
index d58943f9681da..2ee7d3f5eac17 100644
--- a/compiler-rt/test/orc/TestCases/Darwin/arm64/objc-imageinfo.S
+++ b/compiler-rt/test/orc/TestCases/Darwin/arm64/objc-imageinfo.S
@@ -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
@@ -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
@@ -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
diff --git a/compiler-rt/test/orc/TestCases/Darwin/x86-64/objc-imageinfo.S b/compiler-rt/test/orc/TestCases/Darwin/x86-64/objc-imageinfo.S
index 90b5c3a38eebe..d4e9b4b05fb88 100644
--- a/compiler-rt/test/orc/TestCases/Darwin/x86-64/objc-imageinfo.S
+++ b/compiler-rt/test/orc/TestCases/Darwin/x86-64/objc-imageinfo.S
@@ -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
@@ -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
@@ -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
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index 1fa8a1274911c..2b397b2d48e7d 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -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",
@@ -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 "
More information about the llvm-commits
mailing list