[PATCH] D116092: [XCOFF] make sure same number of paddings are added

ChenZheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 21 00:47:11 PST 2021


shchenz created this revision.
shchenz added reviewers: jsji, PowerPC.
Herald added subscribers: steven.zhang, hiraditya.
shchenz requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This is found in D114419 <https://reviews.llvm.org/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 <https://reviews.llvm.org/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 <https://reviews.llvm.org/D114419>?


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116092

Files:
  llvm/lib/MC/XCOFFObjectWriter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116092.395612.patch
Type: text/x-patch
Size: 4099 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211221/dc4ca9e7/attachment.bin>


More information about the llvm-commits mailing list