Skip to content

Commit

Permalink
[ELF] Remove elf::config indirection. NFC
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
MaskRay committed Oct 1, 2022
1 parent d7804e1 commit a623a4c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lld/ELF/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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>();
Expand Down
1 change: 0 additions & 1 deletion lld/ELF/Relocations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a623a4c

Please sign in to comment.