39
39
#include < set>
40
40
#include < sstream>
41
41
#include < string>
42
+ #include < utility>
42
43
43
44
// Stream redirect.
44
45
#ifdef _WIN32
@@ -3454,40 +3455,50 @@ namespace Cpp {
3454
3455
}
3455
3456
3456
3457
class AutoLoadLibrarySearchGenerator ;
3457
- static AutoLoadLibrarySearchGenerator *ALLSG = nullptr ;
3458
+
3459
+ // Last assigned Autoload SearchGenerator
3460
+ // TODO: Test for thread safe.
3461
+ static AutoLoadLibrarySearchGenerator *AutoSG = nullptr ;
3458
3462
3459
3463
class AutoLoadLibrarySearchGenerator : public llvm ::orc::DefinitionGenerator {
3460
- public:
3461
3464
bool Enabled = false ;
3465
+ public:
3466
+ bool isEnabled () {
3467
+ return Enabled;
3468
+ }
3469
+
3470
+ void setEnabled (bool enabled) {
3471
+ Enabled = enabled;
3472
+ }
3462
3473
3463
3474
// Lazy materialization unit class helper
3464
3475
class AutoloadLibraryMU : public llvm ::orc::MaterializationUnit {
3465
- std::string lib;
3476
+ const std::string lib;
3466
3477
llvm::orc::SymbolNameVector syms;
3467
3478
public:
3468
- AutoloadLibraryMU (const std::string & Library, const llvm::orc::SymbolNameVector &Symbols)
3479
+ AutoloadLibraryMU (const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
3469
3480
: MaterializationUnit({getSymbolFlagsMap (Symbols), nullptr }), lib(Library), syms(Symbols) {}
3470
3481
3471
- StringRef getName () const override {
3482
+ [[nodiscard]] StringRef getName () const override {
3472
3483
return " <Symbols from Autoloaded Library>" ;
3473
3484
}
3474
3485
3475
3486
void materialize (std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3476
- if (!ALLSG || !ALLSG-> Enabled ) {
3487
+ if (!AutoSG || !AutoSG-> isEnabled () ) {
3477
3488
R->failMaterialization ();
3478
3489
return ;
3479
3490
}
3480
3491
3481
3492
LLVM_DEBUG (dbgs () << " Materialize " << lib << " syms=" << syms);
3482
3493
3483
3494
auto & I = getInterp ();
3484
- auto DLM = I.getDynamicLibraryManager ();
3495
+ auto * DLM = I.getDynamicLibraryManager ();
3485
3496
3486
3497
llvm::orc::SymbolMap loadedSymbols;
3487
3498
llvm::orc::SymbolNameSet failedSymbols;
3488
3499
bool loadedLibrary = false ;
3489
3500
3490
- for (auto symbol : syms) {
3501
+ for (const auto & symbol : syms) {
3491
3502
std::string symbolStr = (*symbol).str ();
3492
3503
std::string nameForDlsym = DemangleNameForDlsym (symbolStr);
3493
3504
@@ -3539,24 +3550,24 @@ namespace Cpp {
3539
3550
private:
3540
3551
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap (const llvm::orc::SymbolNameVector &Symbols) {
3541
3552
llvm::orc::SymbolFlagsMap map;
3542
- for (auto symbolName : Symbols)
3553
+ for (const auto & symbolName : Symbols)
3543
3554
map[symbolName] = llvm::JITSymbolFlags::Exported;
3544
3555
return map;
3545
3556
}
3546
3557
};
3547
3558
3548
3559
llvm::Error tryToGenerate (llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
3549
3560
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3550
- if (Enabled ) {
3561
+ if (isEnabled () ) {
3551
3562
LLVM_DEBUG (dbgs () << " tryToGenerate" );
3552
3563
3553
3564
auto & I = getInterp ();
3554
- auto DLM = I.getDynamicLibraryManager ();
3565
+ auto * DLM = I.getDynamicLibraryManager ();
3555
3566
3556
3567
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
3557
3568
llvm::orc::SymbolMap NewSymbols;
3558
- for (auto &KV : Symbols) {
3559
- auto &Name = KV.first ;
3569
+ for (const auto &KV : Symbols) {
3570
+ const auto &Name = KV.first ;
3560
3571
if ((*Name).empty ())
3561
3572
continue ;
3562
3573
@@ -3582,6 +3593,7 @@ namespace Cpp {
3582
3593
3583
3594
return llvm::Error::success ();
3584
3595
}
3596
+
3585
3597
};
3586
3598
3587
3599
void SetLibrariesAutoload (bool autoload /* = true */ ) {
@@ -3593,16 +3605,16 @@ namespace Cpp {
3593
3605
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib ().get ();
3594
3606
#endif // CLANG_VERSION_MAJOR
3595
3607
3596
- if (!ALLSG )
3597
- ALLSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3598
- ALLSG-> Enabled = autoload;
3608
+ if (!AutoSG )
3609
+ AutoSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3610
+ AutoSG-> setEnabled ( autoload) ;
3599
3611
3600
- LLVM_DEBUG (dbgs () << " Autoload=" << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3612
+ LLVM_DEBUG (dbgs () << " Autoload=" << (AutoSG-> isEnabled () ? " ON" : " OFF" ));
3601
3613
}
3602
3614
3603
3615
bool GetLibrariesAutoload () {
3604
- LLVM_DEBUG (dbgs () << " Autoload is " << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3605
- return ALLSG && ALLSG-> Enabled ;
3616
+ LLVM_DEBUG (dbgs () << " Autoload is " << (AutoSG && AutoSG-> isEnabled () ? " ON" : " OFF" ));
3617
+ return AutoSG && AutoSG-> isEnabled () ;
3606
3618
}
3607
3619
3608
3620
#undef DEBUG_TYPE
0 commit comments