[lld] r368784 - [ELF] Initialize 2 fields of Symbol in SymbolTable::insert

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 13 18:52:47 PDT 2019


Author: maskray
Date: Tue Aug 13 18:52:47 2019
New Revision: 368784

URL: http://llvm.org/viewvc/llvm-project?rev=368784&view=rev
Log:
[ELF] Initialize 2 fields of Symbol in SymbolTable::insert

A new symbol is added to elf::symtab in 3 steps:

1) SymbolTable::insert creates a placeholder.
2) Symbol::mergeProperties
3) Symbol::replace

Fields referenced by steps 2) and 3) should be initialized in
SymbolTable::insert.  `traced` and `referenced` were missed previously.
This did not cause problems because compilers generated code that
initialized them (bit fields) to 0.

Reviewed By: grimar

Differential Revision: https://reviews.llvm.org/D66130

Modified:
    lld/trunk/ELF/SymbolTable.cpp
    lld/trunk/ELF/Symbols.h

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=368784&r1=368783&r2=368784&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Tue Aug 13 18:52:47 2019
@@ -71,6 +71,8 @@ Symbol *SymbolTable::insert(StringRef na
   Symbol *sym = reinterpret_cast<Symbol *>(make<SymbolUnion>());
   symVector.push_back(sym);
 
+  // *sym was not initialized by a constructor. Fields that may get referenced
+  // when it is a placeholder must be initialized here.
   sym->setName(name);
   sym->symbolKind = Symbol::PlaceholderKind;
   sym->versionId = VER_NDX_GLOBAL;
@@ -79,6 +81,8 @@ Symbol *SymbolTable::insert(StringRef na
   sym->exportDynamic = false;
   sym->inDynamicList = false;
   sym->canInline = true;
+  sym->referenced = false;
+  sym->traced = false;
   sym->scriptDefined = false;
   sym->partition = 1;
   return sym;

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=368784&r1=368783&r2=368784&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Tue Aug 13 18:52:47 2019
@@ -537,6 +537,8 @@ void Symbol::replace(const Symbol &newSy
   Symbol old = *this;
   memcpy(this, &newSym, newSym.getSymbolSize());
 
+  // old may be a placeholder. The referenced fields must be initialized in
+  // SymbolTable::insert.
   versionId = old.versionId;
   visibility = old.visibility;
   isUsedInRegularObj = old.isUsedInRegularObj;




More information about the llvm-commits mailing list