[llvm] 89aa11e - [ORC] Remove LLVM-side MachO Platform runtime support.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 16 21:32:32 PDT 2021
Author: Lang Hames
Date: 2021-07-17T14:25:31+10:00
New Revision: 89aa11ed2817697abcf3416651d34cd85b5bf5cf
URL: https://github.com/llvm/llvm-project/commit/89aa11ed2817697abcf3416651d34cd85b5bf5cf
DIFF: https://github.com/llvm/llvm-project/commit/89aa11ed2817697abcf3416651d34cd85b5bf5cf.diff
LOG: [ORC] Remove LLVM-side MachO Platform runtime support.
Support for this functionality is moving to the ORC runtime.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
llvm/tools/lli/lli.cpp
Removed:
llvm/test/ExecutionEngine/OrcLazy/objc-minimal.ll
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index 50a2d95624c3c..cc23147aac388 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -442,20 +442,6 @@ class LLLazyJITBuilder
/// should be preferred where available.
void setUpGenericLLVMIRPlatform(LLJIT &J);
-/// Configure the LLJIT instance to use MachOPlatform support.
-///
-/// Warning: MachOPlatform *requires* that LLJIT be configured to use
-/// ObjectLinkingLayer (default on platforms supported by JITLink). If
-/// MachOPlatform is used with RTDyldObjectLinkingLayer it will result in
-/// undefined behavior).
-///
-/// MachOPlatform installs an ObjectLinkingLayer plugin to scrape initializers
-/// from the __mod_inits section. It also provides interposes for the dlfcn
-/// functions (dlopen, dlclose, dlsym, dlerror) that work for JITDylibs as
-/// well as regular libraries (JITDylibs will be preferenced, so make sure
-/// your JITDylib names do not shadow any real library paths).
-Error setUpMachOPlatform(LLJIT &J);
-
/// Configure the LLJIT instance to disable platform support explicitly. This is
/// useful in two cases: for platforms that don't have such requirements and for
/// platforms, that we have no explicit support yet and that don't work well
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
index e708604a19e10..10d0f90510c91 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOPlatform.h
@@ -26,9 +26,6 @@
namespace llvm {
namespace orc {
-/// Enable registration of JIT'd ObjC classes and selectors.
-Error enableObjCRegistration(const char *PathToLibObjC);
-bool objCRegistrationEnabled();
class MachOJITDylibInitializers {
public:
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 08fd86b7979b1..2d1f394a5fb97 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -502,397 +502,6 @@ GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
return std::move(TSM);
}
-class MachOPlatformSupport : public LLJIT::PlatformSupport {
-public:
- using DLOpenType = void *(*)(const char *Name, int Mode);
- using DLCloseType = int (*)(void *Handle);
- using DLSymType = void *(*)(void *Handle, const char *Name);
- using DLErrorType = const char *(*)();
-
- struct DlFcnValues {
- Optional<void *> RTLDDefault;
- DLOpenType dlopen = nullptr;
- DLCloseType dlclose = nullptr;
- DLSymType dlsym = nullptr;
- DLErrorType dlerror = nullptr;
- };
-
- static Expected<std::unique_ptr<MachOPlatformSupport>>
- Create(LLJIT &J, JITDylib &PlatformJITDylib) {
-
- // Make process symbols visible.
- {
- std::string ErrMsg;
- auto Lib = sys::DynamicLibrary::getPermanentLibrary(nullptr, &ErrMsg);
- if (!Lib.isValid())
- return make_error<StringError>(std::move(ErrMsg),
- inconvertibleErrorCode());
- }
-
- DlFcnValues DlFcn;
-
- // Add support for RTLDDefault on known platforms.
-#ifdef __APPLE__
- DlFcn.RTLDDefault = reinterpret_cast<void *>(-2);
-#endif // __APPLE__
-
- if (auto Err = hookUpFunction(DlFcn.dlopen, "dlopen"))
- return std::move(Err);
- if (auto Err = hookUpFunction(DlFcn.dlclose, "dlclose"))
- return std::move(Err);
- if (auto Err = hookUpFunction(DlFcn.dlsym, "dlsym"))
- return std::move(Err);
- if (auto Err = hookUpFunction(DlFcn.dlerror, "dlerror"))
- return std::move(Err);
-
- std::unique_ptr<MachOPlatformSupport> MP(
- new MachOPlatformSupport(J, PlatformJITDylib, DlFcn));
- return std::move(MP);
- }
-
- Error initialize(JITDylib &JD) override {
- LLVM_DEBUG({
- dbgs() << "MachOPlatformSupport initializing \"" << JD.getName()
- << "\"\n";
- });
-
- 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;
- }
- }
- KV.second.runModInits();
- }
-
- return Error::success();
- }
-
- Error deinitialize(JITDylib &JD) override {
- auto &ES = J.getExecutionSession();
- if (auto DeinitSeq = MP.getDeinitializerSequence(JD)) {
- for (auto &KV : *DeinitSeq) {
- auto DSOHandleName = ES.intern("___dso_handle");
-
- // FIXME: Run DeInits here.
- auto Result = ES.lookup(
- {{KV.first, JITDylibLookupFlags::MatchAllSymbols}},
- SymbolLookupSet(DSOHandleName,
- SymbolLookupFlags::WeaklyReferencedSymbol));
- if (!Result)
- return Result.takeError();
- if (Result->empty())
- continue;
- assert(Result->count(DSOHandleName) &&
- "Result does not contain __dso_handle");
- auto *DSOHandle = jitTargetAddressToPointer<void *>(
- Result->begin()->second.getAddress());
- AtExitMgr.runAtExits(DSOHandle);
- }
- } else
- return DeinitSeq.takeError();
- return Error::success();
- }
-
-private:
- template <typename FunctionPtrTy>
- static Error hookUpFunction(FunctionPtrTy &Fn, const char *Name) {
- if (auto *FnAddr = sys::DynamicLibrary::SearchForAddressOfSymbol(Name)) {
- Fn = reinterpret_cast<FunctionPtrTy>(Fn);
- return Error::success();
- }
-
- return make_error<StringError>((Twine("Can not enable MachO JIT Platform: "
- "missing function: ") +
- Name)
- .str(),
- inconvertibleErrorCode());
- }
-
- MachOPlatformSupport(LLJIT &J, JITDylib &PlatformJITDylib, DlFcnValues DlFcn)
- : J(J), MP(setupPlatform(J)), DlFcn(std::move(DlFcn)) {
-
- SymbolMap HelperSymbols;
-
- // platform and atexit helpers.
- HelperSymbols[J.mangleAndIntern("__lljit.platform_support_instance")] =
- JITEvaluatedSymbol(pointerToJITTargetAddress(this), JITSymbolFlags());
- HelperSymbols[J.mangleAndIntern("__lljit.cxa_atexit_helper")] =
- JITEvaluatedSymbol(pointerToJITTargetAddress(registerAtExitHelper),
- JITSymbolFlags());
- HelperSymbols[J.mangleAndIntern("__lljit.run_atexits_helper")] =
- JITEvaluatedSymbol(pointerToJITTargetAddress(runAtExitsHelper),
- JITSymbolFlags());
-
- // dlfcn helpers.
- HelperSymbols[J.mangleAndIntern("__lljit.dlopen_helper")] =
- JITEvaluatedSymbol(pointerToJITTargetAddress(dlopenHelper),
- JITSymbolFlags());
- HelperSymbols[J.mangleAndIntern("__lljit.dlclose_helper")] =
- JITEvaluatedSymbol(pointerToJITTargetAddress(dlcloseHelper),
- JITSymbolFlags());
- HelperSymbols[J.mangleAndIntern("__lljit.dlsym_helper")] =
- JITEvaluatedSymbol(pointerToJITTargetAddress(dlsymHelper),
- JITSymbolFlags());
- HelperSymbols[J.mangleAndIntern("__lljit.dlerror_helper")] =
- JITEvaluatedSymbol(pointerToJITTargetAddress(dlerrorHelper),
- JITSymbolFlags());
-
- cantFail(
- PlatformJITDylib.define(absoluteSymbols(std::move(HelperSymbols))));
- cantFail(MP.setupJITDylib(J.getMainJITDylib()));
- cantFail(J.addIRModule(PlatformJITDylib, createPlatformRuntimeModule()));
- }
-
- static MachOPlatform &setupPlatform(LLJIT &J) {
- auto Tmp = std::make_unique<MachOPlatform>(
- J.getExecutionSession(),
- static_cast<ObjectLinkingLayer &>(J.getObjLinkingLayer()),
- createStandardSymbolsObject(J));
- auto &MP = *Tmp;
- J.getExecutionSession().setPlatform(std::move(Tmp));
- return MP;
- }
-
- static std::unique_ptr<MemoryBuffer> createStandardSymbolsObject(LLJIT &J) {
- LLVMContext Ctx;
- Module M("__standard_symbols", Ctx);
- M.setDataLayout(J.getDataLayout());
-
- auto *Int64Ty = Type::getInt64Ty(Ctx);
-
- auto *DSOHandle =
- new GlobalVariable(M, Int64Ty, true, GlobalValue::ExternalLinkage,
- ConstantInt::get(Int64Ty, 0), "__dso_handle");
- DSOHandle->setVisibility(GlobalValue::DefaultVisibility);
-
- return cantFail(J.getIRCompileLayer().getCompiler()(M));
- }
-
- ThreadSafeModule createPlatformRuntimeModule() {
- auto Ctx = std::make_unique<LLVMContext>();
- auto M = std::make_unique<Module>("__standard_lib", *Ctx);
- M->setDataLayout(J.getDataLayout());
-
- auto *MachOPlatformSupportTy =
- StructType::create(*Ctx, "lljit.MachOPlatformSupport");
-
- auto *PlatformInstanceDecl = new GlobalVariable(
- *M, MachOPlatformSupportTy, true, GlobalValue::ExternalLinkage, nullptr,
- "__lljit.platform_support_instance");
-
- auto *Int8Ty = Type::getInt8Ty(*Ctx);
- auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
- auto *VoidTy = Type::getVoidTy(*Ctx);
- auto *BytePtrTy = PointerType::getUnqual(Int8Ty);
- auto *AtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
- auto *AtExitCallbackPtrTy = PointerType::getUnqual(AtExitCallbackTy);
-
- addHelperAndWrapper(
- *M, "__cxa_atexit",
- FunctionType::get(IntTy, {AtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
- false),
- GlobalValue::DefaultVisibility, "__lljit.cxa_atexit_helper",
- {PlatformInstanceDecl});
-
- addHelperAndWrapper(*M, "dlopen",
- FunctionType::get(BytePtrTy, {BytePtrTy, IntTy}, false),
- GlobalValue::DefaultVisibility, "__lljit.dlopen_helper",
- {PlatformInstanceDecl});
-
- addHelperAndWrapper(*M, "dlclose",
- FunctionType::get(IntTy, {BytePtrTy}, false),
- GlobalValue::DefaultVisibility,
- "__lljit.dlclose_helper", {PlatformInstanceDecl});
-
- addHelperAndWrapper(
- *M, "dlsym",
- FunctionType::get(BytePtrTy, {BytePtrTy, BytePtrTy}, false),
- GlobalValue::DefaultVisibility, "__lljit.dlsym_helper",
- {PlatformInstanceDecl});
-
- addHelperAndWrapper(*M, "dlerror", FunctionType::get(BytePtrTy, {}, false),
- GlobalValue::DefaultVisibility,
- "__lljit.dlerror_helper", {PlatformInstanceDecl});
-
- return ThreadSafeModule(std::move(M), std::move(Ctx));
- }
-
- static void registerAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
- void *DSOHandle) {
- static_cast<MachOPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
- F, Ctx, DSOHandle);
- }
-
- static void runAtExitsHelper(void *Self, void *DSOHandle) {
- static_cast<MachOPlatformSupport *>(Self)->AtExitMgr.runAtExits(DSOHandle);
- }
-
- void *jit_dlopen(const char *Path, int Mode) {
- JITDylib *JDToOpen = nullptr;
- // FIXME: Do the right thing with Mode flags.
- {
- std::lock_guard<std::mutex> Lock(PlatformSupportMutex);
-
- // Clear any existing error messages.
- dlErrorMsgs.erase(std::this_thread::get_id());
-
- if (auto *JD = J.getExecutionSession().getJITDylibByName(Path)) {
- auto I = JDRefCounts.find(JD);
- if (I != JDRefCounts.end()) {
- ++I->second;
- return JD;
- }
-
- JDRefCounts[JD] = 1;
- JDToOpen = JD;
- }
- }
-
- if (JDToOpen) {
- if (auto Err = initialize(*JDToOpen)) {
- recordError(std::move(Err));
- return 0;
- }
- }
-
- // Fall through to dlopen if no JITDylib found for Path.
- return DlFcn.dlopen(Path, Mode);
- }
-
- static void *dlopenHelper(void *Self, const char *Path, int Mode) {
- return static_cast<MachOPlatformSupport *>(Self)->jit_dlopen(Path, Mode);
- }
-
- int jit_dlclose(void *Handle) {
- JITDylib *JDToClose = nullptr;
-
- {
- std::lock_guard<std::mutex> Lock(PlatformSupportMutex);
-
- // Clear any existing error messages.
- dlErrorMsgs.erase(std::this_thread::get_id());
-
- auto I = JDRefCounts.find(Handle);
- if (I != JDRefCounts.end()) {
- --I->second;
- if (I->second == 0) {
- JDRefCounts.erase(I);
- JDToClose = static_cast<JITDylib *>(Handle);
- } else
- return 0;
- }
- }
-
- if (JDToClose) {
- if (auto Err = deinitialize(*JDToClose)) {
- recordError(std::move(Err));
- return -1;
- }
- return 0;
- }
-
- // Fall through to dlclose if no JITDylib found for Path.
- return DlFcn.dlclose(Handle);
- }
-
- static int dlcloseHelper(void *Self, void *Handle) {
- return static_cast<MachOPlatformSupport *>(Self)->jit_dlclose(Handle);
- }
-
- void *jit_dlsym(void *Handle, const char *Name) {
- JITDylibSearchOrder JITSymSearchOrder;
-
- // FIXME: RTLD_NEXT, RTLD_SELF not supported.
- {
- std::lock_guard<std::mutex> Lock(PlatformSupportMutex);
-
- // Clear any existing error messages.
- dlErrorMsgs.erase(std::this_thread::get_id());
-
- if (JDRefCounts.count(Handle)) {
- JITSymSearchOrder.push_back(
- {static_cast<JITDylib *>(Handle),
- JITDylibLookupFlags::MatchExportedSymbolsOnly});
- } else if (Handle == DlFcn.RTLDDefault) {
- for (auto &KV : JDRefCounts)
- JITSymSearchOrder.push_back(
- {static_cast<JITDylib *>(KV.first),
- JITDylibLookupFlags::MatchExportedSymbolsOnly});
- }
- }
-
- if (!JITSymSearchOrder.empty()) {
- auto MangledName = J.mangleAndIntern(Name);
- SymbolLookupSet Syms(MangledName,
- SymbolLookupFlags::WeaklyReferencedSymbol);
- if (auto Result = J.getExecutionSession().lookup(JITSymSearchOrder, Syms,
- LookupKind::DLSym)) {
- auto I = Result->find(MangledName);
- if (I != Result->end())
- return jitTargetAddressToPointer<void *>(I->second.getAddress());
- } else {
- recordError(Result.takeError());
- return 0;
- }
- }
-
- // Fall through to dlsym.
- return DlFcn.dlsym(Handle, Name);
- }
-
- static void *dlsymHelper(void *Self, void *Handle, const char *Name) {
- return static_cast<MachOPlatformSupport *>(Self)->jit_dlsym(Handle, Name);
- }
-
- const char *jit_dlerror() {
- {
- std::lock_guard<std::mutex> Lock(PlatformSupportMutex);
- auto I = dlErrorMsgs.find(std::this_thread::get_id());
- if (I != dlErrorMsgs.end())
- return I->second->c_str();
- }
- return DlFcn.dlerror();
- }
-
- static const char *dlerrorHelper(void *Self) {
- return static_cast<MachOPlatformSupport *>(Self)->jit_dlerror();
- }
-
- void recordError(Error Err) {
- std::lock_guard<std::mutex> Lock(PlatformSupportMutex);
- dlErrorMsgs[std::this_thread::get_id()] =
- std::make_unique<std::string>(toString(std::move(Err)));
- }
-
- std::mutex PlatformSupportMutex;
- LLJIT &J;
- MachOPlatform &MP;
- DlFcnValues DlFcn;
- ItaniumCXAAtExitSupport AtExitMgr;
- DenseMap<void *, unsigned> JDRefCounts;
- std::map<std::thread::id, std::unique_ptr<std::string>> dlErrorMsgs;
-};
-
/// Inactive Platform Support
///
/// Explicitly disables platform support. JITDylibs are not scanned for special
@@ -1173,15 +782,6 @@ void setUpGenericLLVMIRPlatform(LLJIT &J) {
J.setPlatformSupport(std::make_unique<GenericLLVMIRPlatformSupport>(J));
}
-Error setUpMachOPlatform(LLJIT &J) {
- LLVM_DEBUG({ dbgs() << "Setting up MachOPlatform support for LLJIT\n"; });
- auto MP = MachOPlatformSupport::Create(J, J.getMainJITDylib());
- if (!MP)
- return MP.takeError();
- J.setPlatformSupport(std::move(*MP));
- return Error::success();
-}
-
Error setUpInactivePlatform(LLJIT &J) {
LLVM_DEBUG(
{ dbgs() << "Explicitly deactivated platform support for LLJIT\n"; });
diff --git a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
index dd421f91166f4..0fe4f00a1b6c3 100644
--- a/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/MachOPlatform.cpp
@@ -15,144 +15,9 @@
#define DEBUG_TYPE "orc"
-namespace {
-
-struct objc_class;
-struct objc_image_info;
-struct objc_object;
-struct objc_selector;
-
-using Class = objc_class *;
-using id = objc_object *;
-using SEL = objc_selector *;
-
-using ObjCMsgSendTy = id (*)(id, SEL, ...);
-using ObjCReadClassPairTy = Class (*)(Class, const objc_image_info *);
-using SelRegisterNameTy = SEL (*)(const char *);
-
-enum class ObjCRegistrationAPI { Uninitialized, Unavailable, Initialized };
-
-ObjCRegistrationAPI ObjCRegistrationAPIState =
- ObjCRegistrationAPI::Uninitialized;
-ObjCMsgSendTy objc_msgSend = nullptr;
-ObjCReadClassPairTy objc_readClassPair = nullptr;
-SelRegisterNameTy sel_registerName = nullptr;
-
-} // end anonymous namespace
-
namespace llvm {
namespace orc {
-template <typename FnTy>
-static Error setUpObjCRegAPIFunc(FnTy &Target, sys::DynamicLibrary &LibObjC,
- const char *Name) {
- if (void *Addr = LibObjC.getAddressOfSymbol(Name))
- Target = reinterpret_cast<FnTy>(Addr);
- else
- return make_error<StringError>(
- (Twine("Could not find address for ") + Name).str(),
- inconvertibleErrorCode());
- return Error::success();
-}
-
-Error enableObjCRegistration(const char *PathToLibObjC) {
- // If we've already tried to initialize then just bail out.
- if (ObjCRegistrationAPIState != ObjCRegistrationAPI::Uninitialized)
- return Error::success();
-
- ObjCRegistrationAPIState = ObjCRegistrationAPI::Unavailable;
-
- std::string ErrMsg;
- auto LibObjC =
- sys::DynamicLibrary::getPermanentLibrary(PathToLibObjC, &ErrMsg);
-
- if (!LibObjC.isValid())
- return make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode());
-
- if (auto Err = setUpObjCRegAPIFunc(objc_msgSend, LibObjC, "objc_msgSend"))
- return Err;
- if (auto Err = setUpObjCRegAPIFunc(objc_readClassPair, LibObjC,
- "objc_readClassPair"))
- return Err;
- if (auto Err =
- setUpObjCRegAPIFunc(sel_registerName, LibObjC, "sel_registerName"))
- return Err;
-
- ObjCRegistrationAPIState = ObjCRegistrationAPI::Initialized;
- return Error::success();
-}
-
-bool objCRegistrationEnabled() {
- return ObjCRegistrationAPIState == ObjCRegistrationAPI::Initialized;
-}
-
-void MachOJITDylibInitializers::runModInits() const {
- for (const auto &ModInit : ModInitSections) {
- assert(ModInit.size().getValue() % sizeof(uintptr_t) == 0 &&
- "ModInit section size is not a pointer multiple?");
- for (uintptr_t *InitPtr = jitTargetAddressToPointer<uintptr_t *>(
- ModInit.StartAddress.getValue()),
- *InitEnd = jitTargetAddressToPointer<uintptr_t *>(
- ModInit.EndAddress.getValue());
- InitPtr != InitEnd; ++InitPtr) {
- auto *Initializer = reinterpret_cast<void (*)()>(*InitPtr);
- Initializer();
- }
- }
-}
-
-void MachOJITDylibInitializers::registerObjCSelectors() const {
- assert(objCRegistrationEnabled() && "ObjC registration not enabled.");
-
- for (const auto &ObjCSelRefs : ObjCSelRefsSections) {
- assert(ObjCSelRefs.size().getValue() % sizeof(uintptr_t) == 0 &&
- "ObjCSelRefs section size is not a pointer multiple?");
- for (auto SelEntryAddr = ObjCSelRefs.StartAddress;
- SelEntryAddr != ObjCSelRefs.EndAddress;
- SelEntryAddr += ExecutorAddrDiff(sizeof(uintptr_t))) {
- const auto *SelName =
- *jitTargetAddressToPointer<const char **>(SelEntryAddr.getValue());
- auto Sel = sel_registerName(SelName);
- *jitTargetAddressToPointer<SEL *>(SelEntryAddr.getValue()) = Sel;
- }
- }
-}
-
-Error MachOJITDylibInitializers::registerObjCClasses() const {
- assert(objCRegistrationEnabled() && "ObjC registration not enabled.");
-
- struct ObjCClassCompiled {
- void *Metaclass;
- void *Parent;
- void *Cache1;
- void *Cache2;
- void *Data;
- };
-
- auto *ImageInfo =
- jitTargetAddressToPointer<const objc_image_info *>(ObjCImageInfoAddr);
- auto ClassSelector = sel_registerName("class");
-
- for (const auto &ObjCClassList : ObjCClassListSections) {
- assert(ObjCClassList.size().getValue() % sizeof(uintptr_t) == 0 &&
- "ObjCClassList section size is not a pointer multiple?");
- for (auto ClassPtrAddr = ObjCClassList.StartAddress;
- ClassPtrAddr != ObjCClassList.EndAddress;
- ClassPtrAddr += ExecutorAddrDiff(sizeof(uintptr_t))) {
- auto Cls = *ClassPtrAddr.toPtr<Class *>();
- auto *ClassCompiled = *ClassPtrAddr.toPtr<ObjCClassCompiled **>();
- objc_msgSend(reinterpret_cast<id>(ClassCompiled->Parent), ClassSelector);
- auto Registered = objc_readClassPair(Cls, ImageInfo);
-
- // FIXME: Improve diagnostic by reporting the failed class's name.
- if (Registered != Cls)
- return make_error<StringError>("Unable to register Objective-C class",
- inconvertibleErrorCode());
- }
- }
- return Error::success();
-}
-
MachOPlatform::MachOPlatform(
ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
std::unique_ptr<MemoryBuffer> StandardSymbolsObject)
diff --git a/llvm/test/ExecutionEngine/OrcLazy/objc-minimal.ll b/llvm/test/ExecutionEngine/OrcLazy/objc-minimal.ll
deleted file mode 100644
index 06a1224fdb793..0000000000000
--- a/llvm/test/ExecutionEngine/OrcLazy/objc-minimal.ll
+++ /dev/null
@@ -1,73 +0,0 @@
-; REQUIRES: system-darwin
-; RUN: env ASAN_OPTIONS=detect_leaks=0 lli -jit-kind=orc-lazy %s
-;
-; Sanity check MachO Platform support: Call a no-op method (returning int 0) on
-; an ObjC object. This test checks that we correctly auto-identify this as a
-; MachO target, configure MachOPlatform support, and correctly register the
-; class metadata and method selector with the Objective-C runtime.
-
-source_filename = "objc-minimal.mm"
-target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-apple-macosx10.14.0"
-
-%0 = type opaque
-%struct._objc_cache = type opaque
-%struct._class_t = type { %struct._class_t*, %struct._class_t*, %struct._objc_cache*, i8* (i8*, i8*)**, %struct._class_ro_t* }
-%struct._class_ro_t = type { i32, i32, i32, i8*, i8*, %struct.__method_list_t*, %struct._objc_protocol_list*, %struct._ivar_list_t*, i8*, %struct._prop_list_t* }
-%struct.__method_list_t = type { i32, i32, [0 x %struct._objc_method] }
-%struct._objc_method = type { i8*, i8*, i8* }
-%struct._objc_protocol_list = type { i64, [0 x %struct._protocol_t*] }
-%struct._protocol_t = type { i8*, i8*, %struct._objc_protocol_list*, %struct.__method_list_t*, %struct.__method_list_t*, %struct.__method_list_t*, %struct.__method_list_t*, %struct._prop_list_t*, i32, i32, i8**, i8*, %struct._prop_list_t* }
-%struct._ivar_list_t = type { i32, i32, [0 x %struct._ivar_t] }
-%struct._ivar_t = type { i64*, i8*, i8*, i32, i32 }
-%struct._prop_list_t = type { i32, i32, [0 x %struct._prop_t] }
-%struct._prop_t = type { i8*, i8* }
-
- at _objc_empty_cache = external global %struct._objc_cache
-@"OBJC_METACLASS_$_NSObject" = external global %struct._class_t
- at OBJC_CLASS_NAME_ = private unnamed_addr constant [4 x i8] c"Foo\00", section "__TEXT,__objc_classname,cstring_literals", align 1
-@"\01l_OBJC_METACLASS_RO_$_Foo" = private global %struct._class_ro_t { i32 1, i32 40, i32 40, i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @OBJC_CLASS_NAME_, i32 0, i32 0), %struct.__method_list_t* null, %struct._objc_protocol_list* null, %struct._ivar_list_t* null, i8* null, %struct._prop_list_t* null }, section "__DATA, __objc_const", align 8
-@"OBJC_METACLASS_$_Foo" = global %struct._class_t { %struct._class_t* @"OBJC_METACLASS_$_NSObject", %struct._class_t* @"OBJC_METACLASS_$_NSObject", %struct._objc_cache* @_objc_empty_cache, i8* (i8*, i8*)** null, %struct._class_ro_t* @"\01l_OBJC_METACLASS_RO_$_Foo" }, section "__DATA, __objc_data", align 8
-@"OBJC_CLASS_$_NSObject" = external global %struct._class_t
- at OBJC_METH_VAR_NAME_ = private unnamed_addr constant [4 x i8] c"foo\00", section "__TEXT,__objc_methname,cstring_literals", align 1
- at OBJC_METH_VAR_TYPE_ = private unnamed_addr constant [8 x i8] c"i16 at 0:8\00", section "__TEXT,__objc_methtype,cstring_literals", align 1
-@"\01l_OBJC_$_INSTANCE_METHODS_Foo" = private global { i32, i32, [1 x %struct._objc_method] } { i32 24, i32 1, [1 x %struct._objc_method] [%struct._objc_method { i8* getelementptr inbounds ([4 x i8], [4 x i8]* @OBJC_METH_VAR_NAME_, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @OBJC_METH_VAR_TYPE_, i32 0, i32 0), i8* bitcast (i32 (%0*, i8*)* @"\01-[Foo foo]" to i8*) }] }, section "__DATA, __objc_const", align 8
-@"\01l_OBJC_CLASS_RO_$_Foo" = private global %struct._class_ro_t { i32 0, i32 8, i32 8, i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @OBJC_CLASS_NAME_, i32 0, i32 0), %struct.__method_list_t* bitcast ({ i32, i32, [1 x %struct._objc_method] }* @"\01l_OBJC_$_INSTANCE_METHODS_Foo" to %struct.__method_list_t*), %struct._objc_protocol_list* null, %struct._ivar_list_t* null, i8* null, %struct._prop_list_t* null }, section "__DATA, __objc_const", align 8
-@"OBJC_CLASS_$_Foo" = global %struct._class_t { %struct._class_t* @"OBJC_METACLASS_$_Foo", %struct._class_t* @"OBJC_CLASS_$_NSObject", %struct._objc_cache* @_objc_empty_cache, i8* (i8*, i8*)** null, %struct._class_ro_t* @"\01l_OBJC_CLASS_RO_$_Foo" }, section "__DATA, __objc_data", align 8
-@"OBJC_CLASSLIST_REFERENCES_$_" = private global %struct._class_t* @"OBJC_CLASS_$_Foo", section "__DATA,__objc_classrefs,regular,no_dead_strip", align 8
- at OBJC_METH_VAR_NAME_.1 = private unnamed_addr constant [5 x i8] c"init\00", section "__TEXT,__objc_methname,cstring_literals", align 1
- at OBJC_SELECTOR_REFERENCES_ = private externally_initialized global i8* getelementptr inbounds ([5 x i8], [5 x i8]* @OBJC_METH_VAR_NAME_.1, i64 0, i64 0), section "__DATA,__objc_selrefs,literal_pointers,no_dead_strip", align 8
- at OBJC_SELECTOR_REFERENCES_.2 = private externally_initialized global i8* getelementptr inbounds ([4 x i8], [4 x i8]* @OBJC_METH_VAR_NAME_, i64 0, i64 0), section "__DATA,__objc_selrefs,literal_pointers,no_dead_strip", align 8
-@"OBJC_LABEL_CLASS_$" = private global [1 x i8*] [i8* bitcast (%struct._class_t* @"OBJC_CLASS_$_Foo" to i8*)], section "__DATA,__objc_classlist,regular,no_dead_strip", align 8
- at llvm.compiler.used = appending global [9 x i8*] [i8* bitcast ({ i32, i32, [1 x %struct._objc_method] }* @"\01l_OBJC_$_INSTANCE_METHODS_Foo" to i8*), i8* bitcast (%struct._class_t** @"OBJC_CLASSLIST_REFERENCES_$_" to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @OBJC_CLASS_NAME_, i32 0, i32 0), i8* bitcast ([1 x i8*]* @"OBJC_LABEL_CLASS_$" to i8*), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @OBJC_METH_VAR_NAME_, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @OBJC_METH_VAR_NAME_.1, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @OBJC_METH_VAR_TYPE_, i32 0, i32 0), i8* bitcast (i8** @OBJC_SELECTOR_REFERENCES_ to i8*), i8* bitcast (i8** @OBJC_SELECTOR_REFERENCES_.2 to i8*)], section "llvm.metadata"
-
-; Function Attrs: noinline norecurse nounwind readnone ssp uwtable
-define internal i32 @"\01-[Foo foo]"(%0* nocapture readnone, i8* nocapture readnone) {
- ret i32 0
-}
-
-; Function Attrs: noinline norecurse ssp uwtable
-define i32 @main(i32, i8** nocapture readnone) local_unnamed_addr {
- %3 = load i8*, i8** bitcast (%struct._class_t** @"OBJC_CLASSLIST_REFERENCES_$_" to i8**), align 8
- %4 = tail call i8* @objc_alloc(i8* %3)
- %5 = load i8*, i8** @OBJC_SELECTOR_REFERENCES_, align 8
- %6 = tail call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* (i8*, i8*)*)(i8* %4, i8* %5)
- %7 = load i8*, i8** @OBJC_SELECTOR_REFERENCES_.2, align 8
- %8 = tail call i32 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i32 (i8*, i8*)*)(i8* %6, i8* %7)
- ret i32 %8
-}
-
-declare i8* @objc_alloc(i8*) local_unnamed_addr
-
-; Function Attrs: nonlazybind
-declare i8* @objc_msgSend(i8*, i8*, ...) local_unnamed_addr
-
-!llvm.module.flags = !{!0, !1, !2, !3, !4, !5, !6 }
-
-!0 = !{i32 2, !"SDK Version", [2 x i32] [i32 10, i32 15]}
-!1 = !{i32 1, !"Objective-C Version", i32 2}
-!2 = !{i32 1, !"Objective-C Image Info Version", i32 0}
-!3 = !{i32 1, !"Objective-C Image Info Section", !"__DATA,__objc_imageinfo,regular,no_dead_strip"}
-!4 = !{i32 4, !"Objective-C Garbage Collection", i32 0}
-!5 = !{i32 1, !"Objective-C Class Properties", i32 64}
-!6 = !{i32 1, !"wchar_size", i32 4}
diff --git a/llvm/tools/lli/lli.cpp b/llvm/tools/lli/lli.cpp
index 47fb364212897..50917a92b3be4 100644
--- a/llvm/tools/lli/lli.cpp
+++ b/llvm/tools/lli/lli.cpp
@@ -33,7 +33,6 @@
#include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
#include "llvm/ExecutionEngine/Orc/JITTargetMachineBuilder.h"
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
-#include "llvm/ExecutionEngine/Orc/MachOPlatform.h"
#include "llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h"
#include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h"
#include "llvm/ExecutionEngine/Orc/SymbolStringPool.h"
@@ -228,7 +227,7 @@ namespace {
cl::desc("Do not resolve lli process symbols in JIT'd code"),
cl::init(false));
- enum class LLJITPlatform { Inactive, DetectHost, GenericIR, MachO };
+ enum class LLJITPlatform { Inactive, DetectHost, GenericIR };
cl::opt<LLJITPlatform>
Platform("lljit-platform", cl::desc("Platform to use with LLJIT"),
@@ -237,8 +236,6 @@ namespace {
"Select based on JIT target triple"),
clEnumValN(LLJITPlatform::GenericIR, "GenericIR",
"Use LLJITGenericIRPlatform"),
- clEnumValN(LLJITPlatform::MachO, "MachO",
- "Use LLJITMachOPlatform"),
clEnumValN(LLJITPlatform::Inactive, "Inactive",
"Disable platform support explicitly")),
cl::Hidden);
@@ -913,21 +910,13 @@ int runOrcJIT(const char *ProgName) {
// Set up LLJIT platform.
{
LLJITPlatform P = Platform;
- if (P == LLJITPlatform::DetectHost) {
- if (TT->isOSBinFormatMachO())
- P = LLJITPlatform::MachO;
- else
- P = LLJITPlatform::GenericIR;
- }
+ if (P == LLJITPlatform::DetectHost)
+ P = LLJITPlatform::GenericIR;
switch (P) {
case LLJITPlatform::GenericIR:
// Nothing to do: LLJITBuilder will use this by default.
break;
- case LLJITPlatform::MachO:
- Builder.setPlatformSetUp(orc::setUpMachOPlatform);
- ExitOnErr(orc::enableObjCRegistration("libobjc.dylib"));
- break;
case LLJITPlatform::Inactive:
Builder.setPlatformSetUp(orc::setUpInactivePlatform);
break;
More information about the llvm-commits
mailing list