// object file, which may truncate it. We should detect that truncation where
// 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) {
switch (Kind) {
default: llvm_unreachable("invalid fixup kind!");
uint64_t FileOffset, uint64_t RelocationsStart,
unsigned NumRelocations) {
// The offset is unused for virtual sections.
- if (isVirtualSection(SD.getSection())) {
+ if (Asm.getBackend().isVirtualSection(SD.getSection())) {
assert(SD.getFileSize() == 0 && "Invalid file size!");
FileOffset = 0;
}
VMSize = std::max(VMSize, SD.getAddress() + SD.getSize());
- if (isVirtualSection(SD.getSection()))
+ if (Asm.getBackend().isVirtualSection(SD.getSection()))
continue;
SectionDataSize = std::max(SectionDataSize,
std::vector<MachRelocationEntry> &Relocs = Relocations[it];
unsigned NumRelocs = Relocs.size();
uint64_t SectionStart = SectionDataStart + it->getAddress();
- WriteSection(*it, SectionStart, RelocTableEnd, NumRelocs);
+ WriteSection(Asm, *it, SectionStart, RelocTableEnd, NumRelocs);
RelocTableEnd += NumRelocs * RelocationInfoSize;
}
// Set the section sizes.
SD.setSize(Address - SD.getAddress());
- if (isVirtualSection(SD.getSection()))
+ if (getBackend().isVirtualSection(SD.getSection()))
SD.setFileSize(0);
else
SD.setFileSize(Address - SD.getAddress());
void MCAssembler::WriteSectionData(const MCSectionData *SD,
MCObjectWriter *OW) const {
// Ignore virtual sections.
- if (isVirtualSection(SD->getSection())) {
+ if (getBackend().isVirtualSection(SD->getSection())) {
assert(SD->getFileSize() == 0);
return;
}
MCSectionData &SD = *it;
// Skip virtual sections.
- if (isVirtualSection(SD.getSection()))
+ if (getBackend().isVirtualSection(SD.getSection()))
continue;
// Align this section if necessary by adding padding bytes to the previous
for (iterator it = begin(), ie = end(); it != ie; ++it) {
MCSectionData &SD = *it;
- if (!isVirtualSection(SD.getSection()))
+ if (!getBackend().isVirtualSection(SD.getSection()))
continue;
// Align this section if necessary by adding padding bytes to the previous
#include "X86.h"
#include "X86FixupKinds.h"
#include "llvm/MC/MCAssembler.h"
+#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCSectionMachO.h"
#include "llvm/Target/TargetRegistry.h"
#include "llvm/Target/TargetAsmBackend.h"
}
};
+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 {
public:
DarwinX86AsmBackend(const Target &T)
HasAbsolutizedSet = 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 {
case Triple::Darwin:
return new DarwinX86_32AsmBackend(T);
default:
- return new X86AsmBackend(T);
+ return new ELFX86AsmBackend(T);
}
}
case Triple::Darwin:
return new DarwinX86_64AsmBackend(T);
default:
- return new X86AsmBackend(T);
+ return new ELFX86AsmBackend(T);
}
}