[PATCH] D41263: Fix size computation in WindowsResourceCOFFWriter::performFileLayout()

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 14 16:44:31 PST 2017


inglorion created this revision.
inglorion added reviewers: ruiu, zturner.
Herald added a subscriber: hiraditya.

We calculated the size of auxiliary sections as two coff_symbol16s,
instead of as a coff_symbol16 and a coff_aux_section_definition. This
caused us to allocate insufficient bytes, causing the linker to crash
on some resource files. This change fixes the computation.

Fixes PR35581.


https://reviews.llvm.org/D41263

Files:
  llvm/lib/Object/WindowsResource.cpp


Index: llvm/lib/Object/WindowsResource.cpp
===================================================================
--- llvm/lib/Object/WindowsResource.cpp
+++ llvm/lib/Object/WindowsResource.cpp
@@ -375,10 +375,10 @@
   // We have reached the address of the symbol table.
   SymbolTableOffset = FileSize;
 
-  FileSize += COFF::Symbol16Size;     // size of the @feat.00 symbol.
-  FileSize += 4 * COFF::Symbol16Size; // symbol + aux for each section.
-  FileSize += Data.size() * COFF::Symbol16Size; // 1 symbol per resource.
-  FileSize += 4; // four null bytes for the string table.
+  FileSize += 3 * COFF::Symbol16Size +          // @feat.00, .rsrc$1, .rsrc$2
+    2 * sizeof(coff_aux_section_definition) +   // first and second aux section
+    Data.size() * COFF::Symbol16Size +          // 1 symbol per resource
+    4;                                          // string table (4 nul bytes).
 }
 
 void WindowsResourceCOFFWriter::performSectionOneLayout() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41263.127047.patch
Type: text/x-patch
Size: 961 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171215/08a76767/attachment.bin>


More information about the llvm-commits mailing list