/// Get the assembler object this is a layout for.
MCAssembler &getAssembler() const { return Assembler; }
- uint64_t getFragmentAddress(const MCFragment *F) const;
+ /// @name Fragment Layout Data
+ /// @{
+ /// \brief Get the effective size of the given fragment, as computed in the
+ /// current layout.
uint64_t getFragmentEffectiveSize(const MCFragment *F) const;
+
+ /// \brief Set the effective size of the given fragment.
void setFragmentEffectiveSize(MCFragment *F, uint64_t Value);
+ /// \brief Get the offset of the given fragment inside its containing section.
uint64_t getFragmentOffset(const MCFragment *F) const;
+
+ /// \brief Set the offset of the given fragment inside its containing section.
void setFragmentOffset(MCFragment *F, uint64_t Value);
+ /// @}
+ /// @name Section Layout Data
+ /// @{
+
+ /// \brief Get the computed address of the given section.
uint64_t getSectionAddress(const MCSectionData *SD) const;
+ /// \brief Set the computed address of the given section.
+ void setSectionAddress(MCSectionData *SD, uint64_t Value);
+
+ /// \brief Get the data size of the given section, as emitted to the object
+ /// file. This may include additional padding, or be 0 for virtual sections.
+ uint64_t getSectionFileSize(const MCSectionData *SD) const;
+
+ /// \brief Set the data size of the given section.
+ void setSectionFileSize(MCSectionData *SD, uint64_t Value);
+
+ /// \brief Get the actual data size of the given section.
+ uint64_t getSectionSize(const MCSectionData *SD) const;
+
+ /// \brief Set the actual data size of the given section.
+ void setSectionSize(MCSectionData *SD, uint64_t Value);
+
+ /// @}
+ /// @name Utility Functions
+ /// @{
+
+ /// \brief Get the address of the given fragment, as computed in the current
+ /// layout.
+ uint64_t getFragmentAddress(const MCFragment *F) const;
+
+ /// \brief Get the address of the given symbol, as computed in the current
+ /// layout.
uint64_t getSymbolAddress(const MCSymbolData *SD) const;
- void setSectionAddress(MCSectionData *SD, uint64_t Value);
+ /// @}
};
} // end namespace llvm
unsigned getAlignment() const { return Alignment; }
void setAlignment(unsigned Value) { Alignment = Value; }
+ bool hasInstructions() const { return HasInstructions; }
+ void setHasInstructions(bool Value) { HasInstructions = Value; }
+
/// @name Fragment Access
/// @{
bool empty() const { return Fragments.empty(); }
- /// @}
- /// @name Assembler Backend Support
- /// @{
- //
- // FIXME: This could all be kept private to the assembler implementation.
-
- uint64_t getSize() const {
- assert(Size != ~UINT64_C(0) && "File size not set!");
- return Size;
- }
- void setSize(uint64_t Value) { Size = Value; }
-
- uint64_t getFileSize() const {
- assert(FileSize != ~UINT64_C(0) && "File size not set!");
- return FileSize;
- }
- void setFileSize(uint64_t Value) { FileSize = Value; }
-
- bool hasInstructions() const { return HasInstructions; }
- void setHasInstructions(bool Value) { HasInstructions = Value; }
-
- /// @}
-
void dump();
};
SD->Address = Value;
}
+uint64_t MCAsmLayout::getSectionSize(const MCSectionData *SD) const {
+ assert(SD->Size != ~UINT64_C(0) && "File size not set!");
+ return SD->Size;
+}
+void MCAsmLayout::setSectionSize(MCSectionData *SD, uint64_t Value) {
+ SD->Size = Value;
+}
+
+uint64_t MCAsmLayout::getSectionFileSize(const MCSectionData *SD) const {
+ assert(SD->FileSize != ~UINT64_C(0) && "File size not set!");
+ return SD->FileSize;
+}
+void MCAsmLayout::setSectionFileSize(MCSectionData *SD, uint64_t Value) {
+ SD->FileSize = Value;
+}
+
+ /// @}
+
/* *** */
MCFragment::MCFragment() : Kind(FragmentType(~0)) {
}
// Set the section sizes.
- SD.setSize(Address - StartAddress);
+ Layout.setSectionSize(&SD, Address - StartAddress);
if (getBackend().isVirtualSection(SD.getSection()))
- SD.setFileSize(0);
+ Layout.setSectionFileSize(&SD, 0);
else
- SD.setFileSize(Address - StartAddress);
+ Layout.setSectionFileSize(&SD, Address - StartAddress);
}
/// WriteFragmentData - Write the \arg F data to the output file.
void MCAssembler::WriteSectionData(const MCSectionData *SD,
const MCAsmLayout &Layout,
MCObjectWriter *OW) const {
+ uint64_t SectionSize = Layout.getSectionSize(SD);
+ uint64_t SectionFileSize = Layout.getSectionFileSize(SD);
+
// Ignore virtual sections.
if (getBackend().isVirtualSection(SD->getSection())) {
- assert(SD->getFileSize() == 0);
+ assert(SectionFileSize == 0 && "Invalid size for section!");
return;
}
WriteFragmentData(*this, Layout, *it, OW);
// Add section padding.
- assert(SD->getFileSize() >= SD->getSize() && "Invalid section sizes!");
- OW->WriteZeros(SD->getFileSize() - SD->getSize());
+ assert(SectionFileSize >= SectionSize && "Invalid section sizes!");
+ OW->WriteZeros(SectionFileSize - SectionSize);
- assert(OW->getStream().tell() - Start == SD->getFileSize());
+ assert(OW->getStream().tell() - Start == SectionFileSize);
}
void MCAssembler::Finish() {
// section.
if (uint64_t Pad = OffsetToAlignment(Address, it->getAlignment())) {
assert(Prev && "Missing prev section!");
- Prev->setFileSize(Prev->getFileSize() + Pad);
+ Layout.setSectionFileSize(Prev, Layout.getSectionFileSize(Prev) + Pad);
Address += Pad;
}
// Layout the section fragments and its size.
Layout.setSectionAddress(&SD, Address);
LayoutSection(SD, Layout);
- Address += SD.getFileSize();
+ Address += Layout.getSectionFileSize(&SD);
Prev = &SD;
}
Layout.setSectionAddress(&SD, Address);
LayoutSection(SD, Layout);
- Address += SD.getSize();
+ Address += Layout.getSectionSize(&SD);
}
// Scan for fragments that need relaxation.
void WriteSection(const MCAssembler &Asm, const MCAsmLayout &Layout,
const MCSectionData &SD, uint64_t FileOffset,
uint64_t RelocationsStart, unsigned NumRelocations) {
+ uint64_t SectionSize = Layout.getSectionSize(&SD);
+ uint64_t SectionFileSize = Layout.getSectionFileSize(&SD);
+
// The offset is unused for virtual sections.
if (Asm.getBackend().isVirtualSection(SD.getSection())) {
- assert(SD.getFileSize() == 0 && "Invalid file size!");
+ assert(SectionFileSize == 0 && "Invalid file size!");
FileOffset = 0;
}
WriteBytes(Section.getSegmentName(), 16);
if (Is64Bit) {
Write64(Layout.getSectionAddress(&SD)); // address
- Write64(SD.getSize()); // size
+ Write64(SectionSize); // size
} else {
Write32(Layout.getSectionAddress(&SD)); // address
- Write32(SD.getSize()); // size
+ Write32(SectionSize); // size
}
Write32(FileOffset);
ie = Asm.end(); it != ie; ++it) {
const MCSectionData &SD = *it;
uint64_t Address = Layout.getSectionAddress(&SD);
+ uint64_t Size = Layout.getSectionSize(&SD);
+ uint64_t FileSize = Layout.getSectionFileSize(&SD);
- VMSize = std::max(VMSize, Address + SD.getSize());
+ VMSize = std::max(VMSize, Address + Size);
if (Asm.getBackend().isVirtualSection(SD.getSection()))
continue;
- SectionDataSize = std::max(SectionDataSize, Address + SD.getSize());
- SectionDataFileSize = std::max(SectionDataFileSize,
- Address + SD.getFileSize());
+ SectionDataSize = std::max(SectionDataSize, Address + Size);
+ SectionDataFileSize = std::max(SectionDataFileSize, Address + FileSize);
}
// The section data is padded to 4 bytes.