40
40
#include < set>
41
41
#include < sstream>
42
42
#include < string>
43
+ #include < utility>
43
44
44
45
// Stream redirect.
45
46
#ifdef _WIN32
@@ -3533,40 +3534,50 @@ namespace Cpp {
3533
3534
}
3534
3535
3535
3536
class AutoLoadLibrarySearchGenerator ;
3536
- static AutoLoadLibrarySearchGenerator *ALLSG = nullptr ;
3537
+
3538
+ // Last assigned Autoload SearchGenerator
3539
+ // TODO: Test for thread safe.
3540
+ static AutoLoadLibrarySearchGenerator *AutoSG = nullptr ;
3537
3541
3538
3542
class AutoLoadLibrarySearchGenerator : public llvm ::orc::DefinitionGenerator {
3539
- public:
3540
3543
bool Enabled = false ;
3544
+ public:
3545
+ bool isEnabled () {
3546
+ return Enabled;
3547
+ }
3548
+
3549
+ void setEnabled (bool enabled) {
3550
+ Enabled = enabled;
3551
+ }
3541
3552
3542
3553
// Lazy materialization unit class helper
3543
3554
class AutoloadLibraryMU : public llvm ::orc::MaterializationUnit {
3544
- std::string lib;
3555
+ const std::string lib;
3545
3556
llvm::orc::SymbolNameVector syms;
3546
3557
public:
3547
- AutoloadLibraryMU (const std::string & Library, const llvm::orc::SymbolNameVector &Symbols)
3558
+ AutoloadLibraryMU (const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
3548
3559
: MaterializationUnit({getSymbolFlagsMap (Symbols), nullptr }), lib(Library), syms(Symbols) {}
3549
3560
3550
- StringRef getName () const override {
3561
+ [[nodiscard]] StringRef getName () const override {
3551
3562
return " <Symbols from Autoloaded Library>" ;
3552
3563
}
3553
3564
3554
3565
void materialize (std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3555
- if (!ALLSG || !ALLSG-> Enabled ) {
3566
+ if (!AutoSG || !AutoSG-> isEnabled () ) {
3556
3567
R->failMaterialization ();
3557
3568
return ;
3558
3569
}
3559
3570
3560
3571
LLVM_DEBUG (dbgs () << " Materialize " << lib << " syms=" << syms);
3561
3572
3562
3573
auto & I = getInterp ();
3563
- auto DLM = I.getDynamicLibraryManager ();
3574
+ auto * DLM = I.getDynamicLibraryManager ();
3564
3575
3565
3576
llvm::orc::SymbolMap loadedSymbols;
3566
3577
llvm::orc::SymbolNameSet failedSymbols;
3567
3578
bool loadedLibrary = false ;
3568
3579
3569
- for (auto symbol : syms) {
3580
+ for (const auto & symbol : syms) {
3570
3581
std::string symbolStr = (*symbol).str ();
3571
3582
std::string nameForDlsym = DemangleNameForDlsym (symbolStr);
3572
3583
@@ -3618,24 +3629,24 @@ namespace Cpp {
3618
3629
private:
3619
3630
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap (const llvm::orc::SymbolNameVector &Symbols) {
3620
3631
llvm::orc::SymbolFlagsMap map;
3621
- for (auto symbolName : Symbols)
3632
+ for (const auto & symbolName : Symbols)
3622
3633
map[symbolName] = llvm::JITSymbolFlags::Exported;
3623
3634
return map;
3624
3635
}
3625
3636
};
3626
3637
3627
3638
llvm::Error tryToGenerate (llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
3628
3639
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3629
- if (Enabled ) {
3640
+ if (isEnabled () ) {
3630
3641
LLVM_DEBUG (dbgs () << " tryToGenerate" );
3631
3642
3632
3643
auto & I = getInterp ();
3633
- auto DLM = I.getDynamicLibraryManager ();
3644
+ auto * DLM = I.getDynamicLibraryManager ();
3634
3645
3635
3646
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
3636
3647
llvm::orc::SymbolMap NewSymbols;
3637
- for (auto &KV : Symbols) {
3638
- auto &Name = KV.first ;
3648
+ for (const auto &KV : Symbols) {
3649
+ const auto &Name = KV.first ;
3639
3650
if ((*Name).empty ())
3640
3651
continue ;
3641
3652
@@ -3661,6 +3672,7 @@ namespace Cpp {
3661
3672
3662
3673
return llvm::Error::success ();
3663
3674
}
3675
+
3664
3676
};
3665
3677
3666
3678
void SetLibrariesAutoload (bool autoload /* = true */ ) {
@@ -3672,16 +3684,16 @@ namespace Cpp {
3672
3684
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib ().get ();
3673
3685
#endif // CLANG_VERSION_MAJOR
3674
3686
3675
- if (!ALLSG )
3676
- ALLSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3677
- ALLSG-> Enabled = autoload;
3687
+ if (!AutoSG )
3688
+ AutoSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3689
+ AutoSG-> setEnabled ( autoload) ;
3678
3690
3679
- LLVM_DEBUG (dbgs () << " Autoload=" << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3691
+ LLVM_DEBUG (dbgs () << " Autoload=" << (AutoSG-> isEnabled () ? " ON" : " OFF" ));
3680
3692
}
3681
3693
3682
3694
bool GetLibrariesAutoload () {
3683
- LLVM_DEBUG (dbgs () << " Autoload is " << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3684
- return ALLSG && ALLSG-> Enabled ;
3695
+ LLVM_DEBUG (dbgs () << " Autoload is " << (AutoSG && AutoSG-> isEnabled () ? " ON" : " OFF" ));
3696
+ return AutoSG && AutoSG-> isEnabled () ;
3685
3697
}
3686
3698
3687
3699
#undef DEBUG_TYPE
0 commit comments