[llvm] 4b15dec - [ORC] Remove hard dependency on libobjc when using MachOPlatform with LLJIT.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 4 21:57:48 PST 2020
Author: Lang Hames
Date: 2020-03-04T21:49:28-08:00
New Revision: 4b15decb609ac264cbfc75bc11a99ed0428301f2
URL: https://github.com/llvm/llvm-project/commit/4b15decb609ac264cbfc75bc11a99ed0428301f2
DIFF: https://github.com/llvm/llvm-project/commit/4b15decb609ac264cbfc75bc11a99ed0428301f2.diff
LOG: [ORC] Remove hard dependency on libobjc when using MachOPlatform with LLJIT.
The LLJIT::MachOPlatformSupport class used to unconditionally attempt to
register __objc_selrefs and __objc_classlist sections. If libobjc had not
been loaded this resulted in an assertion, even if no objc sections were
actually present. This patch replaces this unconditional registration with
a check that no objce sections are present if libobjc has not been loaded.
This will allow clients to use MachOPlatform with LLJIT without requiring
libobjc for non-objc code.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
index 0d07f53dd3fb..f869ebdfbe4e 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
@@ -39,6 +39,8 @@ class MachOJITDylibInitializers {
uint64_t NumPtrs = 0;
};
+ using RawPointerSectionList = std::vector<SectionExtent>;
+
void setObjCImageInfoAddr(JITTargetAddress ObjCImageInfoAddr) {
this->ObjCImageInfoAddr = ObjCImageInfoAddr;
}
@@ -47,20 +49,31 @@ class MachOJITDylibInitializers {
ModInitSections.push_back(std::move(ModInit));
}
+ const RawPointerSectionList &getModInitsSections() const {
+ return ModInitSections;
+ }
+
void addObjCSelRefsSection(SectionExtent ObjCSelRefs) {
ObjCSelRefsSections.push_back(std::move(ObjCSelRefs));
}
+ const RawPointerSectionList &getObjCSelRefsSections() const {
+ return ObjCSelRefsSections;
+ }
+
void addObjCClassListSection(SectionExtent ObjCClassList) {
ObjCClassListSections.push_back(std::move(ObjCClassList));
}
+ const RawPointerSectionList &getObjCClassListSections() const {
+ return ObjCClassListSections;
+ }
+
void runModInits() const;
void registerObjCSelectors() const;
Error registerObjCClasses() const;
private:
- using RawPointerSectionList = std::vector<SectionExtent>;
JITTargetAddress ObjCImageInfoAddr;
RawPointerSectionList ModInitSections;
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 2ff9e78f82e1..a847f0ef9421 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -555,18 +555,34 @@ class MachOPlatformSupport : public LLJIT::PlatformSupport {
<< "\"\n";
});
- if (auto InitSeq = MP.getInitializerSequence(JD)) {
+ auto InitSeq = MP.getInitializerSequence(JD);
+ if (!InitSeq)
+ return InitSeq.takeError();
+
+ // If ObjC is not enabled but there are JIT'd ObjC inits then return
+ // an error.
+ if (!objCRegistrationEnabled())
for (auto &KV : *InitSeq) {
+ if (!KV.second.getObjCSelRefsSections().empty() ||
+ !KV.second.getObjCClassListSections().empty())
+ return make_error<StringError>("JITDylib " + KV.first->getName() +
+ " contains objc metadata but objc"
+ " is not enabled",
+ inconvertibleErrorCode());
+ }
+
+ // Run the initializers.
+ for (auto &KV : *InitSeq) {
+ if (objCRegistrationEnabled()) {
KV.second.registerObjCSelectors();
if (auto Err = KV.second.registerObjCClasses()) {
// FIXME: Roll back registrations on error?
return Err;
}
}
- for (auto &KV : *InitSeq)
- KV.second.runModInits();
- } else
- return InitSeq.takeError();
+ KV.second.runModInits();
+ }
+
return Error::success();
}
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index b883a81e5d3f..9a836677ef15 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -81,7 +81,7 @@ Error enableObjCRegistration(const char *PathToLibObjC) {
return Error::success();
}
-bool objcRegistrationEnabled() {
+bool objCRegistrationEnabled() {
return ObjCRegistrationAPIState == ObjCRegistrationAPI::Initialized;
}
@@ -98,7 +98,7 @@ void MachOJITDylibInitializers::runModInits() const {
}
void MachOJITDylibInitializers::registerObjCSelectors() const {
- assert(objcRegistrationEnabled() && "ObjC registration not enabled.");
+ assert(objCRegistrationEnabled() && "ObjC registration not enabled.");
for (const auto &ObjCSelRefs : ObjCSelRefsSections) {
for (uint64_t I = 0; I != ObjCSelRefs.NumPtrs; ++I) {
@@ -112,7 +112,7 @@ void MachOJITDylibInitializers::registerObjCSelectors() const {
}
Error MachOJITDylibInitializers::registerObjCClasses() const {
- assert(objcRegistrationEnabled() && "ObjC registration not enabled.");
+ assert(objCRegistrationEnabled() && "ObjC registration not enabled.");
struct ObjCClassCompiled {
void *Metaclass;
More information about the llvm-commits
mailing list