]> granicus.if.org Git - llvm/commitdiff
[ORC] Guarantee unique JITDylib names in lli, add usage notes to createJITDylib.
authorLang Hames <lhames@gmail.com>
Tue, 21 May 2019 22:07:53 +0000 (22:07 +0000)
committerLang Hames <lhames@gmail.com>
Tue, 21 May 2019 22:07:53 +0000 (22:07 +0000)
JITDylibs should have unique names. This patch adds code to lli to respect this
invariant (by refering to the exist JITDylib if a -jd <name> option is specified
more than once). It also adds usage notes to the doxygen comment for
createJITDylib method in ExecutionSession and LLJIT.

http://llvm.org/PR41937

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361322 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/Orc/Core.h
include/llvm/ExecutionEngine/Orc/LLJIT.h
tools/lli/lli.cpp

index 58bd957500c6e022763af59c0cf257874619e705..d39271ada008375e2f57358a610911b733289eec 100644 (file)
@@ -681,6 +681,10 @@ private:
 
   void emit(const SymbolFlagsMap &Emitted);
 
+  // Removes the given symbols from the symbol table, returning the set of
+  // pending queries.
+  AsynchronousSymbolQuery removeSymbols(const SymbolNameSet &Symbols);
+
   void notifyFailed(const SymbolNameSet &FailedSymbols);
 
   ExecutionSession &ES;
@@ -731,6 +735,10 @@ public:
   JITDylib *getJITDylibByName(StringRef Name);
 
   /// Add a new JITDylib to this ExecutionSession.
+  ///
+  /// The JITDylib Name is required to be unique. Clients should verify that
+  /// names are not being re-used (e.g. by calling getJITDylibByName) if names
+  /// are based on user input.
   JITDylib &createJITDylib(std::string Name,
                            bool AddToMainDylibSearchOrder = true);
 
index 3104de5e4633bf1999cbedefc12fa68fc7197248..b54c7d882e2476da5df2cf55cbe91b2d153e52e5 100644 (file)
@@ -51,7 +51,18 @@ public:
   /// Returns a reference to the JITDylib representing the JIT'd main program.
   JITDylib &getMainJITDylib() { return Main; }
 
+  /// Returns the JITDylib with the given name, or nullptr if no JITDylib with
+  /// that name exists.
+  JITDylib *getJITDylibByName(StringRef Name) {
+    return ES->getJITDylibByName(Name);
+  }
+
   /// Create a new JITDylib with the given name and return a reference to it.
+  ///
+  /// JITDylib names must be unique. If the given name is derived from user
+  /// input or elsewhere in the environment then the client should check
+  /// (e.g. by calling getJITDylibByName) that the given name is not already in
+  /// use.
   JITDylib &createJITDylib(std::string Name) {
     return ES->createJITDylib(std::move(Name));
   }
index a44b7437f700d8fda477d64b6b6e65fdaf26d2ac..fb6cf6ff9159374aa2bef08885098b560a63f33c 100644 (file)
@@ -821,8 +821,10 @@ int runOrcLazyJIT(const char *ProgName) {
     IdxToDylib[0] = &J->getMainJITDylib();
     for (auto JDItr = JITDylibs.begin(), JDEnd = JITDylibs.end();
          JDItr != JDEnd; ++JDItr) {
-      IdxToDylib[JITDylibs.getPosition(JDItr - JITDylibs.begin())] =
-          &J->createJITDylib(*JDItr);
+      orc::JITDylib *JD = J->getJITDylibByName(*JDItr);
+      if (!JD)
+        JD = &J->createJITDylib(*JDItr);
+      IdxToDylib[JITDylibs.getPosition(JDItr - JITDylibs.begin())] = JD;
     }
 
     for (auto EMItr = ExtraModules.begin(), EMEnd = ExtraModules.end();