[llvm-commits] [llvm] r98950 - in /llvm/trunk: include/llvm/Target/TargetAsmBackend.h lib/MC/MCAssembler.cpp lib/Target/X86/X86AsmBackend.cpp
Daniel Dunbar
daniel at zuster.org
Fri Mar 19 02:29:03 PDT 2010
Author: ddunbar
Date: Fri Mar 19 04:29:03 2010
New Revision: 98950
URL: http://llvm.org/viewvc/llvm-project?rev=98950&view=rev
Log:
MC: Add TargetAsmBackend::isVirtualSection hook.
Modified:
llvm/trunk/include/llvm/Target/TargetAsmBackend.h
llvm/trunk/lib/MC/MCAssembler.cpp
llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
Modified: llvm/trunk/include/llvm/Target/TargetAsmBackend.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmBackend.h?rev=98950&r1=98949&r2=98950&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmBackend.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmBackend.h Fri Mar 19 04:29:03 2010
@@ -80,6 +80,10 @@
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
/// data fragment, at the offset specified by the fixup and following the
/// fixup kind as appropriate.
Modified: llvm/trunk/lib/MC/MCAssembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAssembler.cpp?rev=98950&r1=98949&r2=98950&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAssembler.cpp (original)
+++ llvm/trunk/lib/MC/MCAssembler.cpp Fri Mar 19 04:29:03 2010
@@ -43,14 +43,6 @@
// 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!");
@@ -264,7 +256,7 @@
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;
}
@@ -748,7 +740,7 @@
VMSize = std::max(VMSize, SD.getAddress() + SD.getSize());
- if (isVirtualSection(SD.getSection()))
+ if (Asm.getBackend().isVirtualSection(SD.getSection()))
continue;
SectionDataSize = std::max(SectionDataSize,
@@ -776,7 +768,7 @@
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;
}
@@ -1194,7 +1186,7 @@
// 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());
@@ -1342,7 +1334,7 @@
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;
}
@@ -1444,7 +1436,7 @@
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
@@ -1467,7 +1459,7 @@
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
Modified: llvm/trunk/lib/Target/X86/X86AsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86AsmBackend.cpp?rev=98950&r1=98949&r2=98950&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86AsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86AsmBackend.cpp Fri Mar 19 04:29:03 2010
@@ -11,6 +11,7 @@
#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"
@@ -48,6 +49,20 @@
}
};
+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)
@@ -55,6 +70,12 @@
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 {
@@ -92,7 +113,7 @@
case Triple::Darwin:
return new DarwinX86_32AsmBackend(T);
default:
- return new X86AsmBackend(T);
+ return new ELFX86AsmBackend(T);
}
}
@@ -102,6 +123,6 @@
case Triple::Darwin:
return new DarwinX86_64AsmBackend(T);
default:
- return new X86AsmBackend(T);
+ return new ELFX86AsmBackend(T);
}
}
More information about the llvm-commits
mailing list