Match MSVC linker output - align all debug directories on four bytes, while removing debug directory alignment. This would have the same effect on CETCOMPAT support as D89919.
Sorry, I meant the constructor of DebugDirectoryChunk should set the alignment to 4. IMO that's simpler than setting it in the loop below, and ensures all debug directories are 4 byte aligned.
Other chunks set their default alignment like this:
C++ class for the chunk we must align - it derives from NonSectionChunk. Other chunks on the same level (CodeView for example) are also deriving from NonSectionChunk.
There is a bit of confusing terminology here. When dumpbin says that "the following debug directories" it refers not to this chunk, but to its contents (what is stored in debugRecords list). We can still align DebugDirectoryChunk in spirit of matching link.exe output, thought it does not seem to have effect on the outcome with this bug.
The chunk we have to align is ExtendedDllCharacteristicsChunk and in this change we are also looking to align other chunks at the same level. All of them derive from NonSectionChunk, so setting default alignment for DebugDirectoryChunk would not really help.
I've added some comments to point to definition and instantiations.
It is possible to take the default alignment route, but that would require adding that to a handful of classes, rather than just setting it in this function.
This can be aligned to match the output of link.exe
This needs to be aligned to fix the bug.
I think it works. We can keep "less than 4" check or keep it as is.
Do we need "less than four" check? To be honest, I've lifted that from createGuardCFTable, and either way wold work for the issue we are fixing. I don't think /align flag would affect the alignment on this level.
I don't think so. So far there are at most two kinds of sections here, just the two added above. They both need 4 byte alignment, and can't receive a higher alignment from anywhere else. We need to be careful in the cfguard code because we are adjusting the alignment of user-provided sections, so they could've requested a 4k alignment, for example, and we wouldn't want to reduce it.