diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index ccb98a6bc55ea..ac25fc677c664 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -19,6 +19,7 @@ #include "llvm/BinaryFormat/ELF.h" #include "llvm/Support/CachePruning.h" #include "llvm/Support/CodeGen.h" +#include "llvm/Support/Compiler.h" #include "llvm/Support/Compression.h" #include "llvm/Support/Endian.h" #include "llvm/Support/GlobPattern.h" @@ -101,7 +102,7 @@ struct VersionDefinition { // Most fields are direct mapping from the command line options // and such fields have the same name as the corresponding options. // Most fields are initialized by the driver. -struct Configuration { +struct Config { uint8_t osabi = 0; uint32_t andFeatures = 0; llvm::CachePruningPolicy thinLTOCachePolicy; @@ -368,9 +369,12 @@ struct Configuration { unsigned threadCount; }; +struct ConfigWrapper { + Config c; + Config *operator->() { return &c; } +}; -// The only instance of Configuration struct. -extern std::unique_ptr config; +LLVM_LIBRARY_VISIBILITY extern ConfigWrapper config; struct DuplicateSymbol { const Symbol *sym; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index d5e9e8f017d25..3b9d457f4a73e 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -73,7 +73,7 @@ using namespace llvm::support; using namespace lld; using namespace lld::elf; -std::unique_ptr elf::config; +ConfigWrapper elf::config; std::unique_ptr elf::ctx; std::unique_ptr elf::driver; @@ -112,7 +112,7 @@ bool elf::link(ArrayRef args, llvm::raw_ostream &stdoutOS, ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now (use " "--error-limit=0 to see all errors)"; - config = std::make_unique(); + config = ConfigWrapper(); elf::ctx = std::make_unique(); driver = std::make_unique(); script = std::make_unique(); diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 696e172419acb..6c79d1a16337d 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -444,7 +444,6 @@ class RelocationScanner { private: InputSectionBase *sec; OffsetGetter getter; - const Configuration *const config = elf::config.get(); const TargetInfo &target = *elf::target; // End of relocations, used by Mips/PPC64.