[lld] r255178 - [lld][MachO] Always reserve space for the empty string in the mach-o symbol

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 9 16:12:24 PST 2015


Author: lhames
Date: Wed Dec  9 18:12:24 2015
New Revision: 255178

URL: http://llvm.org/viewvc/llvm-project?rev=255178&view=rev
Log:
[lld][MachO] Always reserve space for the empty string in the mach-o symbol
table.

The first entry in the MachO symbol table is always the empty string: make sure
we reserve space for it, or we will overflow the symbol table by one byte.

No test case - this manifests as an occasional memory error. In the near future
I hope to set up a bot building and runnnig LLD with sanitizers - that should
catch future instances of this issue.


Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp?rev=255178&r1=255177&r2=255178&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileBinaryWriter.cpp Wed Dec  9 18:12:24 2015
@@ -1269,7 +1269,7 @@ void MachOFileLayout::computeSymbolTable
   _symbolTableSize = nlistSize * (_file.localSymbols.size()
                                 + _file.globalSymbols.size()
                                 + _file.undefinedSymbols.size());
-  _symbolStringPoolSize = 0;
+  _symbolStringPoolSize = 1; // Always reserve 1-byte for the empty string.
   for (const Symbol &sym : _file.localSymbols) {
     _symbolStringPoolSize += (sym.name.size()+1);
   }




More information about the llvm-commits mailing list