uint64_t NumPtrs = 0;
};
+ using RawPointerSectionList = std::vector<SectionExtent>;
+
void setObjCImageInfoAddr(JITTargetAddress ObjCImageInfoAddr) {
this->ObjCImageInfoAddr = ObjCImageInfoAddr;
}
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;
<< "\"\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();
}
return Error::success();
}
-bool objcRegistrationEnabled() {
+bool objCRegistrationEnabled() {
return ObjCRegistrationAPIState == ObjCRegistrationAPI::Initialized;
}
}
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) {
}
Error MachOJITDylibInitializers::registerObjCClasses() const {
- assert(objcRegistrationEnabled() && "ObjC registration not enabled.");
+ assert(objCRegistrationEnabled() && "ObjC registration not enabled.");
struct ObjCClassCompiled {
void *Metaclass;