mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-23 01:24:30 +00:00
Stop using MCSectionData in MCAsmLayout.h.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@238170 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -16,7 +16,7 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
class MCAssembler;
|
class MCAssembler;
|
||||||
class MCFragment;
|
class MCFragment;
|
||||||
class MCSectionData;
|
class MCSection;
|
||||||
class MCSymbol;
|
class MCSymbol;
|
||||||
class MCSymbolData;
|
class MCSymbolData;
|
||||||
|
|
||||||
@ -31,12 +31,12 @@ class MCAsmLayout {
|
|||||||
MCAssembler &Assembler;
|
MCAssembler &Assembler;
|
||||||
|
|
||||||
/// List of sections in layout order.
|
/// List of sections in layout order.
|
||||||
llvm::SmallVector<MCSectionData *, 16> SectionOrder;
|
llvm::SmallVector<MCSection *, 16> SectionOrder;
|
||||||
|
|
||||||
/// The last fragment which was laid out, or 0 if nothing has been laid
|
/// The last fragment which was laid out, or 0 if nothing has been laid
|
||||||
/// out. Fragments are always laid out in order, so all fragments with a
|
/// out. Fragments are always laid out in order, so all fragments with a
|
||||||
/// lower ordinal will be valid.
|
/// lower ordinal will be valid.
|
||||||
mutable DenseMap<const MCSectionData *, MCFragment *> LastValidFragment;
|
mutable DenseMap<const MCSection *, MCFragment *> LastValidFragment;
|
||||||
|
|
||||||
/// \brief Make sure that the layout for the given fragment is valid, lazily
|
/// \brief Make sure that the layout for the given fragment is valid, lazily
|
||||||
/// computing it if necessary.
|
/// computing it if necessary.
|
||||||
@ -64,10 +64,8 @@ public:
|
|||||||
/// \name Section Access (in layout order)
|
/// \name Section Access (in layout order)
|
||||||
/// @{
|
/// @{
|
||||||
|
|
||||||
llvm::SmallVectorImpl<MCSectionData *> &getSectionOrder() {
|
llvm::SmallVectorImpl<MCSection *> &getSectionOrder() { return SectionOrder; }
|
||||||
return SectionOrder;
|
const llvm::SmallVectorImpl<MCSection *> &getSectionOrder() const {
|
||||||
}
|
|
||||||
const llvm::SmallVectorImpl<MCSectionData *> &getSectionOrder() const {
|
|
||||||
return SectionOrder;
|
return SectionOrder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,11 +83,11 @@ public:
|
|||||||
/// \brief Get the address space size of the given section, as it effects
|
/// \brief Get the address space size of the given section, as it effects
|
||||||
/// layout. This may differ from the size reported by \see getSectionSize() by
|
/// layout. This may differ from the size reported by \see getSectionSize() by
|
||||||
/// not including section tail padding.
|
/// not including section tail padding.
|
||||||
uint64_t getSectionAddressSize(const MCSectionData *SD) const;
|
uint64_t getSectionAddressSize(const MCSection *Sec) const;
|
||||||
|
|
||||||
/// \brief Get the data size of the given section, as emitted to the object
|
/// \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.
|
/// file. This may include additional padding, or be 0 for virtual sections.
|
||||||
uint64_t getSectionFileSize(const MCSectionData *SD) const;
|
uint64_t getSectionFileSize(const MCSection *Sec) const;
|
||||||
|
|
||||||
/// \brief Get the offset of the given symbol, as computed in the current
|
/// \brief Get the offset of the given symbol, as computed in the current
|
||||||
/// layout.
|
/// layout.
|
||||||
|
@ -210,6 +210,11 @@ public:
|
|||||||
return const_cast<MCSection *>(this)->end();
|
return const_cast<MCSection *>(this)->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MCSectionData::reverse_iterator rbegin();
|
||||||
|
MCSectionData::const_reverse_iterator rbegin() const {
|
||||||
|
return const_cast<MCSection *>(this)->rbegin();
|
||||||
|
}
|
||||||
|
|
||||||
MCSectionData::reverse_iterator rend();
|
MCSectionData::reverse_iterator rend();
|
||||||
MCSectionData::const_reverse_iterator rend() const {
|
MCSectionData::const_reverse_iterator rend() const {
|
||||||
return const_cast<MCSection *>(this)->rend();
|
return const_cast<MCSection *>(this)->rend();
|
||||||
|
@ -1314,12 +1314,10 @@ void ELFObjectWriter::writeSectionHeader(
|
|||||||
const std::pair<uint64_t, uint64_t> &Offsets =
|
const std::pair<uint64_t, uint64_t> &Offsets =
|
||||||
SectionOffsets.find(Section)->second;
|
SectionOffsets.find(Section)->second;
|
||||||
uint64_t Size;
|
uint64_t Size;
|
||||||
if (Type == ELF::SHT_NOBITS) {
|
if (Type == ELF::SHT_NOBITS)
|
||||||
const MCSectionData &SD = Asm.getSectionData(*Section);
|
Size = Layout.getSectionAddressSize(Section);
|
||||||
Size = Layout.getSectionAddressSize(&SD);
|
else
|
||||||
} else {
|
|
||||||
Size = Offsets.second - Offsets.first;
|
Size = Offsets.second - Offsets.first;
|
||||||
}
|
|
||||||
|
|
||||||
writeSection(SectionIndexMap, GroupSymbolIndex, Offsets.first, Size,
|
writeSection(SectionIndexMap, GroupSymbolIndex, Offsets.first, Size,
|
||||||
*Section);
|
*Section);
|
||||||
|
@ -70,18 +70,18 @@ MCAsmLayout::MCAsmLayout(MCAssembler &Asm)
|
|||||||
// Compute the section layout order. Virtual sections must go last.
|
// Compute the section layout order. Virtual sections must go last.
|
||||||
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
|
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
|
||||||
if (!it->isVirtualSection())
|
if (!it->isVirtualSection())
|
||||||
SectionOrder.push_back(&it->getSectionData());
|
SectionOrder.push_back(&*it);
|
||||||
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
|
for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
|
||||||
if (it->isVirtualSection())
|
if (it->isVirtualSection())
|
||||||
SectionOrder.push_back(&it->getSectionData());
|
SectionOrder.push_back(&*it);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MCAsmLayout::isFragmentValid(const MCFragment *F) const {
|
bool MCAsmLayout::isFragmentValid(const MCFragment *F) const {
|
||||||
const MCSectionData &SD = F->getParent()->getSectionData();
|
const MCSection *Sec = F->getParent();
|
||||||
const MCFragment *LastValid = LastValidFragment.lookup(&SD);
|
const MCFragment *LastValid = LastValidFragment.lookup(Sec);
|
||||||
if (!LastValid)
|
if (!LastValid)
|
||||||
return false;
|
return false;
|
||||||
assert(LastValid->getParent() == F->getParent());
|
assert(LastValid->getParent() == Sec);
|
||||||
return F->getLayoutOrder() <= LastValid->getLayoutOrder();
|
return F->getLayoutOrder() <= LastValid->getLayoutOrder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,16 +92,14 @@ void MCAsmLayout::invalidateFragmentsFrom(MCFragment *F) {
|
|||||||
|
|
||||||
// Otherwise, reset the last valid fragment to the previous fragment
|
// Otherwise, reset the last valid fragment to the previous fragment
|
||||||
// (if this is the first fragment, it will be NULL).
|
// (if this is the first fragment, it will be NULL).
|
||||||
const MCSectionData &SD = F->getParent()->getSectionData();
|
LastValidFragment[F->getParent()] = F->getPrevNode();
|
||||||
LastValidFragment[&SD] = F->getPrevNode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCAsmLayout::ensureValid(const MCFragment *F) const {
|
void MCAsmLayout::ensureValid(const MCFragment *F) const {
|
||||||
MCSectionData &SD = F->getParent()->getSectionData();
|
MCSection *Sec = F->getParent();
|
||||||
|
MCFragment *Cur = LastValidFragment[Sec];
|
||||||
MCFragment *Cur = LastValidFragment[&SD];
|
|
||||||
if (!Cur)
|
if (!Cur)
|
||||||
Cur = &*SD.begin();
|
Cur = Sec->begin();
|
||||||
else
|
else
|
||||||
Cur = Cur->getNextNode();
|
Cur = Cur->getNextNode();
|
||||||
|
|
||||||
@ -208,19 +206,19 @@ const MCSymbol *MCAsmLayout::getBaseSymbol(const MCSymbol &Symbol) const {
|
|||||||
return &ASym;
|
return &ASym;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t MCAsmLayout::getSectionAddressSize(const MCSectionData *SD) const {
|
uint64_t MCAsmLayout::getSectionAddressSize(const MCSection *Sec) const {
|
||||||
// The size is the last fragment's end offset.
|
// The size is the last fragment's end offset.
|
||||||
const MCFragment &F = SD->getFragmentList().back();
|
const MCFragment &F = Sec->getFragmentList().back();
|
||||||
return getFragmentOffset(&F) + getAssembler().computeFragmentSize(*this, F);
|
return getFragmentOffset(&F) + getAssembler().computeFragmentSize(*this, F);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t MCAsmLayout::getSectionFileSize(const MCSectionData *SD) const {
|
uint64_t MCAsmLayout::getSectionFileSize(const MCSection *Sec) const {
|
||||||
// Virtual sections have no file size.
|
// Virtual sections have no file size.
|
||||||
if (SD->getSection().isVirtualSection())
|
if (Sec->isVirtualSection())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
// Otherwise, the file size is the same as the address space size.
|
// Otherwise, the file size is the same as the address space size.
|
||||||
return getSectionAddressSize(SD);
|
return getSectionAddressSize(Sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler,
|
uint64_t llvm::computeBundlePadding(const MCAssembler &Assembler,
|
||||||
@ -568,7 +566,7 @@ void MCAsmLayout::layoutFragment(MCFragment *F) {
|
|||||||
F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev);
|
F->Offset = Prev->Offset + getAssembler().computeFragmentSize(*this, *Prev);
|
||||||
else
|
else
|
||||||
F->Offset = 0;
|
F->Offset = 0;
|
||||||
LastValidFragment[&F->getParent()->getSectionData()] = F;
|
LastValidFragment[F->getParent()] = F;
|
||||||
|
|
||||||
// If bundling is enabled and this fragment has instructions in it, it has to
|
// If bundling is enabled and this fragment has instructions in it, it has to
|
||||||
// obey the bundling restrictions. With padding, we'll have:
|
// obey the bundling restrictions. With padding, we'll have:
|
||||||
@ -773,8 +771,9 @@ static void writeFragment(const MCAssembler &Asm, const MCAsmLayout &Layout,
|
|||||||
void MCAssembler::writeSectionData(const MCSectionData *SD,
|
void MCAssembler::writeSectionData(const MCSectionData *SD,
|
||||||
const MCAsmLayout &Layout) const {
|
const MCAsmLayout &Layout) const {
|
||||||
// Ignore virtual sections.
|
// Ignore virtual sections.
|
||||||
if (SD->getSection().isVirtualSection()) {
|
const MCSection &Sec = SD->getSection();
|
||||||
assert(Layout.getSectionFileSize(SD) == 0 && "Invalid size for section!");
|
if (Sec.isVirtualSection()) {
|
||||||
|
assert(Layout.getSectionFileSize(&Sec) == 0 && "Invalid size for section!");
|
||||||
|
|
||||||
// Check that contents are only things legal inside a virtual section.
|
// Check that contents are only things legal inside a virtual section.
|
||||||
for (MCSectionData::const_iterator it = SD->begin(),
|
for (MCSectionData::const_iterator it = SD->begin(),
|
||||||
@ -824,7 +823,7 @@ void MCAssembler::writeSectionData(const MCSectionData *SD,
|
|||||||
writeFragment(*this, Layout, *it);
|
writeFragment(*this, Layout, *it);
|
||||||
|
|
||||||
assert(getWriter().getStream().tell() - Start ==
|
assert(getWriter().getStream().tell() - Start ==
|
||||||
Layout.getSectionAddressSize(SD));
|
Layout.getSectionAddressSize(&SD->getSection()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<uint64_t, bool> MCAssembler::handleFixup(const MCAsmLayout &Layout,
|
std::pair<uint64_t, bool> MCAssembler::handleFixup(const MCAsmLayout &Layout,
|
||||||
@ -866,11 +865,11 @@ void MCAssembler::Finish() {
|
|||||||
|
|
||||||
// Assign layout order indices to sections and fragments.
|
// Assign layout order indices to sections and fragments.
|
||||||
for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {
|
for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {
|
||||||
MCSectionData *SD = Layout.getSectionOrder()[i];
|
MCSection *Sec = Layout.getSectionOrder()[i];
|
||||||
SD->getSection().setLayoutOrder(i);
|
Sec->setLayoutOrder(i);
|
||||||
|
|
||||||
unsigned FragmentIndex = 0;
|
unsigned FragmentIndex = 0;
|
||||||
for (MCSectionData::iterator iFrag = SD->begin(), iFragEnd = SD->end();
|
for (MCSectionData::iterator iFrag = Sec->begin(), iFragEnd = Sec->end();
|
||||||
iFrag != iFragEnd; ++iFrag)
|
iFrag != iFragEnd; ++iFrag)
|
||||||
iFrag->setLayoutOrder(FragmentIndex++);
|
iFrag->setLayoutOrder(FragmentIndex++);
|
||||||
}
|
}
|
||||||
|
@ -56,6 +56,8 @@ MCSectionData::iterator MCSection::begin() { return Data.begin(); }
|
|||||||
|
|
||||||
MCSectionData::iterator MCSection::end() { return Data.end(); }
|
MCSectionData::iterator MCSection::end() { return Data.end(); }
|
||||||
|
|
||||||
|
MCSectionData::reverse_iterator MCSection::rbegin() { return Data.rbegin(); }
|
||||||
|
|
||||||
MCSectionData::FragmentListType &MCSection::getFragmentList() {
|
MCSectionData::FragmentListType &MCSection::getFragmentList() {
|
||||||
return Data.getFragmentList();
|
return Data.getFragmentList();
|
||||||
}
|
}
|
||||||
|
@ -107,16 +107,15 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S,
|
|||||||
|
|
||||||
uint64_t MachObjectWriter::getPaddingSize(const MCSection *Sec,
|
uint64_t MachObjectWriter::getPaddingSize(const MCSection *Sec,
|
||||||
const MCAsmLayout &Layout) const {
|
const MCAsmLayout &Layout) const {
|
||||||
uint64_t EndAddr = getSectionAddress(Sec) +
|
uint64_t EndAddr = getSectionAddress(Sec) + Layout.getSectionAddressSize(Sec);
|
||||||
Layout.getSectionAddressSize(&Sec->getSectionData());
|
|
||||||
unsigned Next = Sec->getLayoutOrder() + 1;
|
unsigned Next = Sec->getLayoutOrder() + 1;
|
||||||
if (Next >= Layout.getSectionOrder().size())
|
if (Next >= Layout.getSectionOrder().size())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
const MCSectionData &NextSD = *Layout.getSectionOrder()[Next];
|
const MCSection &NextSec = *Layout.getSectionOrder()[Next];
|
||||||
if (NextSD.getSection().isVirtualSection())
|
if (NextSec.isVirtualSection())
|
||||||
return 0;
|
return 0;
|
||||||
return OffsetToAlignment(EndAddr, NextSD.getSection().getAlignment());
|
return OffsetToAlignment(EndAddr, NextSec.getAlignment());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachObjectWriter::WriteHeader(unsigned NumLoadCommands,
|
void MachObjectWriter::WriteHeader(unsigned NumLoadCommands,
|
||||||
@ -199,12 +198,12 @@ void MachObjectWriter::WriteSection(const MCAssembler &Asm,
|
|||||||
uint64_t RelocationsStart,
|
uint64_t RelocationsStart,
|
||||||
unsigned NumRelocations) {
|
unsigned NumRelocations) {
|
||||||
const MCSectionData &SD = Sec.getSectionData();
|
const MCSectionData &SD = Sec.getSectionData();
|
||||||
uint64_t SectionSize = Layout.getSectionAddressSize(&SD);
|
uint64_t SectionSize = Layout.getSectionAddressSize(&Sec);
|
||||||
const MCSectionMachO &Section = cast<MCSectionMachO>(Sec);
|
const MCSectionMachO &Section = cast<MCSectionMachO>(Sec);
|
||||||
|
|
||||||
// The offset is unused for virtual sections.
|
// The offset is unused for virtual sections.
|
||||||
if (Section.isVirtualSection()) {
|
if (Section.isVirtualSection()) {
|
||||||
assert(Layout.getSectionFileSize(&SD) == 0 && "Invalid file size!");
|
assert(Layout.getSectionFileSize(&Sec) == 0 && "Invalid file size!");
|
||||||
FileOffset = 0;
|
FileOffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -645,18 +644,17 @@ void MachObjectWriter::ComputeSymbolTable(
|
|||||||
void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm,
|
void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm,
|
||||||
const MCAsmLayout &Layout) {
|
const MCAsmLayout &Layout) {
|
||||||
uint64_t StartAddress = 0;
|
uint64_t StartAddress = 0;
|
||||||
const SmallVectorImpl<MCSectionData*> &Order = Layout.getSectionOrder();
|
const SmallVectorImpl<MCSection *> &Order = Layout.getSectionOrder();
|
||||||
for (int i = 0, n = Order.size(); i != n ; ++i) {
|
for (int i = 0, n = Order.size(); i != n ; ++i) {
|
||||||
const MCSectionData *SD = Order[i];
|
const MCSection *Sec = Order[i];
|
||||||
StartAddress =
|
StartAddress = RoundUpToAlignment(StartAddress, Sec->getAlignment());
|
||||||
RoundUpToAlignment(StartAddress, SD->getSection().getAlignment());
|
SectionAddress[Sec] = StartAddress;
|
||||||
SectionAddress[&SD->getSection()] = StartAddress;
|
StartAddress += Layout.getSectionAddressSize(Sec);
|
||||||
StartAddress += Layout.getSectionAddressSize(SD);
|
|
||||||
|
|
||||||
// Explicitly pad the section to match the alignment requirements of the
|
// Explicitly pad the section to match the alignment requirements of the
|
||||||
// following one. This is for 'gas' compatibility, it shouldn't
|
// following one. This is for 'gas' compatibility, it shouldn't
|
||||||
/// strictly be necessary.
|
/// strictly be necessary.
|
||||||
StartAddress += getPaddingSize(&SD->getSection(), Layout);
|
StartAddress += getPaddingSize(Sec, Layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -804,11 +802,12 @@ void MachObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
uint64_t VMSize = 0;
|
uint64_t VMSize = 0;
|
||||||
for (MCAssembler::const_iterator it = Asm.begin(),
|
for (MCAssembler::const_iterator it = Asm.begin(),
|
||||||
ie = Asm.end(); it != ie; ++it) {
|
ie = Asm.end(); it != ie; ++it) {
|
||||||
|
const MCSection &Sec = *it;
|
||||||
const MCSectionData &SD = it->getSectionData();
|
const MCSectionData &SD = it->getSectionData();
|
||||||
uint64_t Address = getSectionAddress(&*it);
|
uint64_t Address = getSectionAddress(&Sec);
|
||||||
uint64_t Size = Layout.getSectionAddressSize(&SD);
|
uint64_t Size = Layout.getSectionAddressSize(&Sec);
|
||||||
uint64_t FileSize = Layout.getSectionFileSize(&SD);
|
uint64_t FileSize = Layout.getSectionFileSize(&Sec);
|
||||||
FileSize += getPaddingSize(&*it, Layout);
|
FileSize += getPaddingSize(&Sec, Layout);
|
||||||
|
|
||||||
VMSize = std::max(VMSize, Address + Size);
|
VMSize = std::max(VMSize, Address + Size);
|
||||||
|
|
||||||
|
@ -950,8 +950,7 @@ void WinCOFFObjectWriter::WriteObject(MCAssembler &Asm,
|
|||||||
if (Sec->Number == -1)
|
if (Sec->Number == -1)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Sec->Header.SizeOfRawData =
|
Sec->Header.SizeOfRawData = Layout.getSectionAddressSize(&Section);
|
||||||
Layout.getSectionAddressSize(&Section.getSectionData());
|
|
||||||
|
|
||||||
if (IsPhysicalSection(Sec)) {
|
if (IsPhysicalSection(Sec)) {
|
||||||
// Align the section data to a four byte boundary.
|
// Align the section data to a four byte boundary.
|
||||||
|
Reference in New Issue
Block a user