[lld] bfd00ae - [lld-link] Change config and driver to unique_ptr
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 11 18:31:30 PST 2022
Author: Fangrui Song
Date: 2022-01-11T18:31:25-08:00
New Revision: bfd00ae31ea25ff02884a9cbb0b64f0372817101
URL: https://github.com/llvm/llvm-project/commit/bfd00ae31ea25ff02884a9cbb0b64f0372817101
DIFF: https://github.com/llvm/llvm-project/commit/bfd00ae31ea25ff02884a9cbb0b64f0372817101.diff
LOG: [lld-link] Change config and driver to unique_ptr
Similar to D116143. My x86-64 `lld` is ~5KiB smaller.
Reviewed By: mstorsjo
Differential Revision: https://reviews.llvm.org/D116996
Added:
Modified:
lld/COFF/Config.h
lld/COFF/Driver.cpp
lld/COFF/Driver.h
Removed:
################################################################################
diff --git a/lld/COFF/Config.h b/lld/COFF/Config.h
index 3917975e165d1..5597389b42264 100644
--- a/lld/COFF/Config.h
+++ b/lld/COFF/Config.h
@@ -282,7 +282,7 @@ struct Configuration {
bool stdcallFixup = false;
};
-extern Configuration *config;
+extern std::unique_ptr<Configuration> config;
} // namespace coff
} // namespace lld
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 6178d328e3f56..f8da63c5edbfb 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -60,8 +60,8 @@ using namespace llvm::sys;
namespace lld {
namespace coff {
-Configuration *config;
-LinkerDriver *driver;
+std::unique_ptr<Configuration> config;
+std::unique_ptr<LinkerDriver> driver;
bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &stdoutOS,
raw_ostream &stderrOS) {
@@ -80,8 +80,8 @@ bool link(ArrayRef<const char *> args, bool canExitEarly, raw_ostream &stdoutOS,
stderrOS.enable_colors(stderrOS.has_colors());
COFFLinkerContext ctx;
- config = make<Configuration>();
- driver = make<LinkerDriver>(ctx);
+ config = std::make_unique<Configuration>();
+ driver = std::make_unique<LinkerDriver>(ctx);
driver->linkerMain(args);
diff --git a/lld/COFF/Driver.h b/lld/COFF/Driver.h
index 77e67b282665b..518ec1470677d 100644
--- a/lld/COFF/Driver.h
+++ b/lld/COFF/Driver.h
@@ -30,8 +30,7 @@
namespace lld {
namespace coff {
-class LinkerDriver;
-extern LinkerDriver *driver;
+extern std::unique_ptr<class LinkerDriver> driver;
using llvm::COFF::MachineTypes;
using llvm::COFF::WindowsSubsystem;
More information about the llvm-commits
mailing list