[llvm] db5b7b3 - [XCOFF] Fix the offset error of dwarf sections caused by D137819.
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 10 09:32:59 PST 2023
Author: esmeyi
Date: 2023-01-10T12:32:13-05:00
New Revision: db5b7b3fe28dfdd4a038c7aac3fce1678765b9e6
URL: https://github.com/llvm/llvm-project/commit/db5b7b3fe28dfdd4a038c7aac3fce1678765b9e6
DIFF: https://github.com/llvm/llvm-project/commit/db5b7b3fe28dfdd4a038c7aac3fce1678765b9e6.diff
LOG: [XCOFF] Fix the offset error of dwarf sections caused by D137819.
Added:
Modified:
llvm/lib/MC/XCOFFObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index 980b014e832f3..0657ed2156593 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -238,6 +238,7 @@ class XCOFFObjectWriter : public MCObjectWriter {
uint32_t SymbolTableEntryCount = 0;
uint64_t SymbolTableOffset = 0;
uint16_t SectionCount = 0;
+ uint32_t PaddingsBeforeDwarf = 0;
std::vector<std::pair<std::string, size_t>> FileNames;
bool HasVisibility = false;
@@ -416,6 +417,7 @@ void XCOFFObjectWriter::reset() {
SymbolTableEntryCount = 0;
SymbolTableOffset = 0;
SectionCount = 0;
+ PaddingsBeforeDwarf = 0;
Strings.clear();
MCObjectWriter::reset();
@@ -1148,7 +1150,6 @@ void XCOFFObjectWriter::finalizeSectionInfo() {
auxiliaryHeaderSize();
// Calculate the file offset to the section data.
- uint64_t CurrAddress = 0;
for (auto *Sec : Sections) {
if (Sec->Index == SectionEntry::UninitializedIndex || Sec->IsVirtual)
continue;
@@ -1157,19 +1158,10 @@ void XCOFFObjectWriter::finalizeSectionInfo() {
RawPointer += Sec->Size;
if (RawPointer > MaxRawDataSize)
report_fatal_error("Section raw data overflowed this object file.");
-
- CurrAddress = Sec->Address + Sec->Size;
}
- // Sections other than DWARF section use DefaultSectionAlign as the default
- // alignment, while DWARF sections have their own alignments. If these two
- // alignments are not the same, we need some padding here and to use this
- // padding in FileOffsetToData calculation.
if (!DwarfSections.empty()) {
- RawPointer +=
- alignTo(CurrAddress,
- (*DwarfSections.begin()).DwarfSect->MCSec->getAlign()) -
- CurrAddress;
+ RawPointer += PaddingsBeforeDwarf;
for (auto &DwarfSection : DwarfSections) {
DwarfSection.FileOffsetToData = RawPointer;
RawPointer += DwarfSection.MemorySize;
@@ -1345,7 +1337,17 @@ void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) {
Section->Size = Address - Section->Address;
}
- // Start to generate DWARF sections.
+ // Start to generate DWARF sections. Sections other than DWARF section use
+ // DefaultSectionAlign as the default alignment, while DWARF sections have
+ // their own alignments. If these two alignments are not the same, we need
+ // some paddings here and record the paddings bytes for FileOffsetToData
+ // calculation.
+ if (!DwarfSections.empty())
+ PaddingsBeforeDwarf =
+ alignTo(Address,
+ (*DwarfSections.begin()).DwarfSect->MCSec->getAlign()) -
+ Address;
+
DwarfSectionEntry *LastDwarfSection = nullptr;
for (auto &DwarfSection : DwarfSections) {
assert((SectionIndex <= MaxSectionIndex) && "Section index overflow!");
More information about the llvm-commits
mailing list