3838#include < set>
3939#include < sstream>
4040#include < string>
41+ #include < utility>
4142
4243// Stream redirect.
4344#ifdef _WIN32
@@ -3449,40 +3450,50 @@ namespace Cpp {
34493450 }
34503451
34513452 class AutoLoadLibrarySearchGenerator ;
3452- static AutoLoadLibrarySearchGenerator *ALLSG = nullptr ;
3453+
3454+ // Last assigned Autoload SearchGenerator
3455+ // TODO: Test for thread safe.
3456+ static AutoLoadLibrarySearchGenerator *AutoSG = nullptr ;
34533457
34543458 class AutoLoadLibrarySearchGenerator : public llvm ::orc::DefinitionGenerator {
3455- public:
34563459 bool Enabled = false ;
3460+ public:
3461+ bool isEnabled () {
3462+ return Enabled;
3463+ }
3464+
3465+ void setEnabled (bool enabled) {
3466+ Enabled = enabled;
3467+ }
34573468
34583469 // Lazy materialization unit class helper
34593470 class AutoloadLibraryMU : public llvm ::orc::MaterializationUnit {
3460- std::string lib;
3471+ const std::string lib;
34613472 llvm::orc::SymbolNameVector syms;
34623473 public:
3463- AutoloadLibraryMU (const std::string & Library, const llvm::orc::SymbolNameVector &Symbols)
3474+ AutoloadLibraryMU (const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
34643475 : MaterializationUnit({getSymbolFlagsMap (Symbols), nullptr }), lib(Library), syms(Symbols) {}
34653476
3466- StringRef getName () const override {
3477+ [[nodiscard]] StringRef getName () const override {
34673478 return " <Symbols from Autoloaded Library>" ;
34683479 }
34693480
34703481 void materialize (std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3471- if (!ALLSG || !ALLSG-> Enabled ) {
3482+ if (!AutoSG || !AutoSG-> isEnabled () ) {
34723483 R->failMaterialization ();
34733484 return ;
34743485 }
34753486
34763487 LLVM_DEBUG (dbgs () << " Materialize " << lib << " syms=" << syms);
34773488
34783489 auto & I = getInterp ();
3479- auto DLM = I.getDynamicLibraryManager ();
3490+ auto * DLM = I.getDynamicLibraryManager ();
34803491
34813492 llvm::orc::SymbolMap loadedSymbols;
34823493 llvm::orc::SymbolNameSet failedSymbols;
34833494 bool loadedLibrary = false ;
34843495
3485- for (auto symbol : syms) {
3496+ for (const auto & symbol : syms) {
34863497 std::string symbolStr = (*symbol).str ();
34873498 std::string nameForDlsym = DemangleNameForDlsym (symbolStr);
34883499
@@ -3534,24 +3545,24 @@ namespace Cpp {
35343545 private:
35353546 static llvm::orc::SymbolFlagsMap getSymbolFlagsMap (const llvm::orc::SymbolNameVector &Symbols) {
35363547 llvm::orc::SymbolFlagsMap map;
3537- for (auto symbolName : Symbols)
3548+ for (const auto & symbolName : Symbols)
35383549 map[symbolName] = llvm::JITSymbolFlags::Exported;
35393550 return map;
35403551 }
35413552 };
35423553
35433554 llvm::Error tryToGenerate (llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
35443555 llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3545- if (Enabled ) {
3556+ if (isEnabled () ) {
35463557 LLVM_DEBUG (dbgs () << " tryToGenerate" );
35473558
35483559 auto & I = getInterp ();
3549- auto DLM = I.getDynamicLibraryManager ();
3560+ auto * DLM = I.getDynamicLibraryManager ();
35503561
35513562 std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
35523563 llvm::orc::SymbolMap NewSymbols;
3553- for (auto &KV : Symbols) {
3554- auto &Name = KV.first ;
3564+ for (const auto &KV : Symbols) {
3565+ const auto &Name = KV.first ;
35553566 if ((*Name).empty ())
35563567 continue ;
35573568
@@ -3577,6 +3588,7 @@ namespace Cpp {
35773588
35783589 return llvm::Error::success ();
35793590 }
3591+
35803592 };
35813593
35823594 void SetLibrariesAutoload (bool autoload /* = true */ ) {
@@ -3588,16 +3600,16 @@ namespace Cpp {
35883600 llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib ().get ();
35893601#endif // CLANG_VERSION_MAJOR
35903602
3591- if (!ALLSG )
3592- ALLSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3593- ALLSG-> Enabled = autoload;
3603+ if (!AutoSG )
3604+ AutoSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3605+ AutoSG-> setEnabled ( autoload) ;
35943606
3595- LLVM_DEBUG (dbgs () << " Autoload=" << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3607+ LLVM_DEBUG (dbgs () << " Autoload=" << (AutoSG-> isEnabled () ? " ON" : " OFF" ));
35963608 }
35973609
35983610 bool GetLibrariesAutoload () {
3599- LLVM_DEBUG (dbgs () << " Autoload is " << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3600- return ALLSG && ALLSG-> Enabled ;
3611+ LLVM_DEBUG (dbgs () << " Autoload is " << (AutoSG && AutoSG-> isEnabled () ? " ON" : " OFF" ));
3612+ return AutoSG && AutoSG-> isEnabled () ;
36013613 }
36023614
36033615#undef DEBUG_TYPE
0 commit comments