[PATCH] D10939: Object/COFF: Fix getSectionSize

Rui Ueyama ruiu at google.com
Fri Jul 3 19:47:11 PDT 2015


ruiu created this revision.
ruiu added a reviewer: majnemer.
ruiu added a subscriber: llvm-commits.

Some tools such as yasm set a bogus value to object file's
VirtualSize field, so we cannot trust this field. This patch
determines if it's an object or an executable by checking
existence of PE header.

http://reviews.llvm.org/D10939

Files:
  lib/Object/COFFObjectFile.cpp

Index: lib/Object/COFFObjectFile.cpp
===================================================================
--- lib/Object/COFFObjectFile.cpp
+++ lib/Object/COFFObjectFile.cpp
@@ -917,20 +917,14 @@
   // SizeOfRawData and VirtualSize change what they represent depending on
   // whether or not we have an executable image.
   //
-  // For object files, SizeOfRawData contains the size of section's data;
-  // VirtualSize is always zero.
-  //
+  // For object files, SizeOfRawData contains the size of section's data.
   // For executables, SizeOfRawData *must* be a multiple of FileAlignment; the
   // actual section size is in VirtualSize.  It is possible for VirtualSize to
   // be greater than SizeOfRawData; the contents past that point should be
   // considered to be zero.
-  uint32_t SectionSize;
-  if (Sec->VirtualSize)
-    SectionSize = std::min(Sec->VirtualSize, Sec->SizeOfRawData);
-  else
-    SectionSize = Sec->SizeOfRawData;
-
-  return SectionSize;
+  if (PE32Header || PE32PlusHeader)
+    return std::min(Sec->VirtualSize, Sec->SizeOfRawData);
+  return Sec->SizeOfRawData;
 }
 
 std::error_code


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10939.29041.patch
Type: text/x-patch
Size: 1120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150704/3382b76d/attachment.bin>


More information about the llvm-commits mailing list