37
37
38
38
#include < sstream>
39
39
#include < string>
40
+ #include < utility>
40
41
41
42
// Stream redirect.
42
43
#ifdef _WIN32
@@ -3396,40 +3397,50 @@ namespace Cpp {
3396
3397
}
3397
3398
3398
3399
class AutoLoadLibrarySearchGenerator ;
3399
- static AutoLoadLibrarySearchGenerator *ALLSG = nullptr ;
3400
+
3401
+ // Last assigned Autoload SearchGenerator
3402
+ // TODO: Test for thread safe.
3403
+ static AutoLoadLibrarySearchGenerator *AutoSG = nullptr ;
3400
3404
3401
3405
class AutoLoadLibrarySearchGenerator : public llvm ::orc::DefinitionGenerator {
3402
- public:
3403
3406
bool Enabled = false ;
3407
+ public:
3408
+ bool isEnabled () {
3409
+ return Enabled;
3410
+ }
3411
+
3412
+ void setEnabled (bool enabled) {
3413
+ Enabled = enabled;
3414
+ }
3404
3415
3405
3416
// Lazy materialization unit class helper
3406
3417
class AutoloadLibraryMU : public llvm ::orc::MaterializationUnit {
3407
- std::string lib;
3418
+ const std::string lib;
3408
3419
llvm::orc::SymbolNameVector syms;
3409
3420
public:
3410
- AutoloadLibraryMU (const std::string & Library, const llvm::orc::SymbolNameVector &Symbols)
3421
+ AutoloadLibraryMU (const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
3411
3422
: MaterializationUnit({getSymbolFlagsMap (Symbols), nullptr }), lib(Library), syms(Symbols) {}
3412
3423
3413
- StringRef getName () const override {
3424
+ [[nodiscard]] StringRef getName () const override {
3414
3425
return " <Symbols from Autoloaded Library>" ;
3415
3426
}
3416
3427
3417
3428
void materialize (std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3418
- if (!ALLSG || !ALLSG-> Enabled ) {
3429
+ if (!AutoSG || !AutoSG-> isEnabled () ) {
3419
3430
R->failMaterialization ();
3420
3431
return ;
3421
3432
}
3422
3433
3423
3434
LLVM_DEBUG (dbgs () << " Materialize " << lib << " syms=" << syms);
3424
3435
3425
3436
auto & I = getInterp ();
3426
- auto DLM = I.getDynamicLibraryManager ();
3437
+ auto * DLM = I.getDynamicLibraryManager ();
3427
3438
3428
3439
llvm::orc::SymbolMap loadedSymbols;
3429
3440
llvm::orc::SymbolNameSet failedSymbols;
3430
3441
bool loadedLibrary = false ;
3431
3442
3432
- for (auto symbol : syms) {
3443
+ for (const auto & symbol : syms) {
3433
3444
std::string symbolStr = (*symbol).str ();
3434
3445
std::string nameForDlsym = DemangleNameForDlsym (symbolStr);
3435
3446
@@ -3481,24 +3492,24 @@ namespace Cpp {
3481
3492
private:
3482
3493
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap (const llvm::orc::SymbolNameVector &Symbols) {
3483
3494
llvm::orc::SymbolFlagsMap map;
3484
- for (auto symbolName : Symbols)
3495
+ for (const auto & symbolName : Symbols)
3485
3496
map[symbolName] = llvm::JITSymbolFlags::Exported;
3486
3497
return map;
3487
3498
}
3488
3499
};
3489
3500
3490
3501
llvm::Error tryToGenerate (llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
3491
3502
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3492
- if (Enabled ) {
3503
+ if (isEnabled () ) {
3493
3504
LLVM_DEBUG (dbgs () << " tryToGenerate" );
3494
3505
3495
3506
auto & I = getInterp ();
3496
- auto DLM = I.getDynamicLibraryManager ();
3507
+ auto * DLM = I.getDynamicLibraryManager ();
3497
3508
3498
3509
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
3499
3510
llvm::orc::SymbolMap NewSymbols;
3500
- for (auto &KV : Symbols) {
3501
- auto &Name = KV.first ;
3511
+ for (const auto &KV : Symbols) {
3512
+ const auto &Name = KV.first ;
3502
3513
if ((*Name).empty ())
3503
3514
continue ;
3504
3515
@@ -3524,6 +3535,7 @@ namespace Cpp {
3524
3535
3525
3536
return llvm::Error::success ();
3526
3537
}
3538
+
3527
3539
};
3528
3540
3529
3541
void SetLibrariesAutoload (bool autoload /* = true */ ) {
@@ -3535,16 +3547,16 @@ namespace Cpp {
3535
3547
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib ().get ();
3536
3548
#endif // CLANG_VERSION_MAJOR
3537
3549
3538
- if (!ALLSG )
3539
- ALLSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3540
- ALLSG-> Enabled = autoload;
3550
+ if (!AutoSG )
3551
+ AutoSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3552
+ AutoSG-> setEnabled ( autoload) ;
3541
3553
3542
- LLVM_DEBUG (dbgs () << " Autoload=" << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3554
+ LLVM_DEBUG (dbgs () << " Autoload=" << (AutoSG-> isEnabled () ? " ON" : " OFF" ));
3543
3555
}
3544
3556
3545
3557
bool GetLibrariesAutoload () {
3546
- LLVM_DEBUG (dbgs () << " Autoload is " << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3547
- return ALLSG && ALLSG-> Enabled ;
3558
+ LLVM_DEBUG (dbgs () << " Autoload is " << (AutoSG && AutoSG-> isEnabled () ? " ON" : " OFF" ));
3559
+ return AutoSG && AutoSG-> isEnabled () ;
3548
3560
}
3549
3561
3550
3562
#undef DEBUG_TYPE
0 commit comments