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