Skip to content

Commit a623a4c

Browse files
committed
[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.
1 parent d7804e1 commit a623a4c

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lld/ELF/Config.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/BinaryFormat/ELF.h"
2020
#include "llvm/Support/CachePruning.h"
2121
#include "llvm/Support/CodeGen.h"
22+
#include "llvm/Support/Compiler.h"
2223
#include "llvm/Support/Compression.h"
2324
#include "llvm/Support/Endian.h"
2425
#include "llvm/Support/GlobPattern.h"
@@ -101,7 +102,7 @@ struct VersionDefinition {
101102
// Most fields are direct mapping from the command line options
102103
// and such fields have the same name as the corresponding options.
103104
// Most fields are initialized by the driver.
104-
struct Configuration {
105+
struct Config {
105106
uint8_t osabi = 0;
106107
uint32_t andFeatures = 0;
107108
llvm::CachePruningPolicy thinLTOCachePolicy;
@@ -368,9 +369,12 @@ struct Configuration {
368369

369370
unsigned threadCount;
370371
};
372+
struct ConfigWrapper {
373+
Config c;
374+
Config *operator->() { return &c; }
375+
};
371376

372-
// The only instance of Configuration struct.
373-
extern std::unique_ptr<Configuration> config;
377+
LLVM_LIBRARY_VISIBILITY extern ConfigWrapper config;
374378

375379
struct DuplicateSymbol {
376380
const Symbol *sym;

lld/ELF/Driver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ using namespace llvm::support;
7373
using namespace lld;
7474
using namespace lld::elf;
7575

76-
std::unique_ptr<Configuration> elf::config;
76+
ConfigWrapper elf::config;
7777
std::unique_ptr<Ctx> elf::ctx;
7878
std::unique_ptr<LinkerDriver> elf::driver;
7979

@@ -112,7 +112,7 @@ bool elf::link(ArrayRef<const char *> args, llvm::raw_ostream &stdoutOS,
112112
ctx->e.errorLimitExceededMsg = "too many errors emitted, stopping now (use "
113113
"--error-limit=0 to see all errors)";
114114

115-
config = std::make_unique<Configuration>();
115+
config = ConfigWrapper();
116116
elf::ctx = std::make_unique<Ctx>();
117117
driver = std::make_unique<LinkerDriver>();
118118
script = std::make_unique<LinkerScript>();

lld/ELF/Relocations.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,6 @@ class RelocationScanner {
444444
private:
445445
InputSectionBase *sec;
446446
OffsetGetter getter;
447-
const Configuration *const config = elf::config.get();
448447
const TargetInfo &target = *elf::target;
449448

450449
// End of relocations, used by Mips/PPC64.

0 commit comments

Comments
 (0)