[llvm] 81cb43f - [ORC][MachOPlatform] Don't add InitSectionSymbols for __objc_imageinfo.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Fri May 5 00:52:40 PDT 2023
Author: Lang Hames
Date: 2023-05-05T00:52:03-07:00
New Revision: 81cb43f44d353196718f745956769db20c2fde99
URL: https://github.com/llvm/llvm-project/commit/81cb43f44d353196718f745956769db20c2fde99
DIFF: https://github.com/llvm/llvm-project/commit/81cb43f44d353196718f745956769db20c2fde99.diff
LOG: [ORC][MachOPlatform] Don't add InitSectionSymbols for __objc_imageinfo.
The __objc_imageinfo section may be deleted (leaving dangling references to any
symbols that it contains), and shouldn't have any dependencies anyway. This
patch verifies that the section has no dependencies and then skips the section.
rdar://108469243
Added:
compiler-rt/test/orc/TestCases/Darwin/arm64/Inputs/objc-Foo-foo-class-method.S
compiler-rt/test/orc/TestCases/Darwin/arm64/objc-cross-file-method-call.S
Modified:
llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
Removed:
################################################################################
diff --git a/compiler-rt/test/orc/TestCases/Darwin/arm64/Inputs/objc-Foo-foo-class-method.S b/compiler-rt/test/orc/TestCases/Darwin/arm64/Inputs/objc-Foo-foo-class-method.S
new file mode 100644
index 0000000000000..12a1f359eb5ae
--- /dev/null
+++ b/compiler-rt/test/orc/TestCases/Darwin/arm64/Inputs/objc-Foo-foo-class-method.S
@@ -0,0 +1,88 @@
+ .section __TEXT,__text,regular,pure_instructions
+ .build_version macos, 14, 0 sdk_version 14, 0
+ .p2align 2
+"+[Foo foo]":
+ mov w0, wzr
+ ret
+
+ .section __TEXT,__objc_classname,cstring_literals
+l_OBJC_CLASS_NAME_:
+ .asciz "Foo"
+
+ .section __TEXT,__objc_methname,cstring_literals
+l_OBJC_METH_VAR_NAME_:
+ .asciz "foo"
+
+ .section __TEXT,__objc_methtype,cstring_literals
+l_OBJC_METH_VAR_TYPE_:
+ .asciz "i16 at 0:8"
+
+ .section __DATA,__objc_const
+ .p2align 3
+__OBJC_$_CLASS_METHODS_Foo:
+ .long 24
+ .long 1
+ .quad l_OBJC_METH_VAR_NAME_
+ .quad l_OBJC_METH_VAR_TYPE_
+ .quad "+[Foo foo]"
+
+ .p2align 3
+__OBJC_METACLASS_RO_$_Foo:
+ .long 1
+ .long 40
+ .long 40
+ .space 4
+ .quad 0
+ .quad l_OBJC_CLASS_NAME_
+ .quad __OBJC_$_CLASS_METHODS_Foo
+ .quad 0
+ .quad 0
+ .quad 0
+ .quad 0
+
+ .section __DATA,__objc_data
+ .globl _OBJC_METACLASS_$_Foo
+ .p2align 3
+_OBJC_METACLASS_$_Foo:
+ .quad _OBJC_METACLASS_$_NSObject
+ .quad _OBJC_METACLASS_$_NSObject
+ .quad __objc_empty_cache
+ .quad 0
+ .quad __OBJC_METACLASS_RO_$_Foo
+
+ .section __DATA,__objc_const
+ .p2align 3
+__OBJC_CLASS_RO_$_Foo:
+ .long 0
+ .long 8
+ .long 8
+ .space 4
+ .quad 0
+ .quad l_OBJC_CLASS_NAME_
+ .quad 0
+ .quad 0
+ .quad 0
+ .quad 0
+ .quad 0
+
+ .section __DATA,__objc_data
+ .globl _OBJC_CLASS_$_Foo
+ .p2align 3
+_OBJC_CLASS_$_Foo:
+ .quad _OBJC_METACLASS_$_Foo
+ .quad _OBJC_CLASS_$_NSObject
+ .quad __objc_empty_cache
+ .quad 0
+ .quad __OBJC_CLASS_RO_$_Foo
+
+ .section __DATA,__objc_classlist,regular,no_dead_strip
+ .p2align 3
+l_OBJC_LABEL_CLASS_$:
+ .quad _OBJC_CLASS_$_Foo
+
+ .section __DATA,__objc_imageinfo,regular,no_dead_strip
+L_OBJC_IMAGE_INFO:
+ .long 0
+ .long 64
+
+.subsections_via_symbols
diff --git a/compiler-rt/test/orc/TestCases/Darwin/arm64/objc-cross-file-method-call.S b/compiler-rt/test/orc/TestCases/Darwin/arm64/objc-cross-file-method-call.S
new file mode 100644
index 0000000000000..0d0d2debd4679
--- /dev/null
+++ b/compiler-rt/test/orc/TestCases/Darwin/arm64/objc-cross-file-method-call.S
@@ -0,0 +1,37 @@
+// Test that calls to Objective-C methods in other files work.
+//
+// RUN: %clang -c -o %t.o %s
+// RUN: %clang -c -o %t.aux.o %S/Inputs/objc-Foo-foo-class-method.S
+// RUN: %llvm_jitlink -preload libobjc.A.dylib %t.o %t.aux.o
+
+ .section __TEXT,__text,regular,pure_instructions
+ .build_version macos, 14, 0 sdk_version 14, 0
+ .globl _main
+ .p2align 2
+_main:
+ adrp x8, _OBJC_CLASSLIST_REFERENCES_$_ at PAGE
+ ldr x0, [x8, _OBJC_CLASSLIST_REFERENCES_$_ at PAGEOFF]
+ adrp x8, _OBJC_SELECTOR_REFERENCES_ at PAGE
+ ldr x1, [x8, _OBJC_SELECTOR_REFERENCES_ at PAGEOFF]
+ b _objc_msgSend
+
+ .section __DATA,__objc_classrefs,regular,no_dead_strip
+ .p2align 3, 0x0
+_OBJC_CLASSLIST_REFERENCES_$_:
+ .quad _OBJC_CLASS_$_Foo
+
+ .section __TEXT,__objc_methname,cstring_literals
+l_OBJC_METH_VAR_NAME_:
+ .asciz "foo"
+
+ .section __DATA,__objc_selrefs,literal_pointers,no_dead_strip
+ .p2align 3, 0x0
+_OBJC_SELECTOR_REFERENCES_:
+ .quad l_OBJC_METH_VAR_NAME_
+
+ .section __DATA,__objc_imageinfo,regular,no_dead_strip
+L_OBJC_IMAGE_INFO:
+ .long 0
+ .long 64
+
+.subsections_via_symbols
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index c6eb12012a1e1..23a992da663df 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -908,7 +908,8 @@ Error MachOPlatform::MachOPlatformPlugin::preserveImportantSections(
// address in the first graph that it appears in, then verify and discard it
// in all subsequent graphs. In this pass we preserve unconditionally -- we'll
// manually throw it away in the processObjCImageInfo pass.
- if (auto *ObjCImageInfoSec = G.findSectionByName("__DATA,__objc_imageinfo")) {
+ if (auto *ObjCImageInfoSec =
+ G.findSectionByName(MachOObjCImageInfoSectionName)) {
if (ObjCImageInfoSec->blocks_size() != 1)
return make_error<StringError>(
"In " + G.getName() +
@@ -916,6 +917,13 @@ Error MachOPlatform::MachOPlatformPlugin::preserveImportantSections(
inconvertibleErrorCode());
G.addAnonymousSymbol(**ObjCImageInfoSec->blocks().begin(), 0, 0, false,
true);
+
+ for (auto *B : ObjCImageInfoSec->blocks())
+ if (!B->edges_empty())
+ return make_error<StringError>("In " + G.getName() + ", " +
+ MachOObjCImageInfoSectionName +
+ " contains references to symbols",
+ inconvertibleErrorCode());
}
// Init sections are important: We need to preserve them and so that their
@@ -923,6 +931,11 @@ Error MachOPlatform::MachOPlatformPlugin::preserveImportantSections(
// registerObjectPlatformSections.
JITLinkSymbolSet InitSectionSymbols;
for (auto &InitSectionName : MachOInitSectionNames) {
+ // Skip ObjCImageInfo -- this shouldn't have any dependencies, and we may
+ // remove it later.
+ if (InitSectionName == MachOObjCImageInfoSectionName)
+ continue;
+
// Skip non-init sections.
auto *InitSection = G.findSectionByName(InitSectionName);
if (!InitSection)
More information about the llvm-commits
mailing list