This is found in D114419. After changing alignment for DWARF sections from 4 to 32, we found one issue in the XCOFF Object Writer.
One example:
Suppose:
1: the size for all sections(.text, .bss, .data) other than DWARF sections is 52 bytes(already aligned to 4 bytes as required by DefaultSectionAlign):
2: DWARF sections alignment is 32 bytes like in D114419
Step1: In the place where we calculate addresses for DWARF sections, we first align the address of the first DWARF section to new alignment 32, so the start address of DWARF section is 64. We need 64 - 52 = 12 padding bytes here. For this calculation, there are 12 padding bytes before DWARF sections
Step 2: in the place where we calculate FileOffsetToData for each DWARF section. This time, the size of the file header and section header will be considered. In the failure case I meet test/CodeGen/PowerPC/aix-dwarf.ll, the size for XCOFF::FileHeaderSize32 + auxiliaryHeaderSize() + SectionCount * XCOFF::SectionHeaderSize32 is 220, so after adding 52 bytes(sections other than DWARF), the start address of the DWARF section is 272, after 32 bytes align, the start address of DWARF section is 288. And for this calculation, there are 288 - 272 = 16 padding bytes here. And we record FileOffsetToData to the section header assuming that there are 16 padding bytes before DWARF sections.
The mismatch padding bytes for the above two calculations will make XCOFFObjectWriter generate invalid XCOFF object for aix-dwarf.ll
Since currently there is no way to change the alignment for DWARF sections, I left this patch without tests and I guess this patch can be verified together with D114419?
simplify the if-else to