41
41
#include < set>
42
42
#include < sstream>
43
43
#include < string>
44
+ #include < utility>
44
45
45
46
// Stream redirect.
46
47
#ifdef _WIN32
@@ -3565,40 +3566,50 @@ namespace Cpp {
3565
3566
}
3566
3567
3567
3568
class AutoLoadLibrarySearchGenerator ;
3568
- static AutoLoadLibrarySearchGenerator *ALLSG = nullptr ;
3569
+
3570
+ // Last assigned Autoload SearchGenerator
3571
+ // TODO: Test for thread safe.
3572
+ static AutoLoadLibrarySearchGenerator *AutoSG = nullptr ;
3569
3573
3570
3574
class AutoLoadLibrarySearchGenerator : public llvm ::orc::DefinitionGenerator {
3571
- public:
3572
3575
bool Enabled = false ;
3576
+ public:
3577
+ bool isEnabled () {
3578
+ return Enabled;
3579
+ }
3580
+
3581
+ void setEnabled (bool enabled) {
3582
+ Enabled = enabled;
3583
+ }
3573
3584
3574
3585
// Lazy materialization unit class helper
3575
3586
class AutoloadLibraryMU : public llvm ::orc::MaterializationUnit {
3576
- std::string lib;
3587
+ const std::string lib;
3577
3588
llvm::orc::SymbolNameVector syms;
3578
3589
public:
3579
- AutoloadLibraryMU (const std::string & Library, const llvm::orc::SymbolNameVector &Symbols)
3590
+ AutoloadLibraryMU (const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
3580
3591
: MaterializationUnit({getSymbolFlagsMap (Symbols), nullptr }), lib(Library), syms(Symbols) {}
3581
3592
3582
- StringRef getName () const override {
3593
+ [[nodiscard]] StringRef getName () const override {
3583
3594
return " <Symbols from Autoloaded Library>" ;
3584
3595
}
3585
3596
3586
3597
void materialize (std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3587
- if (!ALLSG || !ALLSG-> Enabled ) {
3598
+ if (!AutoSG || !AutoSG-> isEnabled () ) {
3588
3599
R->failMaterialization ();
3589
3600
return ;
3590
3601
}
3591
3602
3592
3603
LLVM_DEBUG (dbgs () << " Materialize " << lib << " syms=" << syms);
3593
3604
3594
3605
auto & I = getInterp ();
3595
- auto DLM = I.getDynamicLibraryManager ();
3606
+ auto * DLM = I.getDynamicLibraryManager ();
3596
3607
3597
3608
llvm::orc::SymbolMap loadedSymbols;
3598
3609
llvm::orc::SymbolNameSet failedSymbols;
3599
3610
bool loadedLibrary = false ;
3600
3611
3601
- for (auto symbol : syms) {
3612
+ for (const auto & symbol : syms) {
3602
3613
std::string symbolStr = (*symbol).str ();
3603
3614
std::string nameForDlsym = DemangleNameForDlsym (symbolStr);
3604
3615
@@ -3650,24 +3661,24 @@ namespace Cpp {
3650
3661
private:
3651
3662
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap (const llvm::orc::SymbolNameVector &Symbols) {
3652
3663
llvm::orc::SymbolFlagsMap map;
3653
- for (auto symbolName : Symbols)
3664
+ for (const auto & symbolName : Symbols)
3654
3665
map[symbolName] = llvm::JITSymbolFlags::Exported;
3655
3666
return map;
3656
3667
}
3657
3668
};
3658
3669
3659
3670
llvm::Error tryToGenerate (llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
3660
3671
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3661
- if (Enabled ) {
3672
+ if (isEnabled () ) {
3662
3673
LLVM_DEBUG (dbgs () << " tryToGenerate" );
3663
3674
3664
3675
auto & I = getInterp ();
3665
- auto DLM = I.getDynamicLibraryManager ();
3676
+ auto * DLM = I.getDynamicLibraryManager ();
3666
3677
3667
3678
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
3668
3679
llvm::orc::SymbolMap NewSymbols;
3669
- for (auto &KV : Symbols) {
3670
- auto &Name = KV.first ;
3680
+ for (const auto &KV : Symbols) {
3681
+ const auto &Name = KV.first ;
3671
3682
if ((*Name).empty ())
3672
3683
continue ;
3673
3684
@@ -3693,6 +3704,7 @@ namespace Cpp {
3693
3704
3694
3705
return llvm::Error::success ();
3695
3706
}
3707
+
3696
3708
};
3697
3709
3698
3710
void SetLibrariesAutoload (bool autoload /* = true */ ) {
@@ -3704,16 +3716,16 @@ namespace Cpp {
3704
3716
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib ().get ();
3705
3717
#endif // CLANG_VERSION_MAJOR
3706
3718
3707
- if (!ALLSG )
3708
- ALLSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3709
- ALLSG-> Enabled = autoload;
3719
+ if (!AutoSG )
3720
+ AutoSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3721
+ AutoSG-> setEnabled ( autoload) ;
3710
3722
3711
- LLVM_DEBUG (dbgs () << " Autoload=" << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3723
+ LLVM_DEBUG (dbgs () << " Autoload=" << (AutoSG-> isEnabled () ? " ON" : " OFF" ));
3712
3724
}
3713
3725
3714
3726
bool GetLibrariesAutoload () {
3715
- LLVM_DEBUG (dbgs () << " Autoload is " << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3716
- return ALLSG && ALLSG-> Enabled ;
3727
+ LLVM_DEBUG (dbgs () << " Autoload is " << (AutoSG && AutoSG-> isEnabled () ? " ON" : " OFF" ));
3728
+ return AutoSG && AutoSG-> isEnabled () ;
3717
3729
}
3718
3730
3719
3731
#undef DEBUG_TYPE
0 commit comments