This is an archive of the discontinued LLVM Phabricator instance.

[XCOFF] make sure same number of paddings are added
ClosedPublic

Authored by shchenz on Dec 21 2021, 12:47 AM.

Details

Summary

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?

Diff Detail

Event Timeline

shchenz created this revision.Dec 21 2021, 12:47 AM
shchenz requested review of this revision.Dec 21 2021, 12:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 21 2021, 12:47 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 13 2022, 6:10 PM
jsji resigned from this revision.Jun 2 2022, 7:50 AM

gentle ping

Esme added a comment.Jun 22 2022, 6:23 PM

I don't think a non-NFC patch should be missing tests, how about making D114419 to the parent of this patch and leaving an error check there to be fixed in this patch?

llvm/lib/MC/XCOFFObjectWriter.cpp
1098

simplify the if-else to

if (LastDwarfSection)
  LastDwarfSection->MemorySize =
      DwarfSection.Address - LastDwarfSection->Address;
LastDwarfSection = &DwarfSection;
1101
1103

Why do you want the last Dwarf section to be aligned with the DefaultSectionAlign? It seems to me that it is followed by relocation and not sections, right?

shchenz marked 3 inline comments as done.Jun 23 2022, 9:20 PM

I don't think a non-NFC patch should be missing tests, how about making D114419 to the parent of this patch and leaving an error check there to be fixed in this patch?

A reasonable concern. I also tried to do this. But while I was adding not to the run command and checking warning or error in the output of objdump, I felt maybe it is not so good. Without this patch, if we commit D114419 first, we certainly introduce regression although it will be fixed in this patch, but we still make some builds in bug state. So I think we should commit this patch first and then commit D114419. Adding an option to change the alignment for DWARF section in this file can let me cook some testcase for the change, but that also does not sound like a good idea.

Let me your thoughts. Thanks.

llvm/lib/MC/XCOFFObjectWriter.cpp
1103

Right. No sections after the dwarf section. But it is better to align the final section as loading contents from aligned address is preferred. This also align with previous behavior.

shchenz updated this revision to Diff 439612.Jun 23 2022, 9:21 PM
shchenz marked an inline comment as done.

address @Esme comments

Esme accepted this revision.Jun 28 2022, 1:19 AM

LGTM. Thanks.
Please state in the summary that D114419 will test this patch when submitting.

This revision is now accepted and ready to land.Jun 28 2022, 1:19 AM
This revision was landed with ongoing or failed builds.Jun 28 2022, 9:12 PM
This revision was automatically updated to reflect the committed changes.