[lld] r317039 - Do not access beyond the end of local symbols.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 31 14:26:42 PDT 2017


Author: ruiu
Date: Tue Oct 31 14:26:42 2017
New Revision: 317039

URL: http://llvm.org/viewvc/llvm-project?rev=317039&view=rev
Log:
Do not access beyond the end of local symbols.

This patch resurrects code that was removed in r317007 to not access
beyond allocated memory for a symbol.

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

Modified:
    lld/trunk/COFF/SymbolTable.cpp

Modified: lld/trunk/COFF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/SymbolTable.cpp?rev=317039&r1=317038&r2=317039&view=diff
==============================================================================
--- lld/trunk/COFF/SymbolTable.cpp (original)
+++ lld/trunk/COFF/SymbolTable.cpp Tue Oct 31 14:26:42 2017
@@ -106,7 +106,17 @@ void SymbolTable::reportRemainingUndefin
 
     // A weak alias may have been resolved, so check for that.
     if (Defined *D = Undef->getWeakAlias()) {
-      memcpy(Sym, D, sizeof(SymbolUnion));
+      // We want to replace Sym with D. However, we can't just blindly
+      // copy sizeof(SymbolUnion) bytes from D to Sym because D may be an
+      // internal symbol, and internal symbols are stored as "unparented"
+      // Symbols. For that reason we need to check which type of symbol we
+      // are dealing with and copy the correct number of bytes.
+      if (isa<DefinedRegular>(D))
+        memcpy(Sym, D, sizeof(DefinedRegular));
+      else if (isa<DefinedAbsolute>(D))
+        memcpy(Sym, D, sizeof(DefinedAbsolute));
+      else
+        memcpy(Sym, D, sizeof(SymbolUnion));
       continue;
     }
 




More information about the llvm-commits mailing list