[PATCH] D116996: [lld-link] Change config and driver to unique_ptr

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 11 00:06:11 PST 2022


MaskRay created this revision.
MaskRay added reviewers: aganea, mstorsjo, rnk.
Herald added a subscriber: pengfei.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Similar to D116143 <https://reviews.llvm.org/D116143>. My x86-64 `lld` is ~5KiB smaller.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116996

Files:
  lld/COFF/Config.h
  lld/COFF/Driver.cpp
  lld/COFF/Driver.h


Index: lld/COFF/Driver.h
===================================================================
--- lld/COFF/Driver.h
+++ 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;
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -60,8 +60,8 @@
 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 @@
   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);
 
Index: lld/COFF/Config.h
===================================================================
--- lld/COFF/Config.h
+++ lld/COFF/Config.h
@@ -282,7 +282,7 @@
   bool stdcallFixup = false;
 };
 
-extern Configuration *config;
+extern std::unique_ptr<Configuration> config;
 
 } // namespace coff
 } // namespace lld


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116996.398859.patch
Type: text/x-patch
Size: 1422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220111/3b8d8a06/attachment.bin>


More information about the llvm-commits mailing list