[lld] a8d6d26 - [ELF] Replace make<Defined> with makeDefined. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 15 13:15:09 PST 2021


Author: Fangrui Song
Date: 2021-12-15T13:15:03-08:00
New Revision: a8d6d2614b1807318ae1833f4fcc75d94028fcb2

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

LOG: [ELF] Replace make<Defined> with makeDefined. NFC

This removes SpecificAlloc<Defined> and makes my lld executable 1.5k smaller.
This drops the small memory waste due to the separate BumpPtrAllocator.

Added: 
    

Modified: 
    lld/ELF/Relocations.cpp
    lld/ELF/Symbols.h
    lld/ELF/SyntheticSections.cpp
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index e3782f342897..a8def765621c 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1585,7 +1585,7 @@ static bool handleNonPreemptibleIfunc(Symbol &sym) {
   // original section/value pairs. For non-GOT non-PLT relocation case below, we
   // may alter section/value, so create a copy of the symbol to make
   // section/value fixed.
-  auto *directSym = make<Defined>(cast<Defined>(sym));
+  auto *directSym = makeDefined(cast<Defined>(sym));
   addPltEntry(in.iplt, in.igotPlt, in.relaIplt, target->iRelativeRel,
               *directSym);
   sym.pltIndex = directSym->pltIndex;

diff  --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index e7b4ca0a2be7..5171ca27d7d5 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -16,6 +16,7 @@
 #include "InputFiles.h"
 #include "InputSection.h"
 #include "lld/Common/LLVM.h"
+#include "lld/Common/Memory.h"
 #include "lld/Common/Strings.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/Object/Archive.h"
@@ -576,6 +577,12 @@ void Symbol::replace(const Symbol &newSym) {
     printTraceSymbol(this);
 }
 
+template <typename... T> Defined *makeDefined(T &&...args) {
+  return new (reinterpret_cast<Defined *>(
+      getSpecificAllocSingleton<SymbolUnion>().Allocate()))
+      Defined(std::forward<T>(args)...);
+}
+
 void maybeWarnUnorderableSymbol(const Symbol *sym);
 bool computeIsPreemptible(const Symbol &sym);
 void reportBackrefs();

diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 5982f9054425..49b80772e566 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -264,8 +264,8 @@ InputSection *elf::createInterpSection() {
 
 Defined *elf::addSyntheticLocal(StringRef name, uint8_t type, uint64_t value,
                                 uint64_t size, InputSectionBase &section) {
-  auto *s = make<Defined>(section.file, name, STB_LOCAL, STV_DEFAULT, type,
-                          value, size, &section);
+  Defined *s = makeDefined(section.file, name, STB_LOCAL, STV_DEFAULT, type,
+                           value, size, &section);
   if (in.symTab)
     in.symTab->addSymbol(s);
   return s;

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 17ece08835c1..7ad5f1acecb6 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -752,10 +752,9 @@ template <class ELFT> void Writer<ELFT>::addSectionSymbols() {
     // Set the symbol to be relative to the output section so that its st_value
     // equals the output section address. Note, there may be a gap between the
     // start of the output section and isec.
-    auto *sym =
-        make<Defined>(isec->file, "", STB_LOCAL, /*stOther=*/0, STT_SECTION,
-                      /*value=*/0, /*size=*/0, isec->getOutputSection());
-    in.symTab->addSymbol(sym);
+    in.symTab->addSymbol(
+        makeDefined(isec->file, "", STB_LOCAL, /*stOther=*/0, STT_SECTION,
+                    /*value=*/0, /*size=*/0, isec->getOutputSection()));
   }
 }
 


        


More information about the llvm-commits mailing list