<div dir="ltr">Bump. I'm not really sure who could best review this. </div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jun 10, 2014 at 1:49 PM, Keno Fischer <span dir="ltr"><<a href="mailto:kfischer@college.harvard.edu" target="_blank">kfischer@college.harvard.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I noticed llvm-dwarfdump was crashing on COFF dlls with embedded DWARF debug info. The reason was that SizeOfRawData actually indicates the size on disc which is not the size of the actual section data in a PE file (*.dll, *.exe), because of alignment rules. Instead the size of given by min(SizeOfRawData,VirtualSize).<br>
<br>
I'm not sure what to do with respect to testing, since compiling a file from source would require a COFF capable linker. Is it acceptable to commit an entire PE exectuable to the repository? If so, I'll try to come up with a minimal example where this happens.<br>
<br>
<a href="http://reviews.llvm.org/D4087" target="_blank">http://reviews.llvm.org/D4087</a><br>
<br>
Files:<br>
 lib/Object/COFFObjectFile.cpp<br>
<br>
Index: lib/Object/COFFObjectFile.cpp<br>
===================================================================<br>
--- lib/Object/COFFObjectFile.cpp<br>
+++ lib/Object/COFFObjectFile.cpp<br>
@@ -829,11 +829,21 @@<br>
  // within the file bounds. We don't need to make sure it doesn't cover other<br>
  // data, as there's nothing that says that is not allowed.<br>
  uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData;<br>
- Â uintptr_t ConEnd = ConStart + Sec->SizeOfRawData;<br>
+ Â // COFF requires sections to follow certain alignment rules in PE<br>
+ Â // files. Thus (in a PE file) a section's actual data may be smaller<br>
+ Â // than SizeOfRawData.<br>
+ Â // Since for debug sections later on the actual data matters, we take<br>
+ Â // the min of SizeOfRawData and VirtualSize which is the acutal size<br>
+ Â // of the data.<br>
+ Â uintptr_t Size = Sec->SizeOfRawData;<br>
+ Â // COFF Object files always have VirtualSize set to 0<br>
+ Â if (Sec->VirtualSize != 0)<br>
+ Â Â Size = std::min(Size,(uintptr_t)Sec->VirtualSize);<br>
+ Â uintptr_t ConEnd = ConStart + Size;<br>
  if (ConEnd > uintptr_t(Data->getBufferEnd()))<br>
   return object_error::parse_failed;<br>
  Res = ArrayRef<uint8_t>(reinterpret_cast<const unsigned char*>(ConStart),<br>
- Â Â Â Â Â Â Â Â Â Â Â Â Â Sec->SizeOfRawData);<br>
+ Â Â Â Â Â Â Â Â Â Â Â Â Â Size);<br>
  return object_error::success;<br>
 }<br>
</blockquote></div><br></div>