37
37
38
38
#include < sstream>
39
39
#include < string>
40
+ #include < utility>
40
41
41
42
// Stream redirect.
42
43
#ifdef _WIN32
@@ -3370,40 +3371,50 @@ namespace Cpp {
3370
3371
}
3371
3372
3372
3373
class AutoLoadLibrarySearchGenerator ;
3373
- static AutoLoadLibrarySearchGenerator *ALLSG = nullptr ;
3374
+
3375
+ // Last assigned Autoload SearchGenerator
3376
+ // TODO: Test for thread safe.
3377
+ static AutoLoadLibrarySearchGenerator *AutoSG = nullptr ;
3374
3378
3375
3379
class AutoLoadLibrarySearchGenerator : public llvm ::orc::DefinitionGenerator {
3376
- public:
3377
3380
bool Enabled = false ;
3381
+ public:
3382
+ bool isEnabled () {
3383
+ return Enabled;
3384
+ }
3385
+
3386
+ void setEnabled (bool enabled) {
3387
+ Enabled = enabled;
3388
+ }
3378
3389
3379
3390
// Lazy materialization unit class helper
3380
3391
class AutoloadLibraryMU : public llvm ::orc::MaterializationUnit {
3381
- std::string lib;
3392
+ const std::string lib;
3382
3393
llvm::orc::SymbolNameVector syms;
3383
3394
public:
3384
- AutoloadLibraryMU (const std::string & Library, const llvm::orc::SymbolNameVector &Symbols)
3395
+ AutoloadLibraryMU (const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
3385
3396
: MaterializationUnit({getSymbolFlagsMap (Symbols), nullptr }), lib(Library), syms(Symbols) {}
3386
3397
3387
- StringRef getName () const override {
3398
+ [[nodiscard]] StringRef getName () const override {
3388
3399
return " <Symbols from Autoloaded Library>" ;
3389
3400
}
3390
3401
3391
3402
void materialize (std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3392
- if (!ALLSG || !ALLSG-> Enabled ) {
3403
+ if (!AutoSG || !AutoSG-> isEnabled () ) {
3393
3404
R->failMaterialization ();
3394
3405
return ;
3395
3406
}
3396
3407
3397
3408
LLVM_DEBUG (dbgs () << " Materialize " << lib << " syms=" << syms);
3398
3409
3399
3410
auto & I = getInterp ();
3400
- auto DLM = I.getDynamicLibraryManager ();
3411
+ auto * DLM = I.getDynamicLibraryManager ();
3401
3412
3402
3413
llvm::orc::SymbolMap loadedSymbols;
3403
3414
llvm::orc::SymbolNameSet failedSymbols;
3404
3415
bool loadedLibrary = false ;
3405
3416
3406
- for (auto symbol : syms) {
3417
+ for (const auto & symbol : syms) {
3407
3418
std::string symbolStr = (*symbol).str ();
3408
3419
std::string nameForDlsym = DemangleNameForDlsym (symbolStr);
3409
3420
@@ -3455,24 +3466,24 @@ namespace Cpp {
3455
3466
private:
3456
3467
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap (const llvm::orc::SymbolNameVector &Symbols) {
3457
3468
llvm::orc::SymbolFlagsMap map;
3458
- for (auto symbolName : Symbols)
3469
+ for (const auto & symbolName : Symbols)
3459
3470
map[symbolName] = llvm::JITSymbolFlags::Exported;
3460
3471
return map;
3461
3472
}
3462
3473
};
3463
3474
3464
3475
llvm::Error tryToGenerate (llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
3465
3476
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3466
- if (Enabled ) {
3477
+ if (isEnabled () ) {
3467
3478
LLVM_DEBUG (dbgs () << " tryToGenerate" );
3468
3479
3469
3480
auto & I = getInterp ();
3470
- auto DLM = I.getDynamicLibraryManager ();
3481
+ auto * DLM = I.getDynamicLibraryManager ();
3471
3482
3472
3483
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
3473
3484
llvm::orc::SymbolMap NewSymbols;
3474
- for (auto &KV : Symbols) {
3475
- auto &Name = KV.first ;
3485
+ for (const auto &KV : Symbols) {
3486
+ const auto &Name = KV.first ;
3476
3487
if ((*Name).empty ())
3477
3488
continue ;
3478
3489
@@ -3498,6 +3509,7 @@ namespace Cpp {
3498
3509
3499
3510
return llvm::Error::success ();
3500
3511
}
3512
+
3501
3513
};
3502
3514
3503
3515
void SetLibrariesAutoload (bool autoload /* = true */ ) {
@@ -3509,16 +3521,16 @@ namespace Cpp {
3509
3521
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib ().get ();
3510
3522
#endif // CLANG_VERSION_MAJOR
3511
3523
3512
- if (!ALLSG )
3513
- ALLSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3514
- ALLSG-> Enabled = autoload;
3524
+ if (!AutoSG )
3525
+ AutoSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3526
+ AutoSG-> setEnabled ( autoload) ;
3515
3527
3516
- LLVM_DEBUG (dbgs () << " Autoload=" << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3528
+ LLVM_DEBUG (dbgs () << " Autoload=" << (AutoSG-> isEnabled () ? " ON" : " OFF" ));
3517
3529
}
3518
3530
3519
3531
bool GetLibrariesAutoload () {
3520
- LLVM_DEBUG (dbgs () << " Autoload is " << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3521
- return ALLSG && ALLSG-> Enabled ;
3532
+ LLVM_DEBUG (dbgs () << " Autoload is " << (AutoSG && AutoSG-> isEnabled () ? " ON" : " OFF" ));
3533
+ return AutoSG && AutoSG-> isEnabled () ;
3522
3534
}
3523
3535
3524
3536
#undef DEBUG_TYPE
0 commit comments