34
34
35
35
#include < sstream>
36
36
#include < string>
37
+ #include < utility>
37
38
38
39
// Stream redirect.
39
40
#ifdef _WIN32
@@ -3286,40 +3287,50 @@ namespace Cpp {
3286
3287
}
3287
3288
3288
3289
class AutoLoadLibrarySearchGenerator ;
3289
- static AutoLoadLibrarySearchGenerator *ALLSG = nullptr ;
3290
+
3291
+ // Last assigned Autoload SearchGenerator
3292
+ // TODO: Test for thread safe.
3293
+ static AutoLoadLibrarySearchGenerator *AutoSG = nullptr ;
3290
3294
3291
3295
class AutoLoadLibrarySearchGenerator : public llvm ::orc::DefinitionGenerator {
3292
- public:
3293
3296
bool Enabled = false ;
3297
+ public:
3298
+ bool isEnabled () {
3299
+ return Enabled;
3300
+ }
3301
+
3302
+ void setEnabled (bool enabled) {
3303
+ Enabled = enabled;
3304
+ }
3294
3305
3295
3306
// Lazy materialization unit class helper
3296
3307
class AutoloadLibraryMU : public llvm ::orc::MaterializationUnit {
3297
- std::string lib;
3308
+ const std::string lib;
3298
3309
llvm::orc::SymbolNameVector syms;
3299
3310
public:
3300
- AutoloadLibraryMU (const std::string & Library, const llvm::orc::SymbolNameVector &Symbols)
3311
+ AutoloadLibraryMU (const std::string Library, const llvm::orc::SymbolNameVector &Symbols)
3301
3312
: MaterializationUnit({getSymbolFlagsMap (Symbols), nullptr }), lib(Library), syms(Symbols) {}
3302
3313
3303
- StringRef getName () const override {
3314
+ [[nodiscard]] StringRef getName () const override {
3304
3315
return " <Symbols from Autoloaded Library>" ;
3305
3316
}
3306
3317
3307
3318
void materialize (std::unique_ptr<llvm::orc::MaterializationResponsibility> R) override {
3308
- if (!ALLSG || !ALLSG-> Enabled ) {
3319
+ if (!AutoSG || !AutoSG-> isEnabled () ) {
3309
3320
R->failMaterialization ();
3310
3321
return ;
3311
3322
}
3312
3323
3313
3324
LLVM_DEBUG (dbgs () << " Materialize " << lib << " syms=" << syms);
3314
3325
3315
3326
auto & I = getInterp ();
3316
- auto DLM = I.getDynamicLibraryManager ();
3327
+ auto * DLM = I.getDynamicLibraryManager ();
3317
3328
3318
3329
llvm::orc::SymbolMap loadedSymbols;
3319
3330
llvm::orc::SymbolNameSet failedSymbols;
3320
3331
bool loadedLibrary = false ;
3321
3332
3322
- for (auto symbol : syms) {
3333
+ for (const auto & symbol : syms) {
3323
3334
std::string symbolStr = (*symbol).str ();
3324
3335
std::string nameForDlsym = DemangleNameForDlsym (symbolStr);
3325
3336
@@ -3371,24 +3382,24 @@ namespace Cpp {
3371
3382
private:
3372
3383
static llvm::orc::SymbolFlagsMap getSymbolFlagsMap (const llvm::orc::SymbolNameVector &Symbols) {
3373
3384
llvm::orc::SymbolFlagsMap map;
3374
- for (auto symbolName : Symbols)
3385
+ for (const auto & symbolName : Symbols)
3375
3386
map[symbolName] = llvm::JITSymbolFlags::Exported;
3376
3387
return map;
3377
3388
}
3378
3389
};
3379
3390
3380
3391
llvm::Error tryToGenerate (llvm::orc::LookupState &LS, llvm::orc::LookupKind K, llvm::orc::JITDylib &JD,
3381
3392
llvm::orc::JITDylibLookupFlags JDLookupFlags, const llvm::orc::SymbolLookupSet &Symbols) override {
3382
- if (Enabled ) {
3393
+ if (isEnabled () ) {
3383
3394
LLVM_DEBUG (dbgs () << " tryToGenerate" );
3384
3395
3385
3396
auto & I = getInterp ();
3386
- auto DLM = I.getDynamicLibraryManager ();
3397
+ auto * DLM = I.getDynamicLibraryManager ();
3387
3398
3388
3399
std::unordered_map<std::string, llvm::orc::SymbolNameVector> found;
3389
3400
llvm::orc::SymbolMap NewSymbols;
3390
- for (auto &KV : Symbols) {
3391
- auto &Name = KV.first ;
3401
+ for (const auto &KV : Symbols) {
3402
+ const auto &Name = KV.first ;
3392
3403
if ((*Name).empty ())
3393
3404
continue ;
3394
3405
@@ -3414,6 +3425,7 @@ namespace Cpp {
3414
3425
3415
3426
return llvm::Error::success ();
3416
3427
}
3428
+
3417
3429
};
3418
3430
3419
3431
void SetLibrariesAutoload (bool autoload /* = true */ ) {
@@ -3425,16 +3437,16 @@ namespace Cpp {
3425
3437
llvm::orc::JITDylib& DyLib = *EE.getProcessSymbolsJITDylib ().get ();
3426
3438
#endif // CLANG_VERSION_MAJOR
3427
3439
3428
- if (!ALLSG )
3429
- ALLSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3430
- ALLSG-> Enabled = autoload;
3440
+ if (!AutoSG )
3441
+ AutoSG = &DyLib.addGenerator (std::make_unique<AutoLoadLibrarySearchGenerator>());
3442
+ AutoSG-> setEnabled ( autoload) ;
3431
3443
3432
- LLVM_DEBUG (dbgs () << " Autoload=" << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3444
+ LLVM_DEBUG (dbgs () << " Autoload=" << (AutoSG-> isEnabled () ? " ON" : " OFF" ));
3433
3445
}
3434
3446
3435
3447
bool GetLibrariesAutoload () {
3436
- LLVM_DEBUG (dbgs () << " Autoload is " << (ALLSG && ALLSG-> Enabled ? " ON" : " OFF" ));
3437
- return ALLSG && ALLSG-> Enabled ;
3448
+ LLVM_DEBUG (dbgs () << " Autoload is " << (AutoSG && AutoSG-> isEnabled () ? " ON" : " OFF" ));
3449
+ return AutoSG && AutoSG-> isEnabled () ;
3438
3450
}
3439
3451
3440
3452
#undef DEBUG_TYPE
0 commit comments