diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -22,6 +22,7 @@ #include "llvm/Support/GlobPattern.h" #include "llvm/Support/PrettyStackTrace.h" #include +#include #include namespace lld { @@ -343,7 +344,7 @@ }; // The only instance of Configuration struct. -extern Configuration *config; +extern std::unique_ptr config; // The first two elements of versionDefinitions represent VER_NDX_LOCAL and // VER_NDX_GLOBAL. This helper returns other elements. diff --git a/lld/ELF/Driver.h b/lld/ELF/Driver.h --- a/lld/ELF/Driver.h +++ b/lld/ELF/Driver.h @@ -22,7 +22,7 @@ namespace lld { namespace elf { -extern class LinkerDriver *driver; +extern std::unique_ptr driver; class LinkerDriver { public: diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -71,8 +71,8 @@ using namespace lld; using namespace lld::elf; -Configuration *elf::config; -LinkerDriver *elf::driver; +std::unique_ptr elf::config; +std::unique_ptr elf::driver; static void setConfigs(opt::InputArgList &args); static void readConfigs(opt::InputArgList &args); @@ -111,10 +111,10 @@ errorHandler().exitEarly = canExitEarly; stderrOS.enable_colors(stderrOS.has_colors()); - config = make(); - driver = make(); - script = make(); - symtab = make(); + config = std::make_unique(); + driver = std::make_unique(); + script = std::make_unique(); + symtab = std::make_unique(); partitions = {Partition()}; diff --git a/lld/ELF/LinkerScript.h b/lld/ELF/LinkerScript.h --- a/lld/ELF/LinkerScript.h +++ b/lld/ELF/LinkerScript.h @@ -366,7 +366,7 @@ std::vector orphanSections; }; -extern LinkerScript *script; +extern std::unique_ptr script; } // end namespace elf } // end namespace lld diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp --- a/lld/ELF/LinkerScript.cpp +++ b/lld/ELF/LinkerScript.cpp @@ -47,7 +47,7 @@ using namespace lld; using namespace lld::elf; -LinkerScript *elf::script; +std::unique_ptr elf::script; static bool isSectionPrefix(StringRef prefix, StringRef name) { return name.consume_front(prefix) && (name.empty() || name[0] == '.'); diff --git a/lld/ELF/SymbolTable.h b/lld/ELF/SymbolTable.h --- a/lld/ELF/SymbolTable.h +++ b/lld/ELF/SymbolTable.h @@ -91,7 +91,7 @@ llvm::Optional>> demangledSyms; }; -extern SymbolTable *symtab; +extern std::unique_ptr symtab; } // namespace elf } // namespace lld diff --git a/lld/ELF/SymbolTable.cpp b/lld/ELF/SymbolTable.cpp --- a/lld/ELF/SymbolTable.cpp +++ b/lld/ELF/SymbolTable.cpp @@ -29,7 +29,7 @@ using namespace lld; using namespace lld::elf; -SymbolTable *elf::symtab; +std::unique_ptr elf::symtab; void SymbolTable::wrap(Symbol *sym, Symbol *real, Symbol *wrap) { // Redirect __real_foo to the original foo and foo to the original __wrap_foo.