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