1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 11:42:57 +01:00

MC: Add TargetAsmBackend::isVirtualSection hook.

llvm-svn: 98950
This commit is contained in:
Daniel Dunbar 2010-03-19 09:29:03 +00:00
parent c9bcbc86a8
commit 287ff291e3
3 changed files with 34 additions and 17 deletions

View File

@ -80,6 +80,10 @@ public:
return false; return false;
} }
/// isVirtualSection - Check whether the given section is "virtual", that is
/// has no actual object file contents.
virtual bool isVirtualSection(const MCSection &Section) const = 0;
/// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided /// ApplyFixup - Apply the \arg Value for given \arg Fixup into the provided
/// data fragment, at the offset specified by the fixup and following the /// data fragment, at the offset specified by the fixup and following the
/// fixup kind as appropriate. /// fixup kind as appropriate.

View File

@ -43,14 +43,6 @@ STATISTIC(EmittedFragments, "Number of emitted assembler fragments");
// object file, which may truncate it. We should detect that truncation where // object file, which may truncate it. We should detect that truncation where
// invalid and report errors back. // invalid and report errors back.
/// isVirtualSection - Check if this is a section which does not actually exist
/// in the object file.
static bool isVirtualSection(const MCSection &Section) {
// FIXME: Lame.
const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
return (SMO.getType() == MCSectionMachO::S_ZEROFILL);
}
static unsigned getFixupKindLog2Size(unsigned Kind) { static unsigned getFixupKindLog2Size(unsigned Kind) {
switch (Kind) { switch (Kind) {
default: llvm_unreachable("invalid fixup kind!"); default: llvm_unreachable("invalid fixup kind!");
@ -264,7 +256,7 @@ public:
uint64_t FileOffset, uint64_t RelocationsStart, uint64_t FileOffset, uint64_t RelocationsStart,
unsigned NumRelocations) { unsigned NumRelocations) {
// The offset is unused for virtual sections. // The offset is unused for virtual sections.
if (isVirtualSection(SD.getSection())) { if (Asm.getBackend().isVirtualSection(SD.getSection())) {
assert(SD.getFileSize() == 0 && "Invalid file size!"); assert(SD.getFileSize() == 0 && "Invalid file size!");
FileOffset = 0; FileOffset = 0;
} }
@ -748,7 +740,7 @@ public:
VMSize = std::max(VMSize, SD.getAddress() + SD.getSize()); VMSize = std::max(VMSize, SD.getAddress() + SD.getSize());
if (isVirtualSection(SD.getSection())) if (Asm.getBackend().isVirtualSection(SD.getSection()))
continue; continue;
SectionDataSize = std::max(SectionDataSize, SectionDataSize = std::max(SectionDataSize,
@ -776,7 +768,7 @@ public:
std::vector<MachRelocationEntry> &Relocs = Relocations[it]; std::vector<MachRelocationEntry> &Relocs = Relocations[it];
unsigned NumRelocs = Relocs.size(); unsigned NumRelocs = Relocs.size();
uint64_t SectionStart = SectionDataStart + it->getAddress(); uint64_t SectionStart = SectionDataStart + it->getAddress();
WriteSection(*it, SectionStart, RelocTableEnd, NumRelocs); WriteSection(Asm, *it, SectionStart, RelocTableEnd, NumRelocs);
RelocTableEnd += NumRelocs * RelocationInfoSize; RelocTableEnd += NumRelocs * RelocationInfoSize;
} }
@ -1194,7 +1186,7 @@ void MCAssembler::LayoutSection(MCSectionData &SD) {
// Set the section sizes. // Set the section sizes.
SD.setSize(Address - SD.getAddress()); SD.setSize(Address - SD.getAddress());
if (isVirtualSection(SD.getSection())) if (getBackend().isVirtualSection(SD.getSection()))
SD.setFileSize(0); SD.setFileSize(0);
else else
SD.setFileSize(Address - SD.getAddress()); SD.setFileSize(Address - SD.getAddress());
@ -1342,7 +1334,7 @@ static void WriteFragmentData(const MCFragment &F, MCObjectWriter *OW) {
void MCAssembler::WriteSectionData(const MCSectionData *SD, void MCAssembler::WriteSectionData(const MCSectionData *SD,
MCObjectWriter *OW) const { MCObjectWriter *OW) const {
// Ignore virtual sections. // Ignore virtual sections.
if (isVirtualSection(SD->getSection())) { if (getBackend().isVirtualSection(SD->getSection())) {
assert(SD->getFileSize() == 0); assert(SD->getFileSize() == 0);
return; return;
} }
@ -1444,7 +1436,7 @@ bool MCAssembler::LayoutOnce() {
MCSectionData &SD = *it; MCSectionData &SD = *it;
// Skip virtual sections. // Skip virtual sections.
if (isVirtualSection(SD.getSection())) if (getBackend().isVirtualSection(SD.getSection()))
continue; continue;
// Align this section if necessary by adding padding bytes to the previous // Align this section if necessary by adding padding bytes to the previous
@ -1467,7 +1459,7 @@ bool MCAssembler::LayoutOnce() {
for (iterator it = begin(), ie = end(); it != ie; ++it) { for (iterator it = begin(), ie = end(); it != ie; ++it) {
MCSectionData &SD = *it; MCSectionData &SD = *it;
if (!isVirtualSection(SD.getSection())) if (!getBackend().isVirtualSection(SD.getSection()))
continue; continue;
// Align this section if necessary by adding padding bytes to the previous // Align this section if necessary by adding padding bytes to the previous

View File

@ -11,6 +11,7 @@
#include "X86.h" #include "X86.h"
#include "X86FixupKinds.h" #include "X86FixupKinds.h"
#include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCAssembler.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h" #include "llvm/MC/MCSectionMachO.h"
#include "llvm/Target/TargetRegistry.h" #include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetAsmBackend.h" #include "llvm/Target/TargetAsmBackend.h"
@ -48,6 +49,20 @@ public:
} }
}; };
class ELFX86AsmBackend : public X86AsmBackend {
public:
ELFX86AsmBackend(const Target &T)
: X86AsmBackend(T) {
HasAbsolutizedSet = true;
HasScatteredSymbols = true;
}
bool isVirtualSection(const MCSection &Section) const {
const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
return SE.getType() == MCSectionELF::SHT_NOBITS;;
}
};
class DarwinX86AsmBackend : public X86AsmBackend { class DarwinX86AsmBackend : public X86AsmBackend {
public: public:
DarwinX86AsmBackend(const Target &T) DarwinX86AsmBackend(const Target &T)
@ -55,6 +70,12 @@ public:
HasAbsolutizedSet = true; HasAbsolutizedSet = true;
HasScatteredSymbols = true; HasScatteredSymbols = true;
} }
bool isVirtualSection(const MCSection &Section) const {
const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
return (SMO.getType() == MCSectionMachO::S_ZEROFILL ||
SMO.getType() == MCSectionMachO::S_GB_ZEROFILL);
}
}; };
class DarwinX86_32AsmBackend : public DarwinX86AsmBackend { class DarwinX86_32AsmBackend : public DarwinX86AsmBackend {
@ -92,7 +113,7 @@ TargetAsmBackend *llvm::createX86_32AsmBackend(const Target &T,
case Triple::Darwin: case Triple::Darwin:
return new DarwinX86_32AsmBackend(T); return new DarwinX86_32AsmBackend(T);
default: default:
return new X86AsmBackend(T); return new ELFX86AsmBackend(T);
} }
} }
@ -102,6 +123,6 @@ TargetAsmBackend *llvm::createX86_64AsmBackend(const Target &T,
case Triple::Darwin: case Triple::Darwin:
return new DarwinX86_64AsmBackend(T); return new DarwinX86_64AsmBackend(T);
default: default:
return new X86AsmBackend(T); return new ELFX86AsmBackend(T);
} }
} }