Object/COFF: Do not rely on VirtualSize being 0 in object files.
authorRui Ueyama <ruiu@google.com>
Sat, 4 Jul 2015 03:25:51 +0000 (03:25 +0000)
committerRui Ueyama <ruiu@google.com>
Sat, 4 Jul 2015 03:25:51 +0000 (03:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241387 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Object/COFFObjectFile.cpp

index 9c9a6df368982fd8dfe128e81fd74e27ceff5988..19b53d8028d3eb3b02916b05387aa7f6c7cbb862 100644 (file)
@@ -918,19 +918,15 @@ uint64_t COFFObjectFile::getSectionSize(const coff_section *Sec) const {
   // whether or not we have an executable image.
   //
   // For object files, SizeOfRawData contains the size of section's data;
-  // VirtualSize is always zero.
+  // VirtualSize should be zero but isn't due to buggy COFF writers.
   //
   // 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 (getDOSHeader())
+    return std::min(Sec->VirtualSize, Sec->SizeOfRawData);
+  return Sec->SizeOfRawData;
 }
 
 std::error_code