make isVirtualSection a virtual method on MCSection. Chris' suggestion.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 17 Nov 2010 20:03:54 +0000 (20:03 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 17 Nov 2010 20:03:54 +0000 (20:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@119547 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
include/llvm/MC/MCSection.h
include/llvm/MC/MCSectionCOFF.h
include/llvm/MC/MCSectionELF.h
include/llvm/MC/MCSectionMachO.h
include/llvm/Target/TargetAsmBackend.h
lib/MC/MCAssembler.cpp
lib/MC/MCSectionCOFF.cpp
lib/MC/MCSectionELF.cpp
lib/MC/MCSectionMachO.cpp
lib/MC/MachObjectWriter.cpp
lib/Target/ARM/ARMAsmBackend.cpp
lib/Target/MBlaze/MBlazeAsmBackend.cpp
lib/Target/PowerPC/PPCAsmBackend.cpp
lib/Target/X86/X86AsmBackend.cpp

index b741216f94a4a265d774ef1a483c4aae96a24606..1c01b2f8f3cc659aa455e80733d62ac7b7be3adf 100644 (file)
@@ -64,6 +64,10 @@ namespace llvm {
     // "optimized nops" to fill instead of 0s.
     virtual bool UseCodeAlign() const = 0;
 
+    /// isVirtualSection - Check whether this section is "virtual", that is
+    /// has no actual object file contents.
+    virtual bool isVirtualSection() const = 0;
+
     static bool classof(const MCSection *) { return true; }
   };
 
index 8bf7f448ec53b453ad1fe551d7b028591f23c3b5..b154cf59d106c2c4d9e4a51ef13b58eacd2eeec8 100644 (file)
@@ -56,6 +56,7 @@ namespace llvm {
     virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
                                       raw_ostream &OS) const;
     virtual bool UseCodeAlign() const;
+    virtual bool isVirtualSection() const;
 
     static bool classof(const MCSection *S) {
       return S->getVariant() == SV_COFF;
index 5af538557e58e08a237695a47a2a72db502ce554..9463356db2bf955a16f863347b3851d211c069a8 100644 (file)
@@ -188,6 +188,7 @@ public:
   void PrintSwitchToSection(const MCAsmInfo &MAI,
                             raw_ostream &OS) const;
   virtual bool UseCodeAlign() const;
+  virtual bool isVirtualSection() const;
 
   /// isBaseAddressKnownZero - We know that non-allocatable sections (like
   /// debug info) have a base of zero.
index f409f3253b80466c4cf918a843e058479ea65054..7633515f274426b8069c70baac0c31d1157ca478 100644 (file)
@@ -166,6 +166,7 @@ public:
   virtual void PrintSwitchToSection(const MCAsmInfo &MAI,
                                     raw_ostream &OS) const;
   virtual bool UseCodeAlign() const;
+  virtual bool isVirtualSection() const;
 
   static bool classof(const MCSection *S) {
     return S->getVariant() == SV_MachO;
index b424dea4a56e8feb84420e0989c8e51196693c57..17322d5809364a1760274476a928c5fbcce5f0ce 100644 (file)
@@ -86,10 +86,6 @@ public:
     return true;
   }
 
-  /// isVirtualSection - Check whether the given section is "virtual", that is
-  /// has no actual object file contents.
-  virtual bool isVirtualSection(const MCSection &Section) const = 0;
-
   /// getPointerSize - Get the pointer size in bytes.
   virtual unsigned getPointerSize() const = 0;
 
index c80dc3c2483219908c4ca6e76a3a0c775ae8a775..a23bab25a4d27b2bb487e7d16e8fbeb7a638982c 100644 (file)
@@ -54,10 +54,10 @@ MCAsmLayout::MCAsmLayout(MCAssembler &Asm)
  {
   // Compute the section layout order. Virtual sections must go last.
   for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
-    if (!Asm.getBackend().isVirtualSection(it->getSection()))
+    if (!it->getSection().isVirtualSection())
       SectionOrder.push_back(&*it);
   for (MCAssembler::iterator it = Asm.begin(), ie = Asm.end(); it != ie; ++it)
-    if (Asm.getBackend().isVirtualSection(it->getSection()))
+    if (it->getSection().isVirtualSection())
       SectionOrder.push_back(&*it);
 }
 
@@ -157,7 +157,7 @@ uint64_t MCAsmLayout::getSectionAddressSize(const MCSectionData *SD) const {
 
 uint64_t MCAsmLayout::getSectionFileSize(const MCSectionData *SD) const {
   // Virtual sections have no file size.
-  if (getAssembler().getBackend().isVirtualSection(SD->getSection()))
+  if (SD->getSection().isVirtualSection())
     return 0;
 
   // Otherwise, the file size is the same as the address space size.
@@ -541,7 +541,7 @@ void MCAssembler::WriteSectionData(const MCSectionData *SD,
                                    const MCAsmLayout &Layout,
                                    MCObjectWriter *OW) const {
   // Ignore virtual sections.
-  if (getBackend().isVirtualSection(SD->getSection())) {
+  if (SD->getSection().isVirtualSection()) {
     assert(Layout.getSectionFileSize(SD) == 0 && "Invalid size for section!");
 
     // Check that contents are only things legal inside a virtual section.
@@ -630,7 +630,7 @@ void MCAssembler::Finish(MCObjectWriter *Writer) {
         continue;
 
       // Ignore virtual sections, they don't cause file size modifications.
-      if (getBackend().isVirtualSection(SD->getSection()))
+      if (SD->getSection().isVirtualSection())
         continue;
 
       // Otherwise, create a new align fragment at the end of the previous
index 0909df42227cf4c260d8081716df07fa06c416c2..90091f06e9acd2513e818715bfcd485bdd58b290 100644 (file)
@@ -78,3 +78,7 @@ void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI,
 bool MCSectionCOFF::UseCodeAlign() const {
   return getKind().isText();
 }
+
+bool MCSectionCOFF::isVirtualSection() const {
+  return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
+}
index ab72a0ebf961ed306b56586d0e6bb536a00f27f3..59568adf7085e6d1d1463db7597b59e4aea37e2a 100644 (file)
@@ -107,6 +107,10 @@ bool MCSectionELF::UseCodeAlign() const {
   return getFlags() & MCSectionELF::SHF_EXECINSTR;
 }
 
+bool MCSectionELF::isVirtualSection() const {
+  return getType() == MCSectionELF::SHT_NOBITS;
+}
+
 // HasCommonSymbols - True if this section holds common symbols, this is
 // indicated on the ELF object file by a symbol with SHN_COMMON section 
 // header index.
index 0b74636d422203a6a45fc1348afcc582d7fa894c..43268e63bbd2925612d75eb930db8d6e66ccaaab 100644 (file)
@@ -152,6 +152,12 @@ bool MCSectionMachO::UseCodeAlign() const {
   return hasAttribute(MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS);
 }
 
+bool MCSectionMachO::isVirtualSection() const {
+  return (getType() == MCSectionMachO::S_ZEROFILL ||
+          getType() == MCSectionMachO::S_GB_ZEROFILL ||
+          getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
+}
+
 /// StripSpaces - This removes leading and trailing spaces from the StringRef.
 static void StripSpaces(StringRef &Str) {
   while (!Str.empty() && isspace(Str[0]))
index 41c11fba1d07a1e84bfef1a6b1c8a17835a6bcb8..729a437b18f1c0abeff4818195b72741b8f5a474 100644 (file)
@@ -371,7 +371,7 @@ public:
     uint64_t SectionSize = Layout.getSectionSize(&SD);
 
     // The offset is unused for virtual sections.
-    if (Asm.getBackend().isVirtualSection(SD.getSection())) {
+    if (SD.getSection().isVirtualSection()) {
       assert(Layout.getSectionFileSize(&SD) == 0 && "Invalid file size!");
       FileOffset = 0;
     }
@@ -1191,7 +1191,7 @@ public:
 
       VMSize = std::max(VMSize, Address + Size);
 
-      if (Asm.getBackend().isVirtualSection(SD.getSection()))
+      if (SD.getSection().isVirtualSection())
         continue;
 
       SectionDataSize = std::max(SectionDataSize, Address + Size);
index 75a5511e6cc6fae1d6d4ef83ce638189be5d574a..786c3ca7e5b5566e4c79721a8f831d568750d32b 100644 (file)
@@ -83,11 +83,6 @@ public:
   void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
                   uint64_t Value) const;
 
-  bool isVirtualSection(const MCSection &Section) const {
-    const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
-    return SE.getType() == MCSectionELF::SHT_NOBITS;
-  }
-
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
     return createELFObjectWriter(OS, /*Is64Bit=*/false,
                                  OSType, ELF::EM_ARM,
@@ -118,13 +113,6 @@ public:
   void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
                   uint64_t Value) const;
 
-  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 ||
-            SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
-  }
-
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
     // FIXME: Subtarget info should be derived. Force v7 for now.
     return createMachObjectWriter(OS, /*Is64Bit=*/false, MachO::CPUTypeARM,
index 944ebf1f4bed8455f4835738927e610da07c5810..6fc36f7786d435ea7e8351bbb054eb4daa0dba1e 100644 (file)
@@ -96,11 +96,6 @@ public:
   void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
                   uint64_t Value) const;
 
-  bool isVirtualSection(const MCSection &Section) const {
-    const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
-    return SE.getType() == MCSectionELF::SHT_NOBITS;
-  }
-
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
     return createELFObjectWriter(OS, /*Is64Bit=*/false,
                                  OSType, ELF::EM_MBLAZE,
index a6d1426daf0aed9ccd257af0cc56a6f19f8354ec..6a6177063f5ff92fe36645ac9d33f82595ec6272 100644 (file)
@@ -68,13 +68,6 @@ namespace {
       assert(0 && "UNIMP");
     }
     
-    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 ||
-              SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
-    }
-    
     MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
       bool is64 = getPointerSize() == 8;
       return createMachObjectWriter(OS, /*Is64Bit=*/is64,
index 8910c4215c7181455f146ee17b2f53b02a3cc122..fd823bf52448d3ec1843cafeb0a22bfd63ad6325 100644 (file)
@@ -289,11 +289,6 @@ public:
     const MCSectionELF &ES = static_cast<const MCSectionELF&>(Section);
     return ES.getFlags() & MCSectionELF::SHF_MERGE;
   }
-
-  bool isVirtualSection(const MCSection &Section) const {
-    const MCSectionELF &SE = static_cast<const MCSectionELF&>(Section);
-    return SE.getType() == MCSectionELF::SHT_NOBITS;
-  }
 };
 
 class ELFX86_32AsmBackend : public ELFX86AsmBackend {
@@ -355,11 +350,6 @@ public:
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
     return createWinCOFFObjectWriter(OS, Is64Bit);
   }
-
-  bool isVirtualSection(const MCSection &Section) const {
-    const MCSectionCOFF &SE = static_cast<const MCSectionCOFF&>(Section);
-    return SE.getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA;
-  }
 };
 
 class DarwinX86AsmBackend : public X86AsmBackend {
@@ -374,13 +364,6 @@ public:
   virtual const MCObjectFormat &getObjectFormat() const {
     return Format;
   }
-
-  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 ||
-            SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
-  }
 };
 
 class DarwinX86_32AsmBackend : public DarwinX86AsmBackend {