[llvm] [yaml2obj][XOFF] Update yaml2obj for XCOFF to create valid XCOFF files in more cases. (PR #77620)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 16 01:04:02 PST 2024
================
@@ -134,23 +144,46 @@ bool XCOFFWriter::initSectionHeader(uint64_t &CurrentOffset) {
}
}
- // Calculate the physical/virtual address. This field should contain 0 for
- // all sections except the text, data and bss sections.
- if (InitSections[I].Flags != XCOFF::STYP_TEXT &&
- InitSections[I].Flags != XCOFF::STYP_DATA &&
- InitSections[I].Flags != XCOFF::STYP_BSS)
- InitSections[I].Address = 0;
- else
- InitSections[I].Address = CurrentSecAddr;
+ if (!InitSections[I].Size)
+ InitSections[I].Size = InitSections[I].SectionData.binary_size();
+
+ // We cannot compute section addresses in general. We only enforce
+ // the rule .data and .bss are consecutive, as are .tdata and .tbss.
+ switch (InitSections[I].Flags) {
+ case XCOFF::STYP_DATA:
+ CurrentDataAddr = InitSections[I].Address + InitSections[I].Size;
+ break;
+ case XCOFF::STYP_BSS:
+ if (!InitSections[I].Address)
+ InitSections[I].Address = CurrentDataAddr;
+ break;
+ case XCOFF::STYP_TDATA:
+ CurrentTDataAddr = InitSections[I].Address + InitSections[I].Size;
+ break;
+ case XCOFF::STYP_TBSS:
+ if (!InitSections[I].Address)
+ InitSections[I].Address = CurrentTDataAddr;
+ break;
+ }
- // Calculate the FileOffsetToData and data size for sections.
if (InitSections[I].SectionData.binary_size()) {
- InitSections[I].FileOffsetToData = CurrentOffset;
+ if (InitSections[I].FileOffsetToData) {
+ // Use the providedFileOffsetToData.
+ if (CurrentOffset > InitSections[I].FileOffsetToData) {
+ ErrHandler("Specified FileOffsetToData will overwrite existing data");
+ return false;
+ }
+ CurrentOffset = InitSections[I].FileOffsetToData;
+ } else {
+ CurrentOffset = alignTo(CurrentOffset, DefaultSectionAlign);
+ InitSections[I].FileOffsetToData = CurrentOffset;
+ }
CurrentOffset += InitSections[I].SectionData.binary_size();
- // Ensure the offset is aligned to DefaultSectionAlign.
- CurrentOffset = alignTo(CurrentOffset, DefaultSectionAlign);
- InitSections[I].Size = CurrentOffset - InitSections[I].FileOffsetToData;
- CurrentSecAddr += InitSections[I].Size;
+ if (CurrentOffset > MaxRawDataSize) {
+ ErrHandler("maximum object size of" + Twine(MaxRawDataSize) +
+ "exceeded when writing section data");
----------------
jh7370 wrote:
Could you include the name of the section that is being written?
https://github.com/llvm/llvm-project/pull/77620
More information about the llvm-commits
mailing list