[lld] a623a4c - [ELF] Remove elf::config indirection. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 1 11:39:54 PDT 2022


Author: Fangrui Song
Date: 2022-10-01T11:39:45-07:00
New Revision: a623a4c8b4d5cc933ebc1856ce30aac935f62b18

URL: https://github.com/llvm/llvm-project/commit/a623a4c8b4d5cc933ebc1856ce30aac935f62b18
DIFF: https://github.com/llvm/llvm-project/commit/a623a4c8b4d5cc933ebc1856ce30aac935f62b18.diff

LOG: [ELF] Remove elf::config indirection. NFC

`config` has 1000+ uses so we try to avoid changing `config->foo`. Define a
wrapper with LLVM_LIBRARY_VISIBILITY to remove unneeded GOT and unique_ptr
indirection.

My x86-64 lld executable is 11+KiB smaller.

Added: 
    

Modified: 
    lld/ELF/Config.h
    lld/ELF/Driver.cpp
    lld/ELF/Relocations.cpp

Removed: 
    


################################################################################
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<Configuration> 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<Configuration> elf::config;
+ConfigWrapper elf::config;
 std::unique_ptr<Ctx> elf::ctx;
 std::unique_ptr<LinkerDriver> elf::driver;
 
@@ -112,7 +112,7 @@ bool elf::link(ArrayRef<const char *> 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<Configuration>();
+  config = ConfigWrapper();
   elf::ctx = std::make_unique<Ctx>();
   driver = std::make_unique<LinkerDriver>();
   script = std::make_unique<LinkerScript>();

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.


        


More information about the llvm-commits mailing list