[lld] 7787427 - [ELF] Avoid redundant assignment to Symbol fields. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 28 17:56:26 PDT 2022


Author: Fangrui Song
Date: 2022-09-28T17:56:16-07:00
New Revision: 778742760534499e90a410e6187dd6c491150332

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

LOG: [ELF] Avoid redundant assignment to Symbol fields. NFC

Added: 
    

Modified: 
    lld/ELF/InputFiles.cpp
    lld/ELF/Symbols.h

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index 24183e7cbaa3..2f2d40ba800d 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -1098,6 +1098,7 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
   if (!firstGlobal)
     return;
   SymbolUnion *locals = makeThreadLocalN<SymbolUnion>(firstGlobal);
+  memset(locals, 0, sizeof(SymbolUnion) * firstGlobal);
 
   ArrayRef<Elf_Sym> eSyms = this->getELFSyms<ELFT>();
   for (size_t i = 0, end = firstGlobal; i != end; ++i) {
@@ -1128,9 +1129,9 @@ void ObjFile<ELFT>::initSectionsAndLocalSyms(bool ignoreComdats) {
     else
       new (symbols[i]) Defined(this, name, STB_LOCAL, eSym.st_other, type,
                                eSym.st_value, eSym.st_size, sec);
+    symbols[i]->partition = 1;
     symbols[i]->isUsedInRegularObj = true;
     symbols[i]->auxIdx = -1;
-    symbols[i]->dynsymIndex = 0;
   }
 }
 

diff  --git a/lld/ELF/Symbols.h b/lld/ELF/Symbols.h
index aa7ad4d425e6..e4ec63ac50e9 100644
--- a/lld/ELF/Symbols.h
+++ b/lld/ELF/Symbols.h
@@ -111,7 +111,7 @@ class Symbol {
   uint8_t symbolKind;
 
   // The partition whose dynamic symbol table contains this symbol's definition.
-  uint8_t partition = 1;
+  uint8_t partition;
 
   // True if this symbol is preemptible at load time.
   uint8_t isPreemptible : 1;
@@ -263,12 +263,8 @@ class Symbol {
   Symbol(Kind k, InputFile *file, StringRef name, uint8_t binding,
          uint8_t stOther, uint8_t type)
       : file(file), nameData(name.data()), nameSize(name.size()), type(type),
-        binding(binding), stOther(stOther), symbolKind(k), isPreemptible(false),
-        isUsedInRegularObj(false), used(false), exportDynamic(false),
-        inDynamicList(false), referenced(false), referencedAfterWrap(false),
-        traced(false), hasVersionSuffix(false), isInIplt(false),
-        gotInIgot(false), folded(false), needsTocRestore(false),
-        scriptDefined(false), dsoProtected(false) {}
+        binding(binding), stOther(stOther), symbolKind(k),
+        exportDynamic(false) {}
 
   void overwrite(Symbol &sym, Kind k) const {
     if (sym.traced)
@@ -307,7 +303,7 @@ class Symbol {
 
   // Temporary flags used to communicate which symbol entries need PLT and GOT
   // entries during postScanRelocations();
-  std::atomic<uint16_t> flags = 0;
+  std::atomic<uint16_t> flags;
 
   // A symAux index used to access GOT/PLT entry indexes. This is allocated in
   // postScanRelocations().
@@ -551,11 +547,11 @@ union SymbolUnion {
 };
 
 template <typename... T> Defined *makeDefined(T &&...args) {
-  auto *sym = new (reinterpret_cast<Defined *>(
-      getSpecificAllocSingleton<SymbolUnion>().Allocate()))
-      Defined(std::forward<T>(args)...);
-  sym->auxIdx = -1;
-  return sym;
+  auto *sym = getSpecificAllocSingleton<SymbolUnion>().Allocate();
+  memset(sym, 0, sizeof(Symbol));
+  auto &s = *new (reinterpret_cast<Defined *>(sym)) Defined(std::forward<T>(args)...);
+  s.auxIdx = -1;
+  return &s;
 }
 
 void reportDuplicate(const Symbol &sym, const InputFile *newFile,


        


More information about the llvm-commits mailing list