[PATCH] COFF: Minor fix to Section size calculation
kfischer at college.harvard.edu
Tue Jun 10 10:49:42 PDT 2014
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).
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.
@@ -829,11 +829,21 @@
// within the file bounds. We don't need to make sure it doesn't cover other
// data, as there's nothing that says that is not allowed.
uintptr_t ConStart = uintptr_t(base()) + Sec->PointerToRawData;
- uintptr_t ConEnd = ConStart + Sec->SizeOfRawData;
+ // COFF requires sections to follow certain alignment rules in PE
+ // files. Thus (in a PE file) a section's actual data may be smaller
+ // than SizeOfRawData.
+ // Since for debug sections later on the actual data matters, we take
+ // the min of SizeOfRawData and VirtualSize which is the acutal size
+ // of the data.
+ uintptr_t Size = Sec->SizeOfRawData;
+ // COFF Object files always have VirtualSize set to 0
+ if (Sec->VirtualSize != 0)
+ Size = std::min(Size,(uintptr_t)Sec->VirtualSize);
+ uintptr_t ConEnd = ConStart + Size;
if (ConEnd > uintptr_t(Data->getBufferEnd()))
Res = ArrayRef<uint8_t>(reinterpret_cast<const unsigned char*>(ConStart),
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1296 bytes
Desc: not available
More information about the llvm-commits