Remove HasCrazyBSS and add a flag in TAI to indicate that '.section'
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 13 Aug 2009 23:30:21 +0000 (23:30 +0000)
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>
Thu, 13 Aug 2009 23:30:21 +0000 (23:30 +0000)
must be emitted for PowerPC-Linux '.bss' section

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78958 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCSectionELF.h
include/llvm/Target/TargetAsmInfo.h
include/llvm/Target/TargetLoweringObjectFile.h
lib/MC/MCSectionELF.cpp
lib/Target/PowerPC/PPCISelLowering.cpp
lib/Target/PowerPC/PPCTargetAsmInfo.cpp
lib/Target/TargetAsmInfo.cpp
lib/Target/TargetLoweringObjectFile.cpp
test/CodeGen/PowerPC/sections.ll [new file with mode: 0644]

index 31e1e6684f60d5f4edc387fe11f96236840b4a2f..8d23b285f3e98c5bdf05bcb24420779921fbe144 100644 (file)
@@ -30,28 +30,24 @@ class MCSectionELF : public MCSection {
   /// below.
   unsigned Flags;
 
-  /// HasCrazyBSS - PPC/Linux doesn't support the .bss directive, it 
-  /// needs .section .bss. TODO: replace this with a TAI method.
-  bool HasCrazyBSS;
-
   /// IsExplicit - Indicates that this section comes from globals with an
   /// explicit section specfied.
   bool IsExplicit;
   
   MCSectionELF(const StringRef &Section, unsigned T, unsigned F, 
-               SectionKind K, bool hasCrazyBSS, bool isExplicit)
+               SectionKind K, bool isExplicit)
     : MCSection(K), SectionName(Section.str()), Type(T), Flags(F), 
-      HasCrazyBSS(hasCrazyBSS), IsExplicit(isExplicit) {}
+      IsExplicit(isExplicit) {}
 public:
   
   static MCSectionELF *Create(const StringRef &Section, unsigned Type, 
-                              unsigned Flags, SectionKind K, 
-                              bool hasCrazyBSS, bool isExplicit, 
+                              unsigned Flags, SectionKind K, bool isExplicit,
                               MCContext &Ctx);
 
   /// ShouldOmitSectionDirective - Decides whether a '.section' directive
   /// should be printed before the section name
-  bool ShouldOmitSectionDirective(const char *Name) const;
+  bool ShouldOmitSectionDirective(const char *Name, 
+                                  const TargetAsmInfo &TAI) const;
 
   /// ShouldPrintSectionType - Only prints the section type if supported
   bool ShouldPrintSectionType(unsigned Ty) const;
index 2654025af2ecafffa5aaa68bba837b3734e4a47e..cb0e346a6117ea341a503fc4898365d4219de560 100644 (file)
@@ -164,6 +164,11 @@ namespace llvm {
     /// Style" syntax for section switching ("#alloc,#write" etc) instead of the
     /// normal ELF syntax (,"a,w") in .section directives.
     bool SunStyleELFSectionSwitchSyntax;   // Defaults to false.
+
+    /// UsesELFSectionDirectiveForBSS - This is true if this target uses ELF
+    /// '.section' directive before the '.bss' one. It's used for PPC/Linux 
+    /// which doesn't support the '.bss' directive only.
+    bool UsesELFSectionDirectiveForBSS;  // Defaults to false.
     
     //===--- Alignment Information ----------------------------------------===//
 
@@ -336,6 +341,9 @@ namespace llvm {
       return SunStyleELFSectionSwitchSyntax;
     }
     
+    bool usesELFSectionDirectiveForBSS() const {
+      return UsesELFSectionDirectiveForBSS;
+    }
 
     // Accessors.
     //
index 2ee6d72ad491c23c4d99f8ce37903ddd3f027142..2264d36df9ef0013e0405cf1bd62791c76c956bd 100644 (file)
@@ -183,7 +183,6 @@ protected:
   
 
 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
-  bool HasCrazyBSS;
   mutable void *UniquingMap;
 protected:
   /// TLSDataSection - Section directive for Thread Local data.
@@ -209,13 +208,9 @@ protected:
                                  unsigned Flags, SectionKind Kind,
                                  bool IsExplicit = false) const;
 public:
-  TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
-                              bool hasCrazyBSS = false)
-    : HasCrazyBSS(hasCrazyBSS), UniquingMap(0) {}
-  
+  TargetLoweringObjectFileELF() : UniquingMap(0) {}
   ~TargetLoweringObjectFileELF();
   
-  
   virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
   
   /// getSectionForConstant - Given a constant with the SectionKind, return a
index 56f803496ace65d59509516d9f30499a0892f757..6e6f9990fe822331f1bd184ba85225d32b17515e 100644 (file)
@@ -16,20 +16,21 @@ using namespace llvm;
 
 MCSectionELF *MCSectionELF::
 Create(const StringRef &Section, unsigned Type, unsigned Flags,
-       SectionKind K, bool hasCrazyBSS, bool isExplicit, MCContext &Ctx) {
+       SectionKind K, bool isExplicit, MCContext &Ctx) {
   return new 
-    (Ctx) MCSectionELF(Section, Type, Flags, K, hasCrazyBSS, isExplicit);
+    (Ctx) MCSectionELF(Section, Type, Flags, K, isExplicit);
 }
 
 // ShouldOmitSectionDirective - Decides whether a '.section' directive
 // should be printed before the section name
-bool MCSectionELF::ShouldOmitSectionDirective(const char *Name) const {
+bool MCSectionELF::ShouldOmitSectionDirective(const char *Name,
+                                        const TargetAsmInfo &TAI) const {
   
-  // PPC/Linux doesn't support the .bss directive, it needs .section .bss.
   // FIXME: Does .section .bss/.data/.text work everywhere??
-  if ((!HasCrazyBSS && strncmp(Name, ".bss", 4) == 0) || 
-      strncmp(Name, ".text", 5) == 0 || 
-      strncmp(Name, ".data", 5) == 0)
+  if (strncmp(Name, ".text", 5) == 0 || 
+      strncmp(Name, ".data", 5) == 0 ||
+      (strncmp(Name, ".bss", 4) == 0 && 
+       !TAI.usesELFSectionDirectiveForBSS())) 
     return true;
 
   return false;
@@ -46,8 +47,8 @@ bool MCSectionELF::ShouldPrintSectionType(unsigned Ty) const {
 
 void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
                                         raw_ostream &OS) const {
-  
-  if (ShouldOmitSectionDirective(SectionName.c_str())) {
+   
+  if (ShouldOmitSectionDirective(SectionName.c_str(), TAI)) {
     OS << '\t' << getSectionName() << '\n';
     return;
   }
index 569026fbb7cfc98ce469c65cbea182014cd084e9..7ad81f8936b7b3cbb27788b5add03f0a603f353c 100644 (file)
@@ -60,7 +60,7 @@ cl::desc("enable preincrement load/store generation on PPC (experimental)"),
 static TargetLoweringObjectFile *CreateTLOF(const PPCTargetMachine &TM) {
   if (TM.getSubtargetImpl()->isDarwin())
     return new TargetLoweringObjectFileMachO();
-  return new TargetLoweringObjectFileELF(true);
+  return new TargetLoweringObjectFileELF();
 }
 
 
index 36cf2a5570ddb2f96785c850be38db0814a90a9b..864475b30a8df8e893ba72cf340dc959c3fca4d3 100644 (file)
@@ -30,6 +30,9 @@ PPCLinuxTargetAsmInfo::PPCLinuxTargetAsmInfo(bool is64Bit) {
   PrivateGlobalPrefix = ".L";
   UsedDirective = "\t# .no_dead_strip\t";
   WeakRefDirective = "\t.weak\t";
+  
+  // Uses '.section' before '.bss' directive
+  UsesELFSectionDirectiveForBSS = true;  
 
   // Debug Information
   AbsoluteDebugSectionOffsets = true;
index 253d72c359ce631a20ace826afcd2a30f78fc7d9..20a584916f7a04d6f9f3161ce11583832984f893 100644 (file)
@@ -50,6 +50,7 @@ TargetAsmInfo::TargetAsmInfo() {
   Data32bitsDirective = "\t.long\t";
   Data64bitsDirective = "\t.quad\t";
   SunStyleELFSectionSwitchSyntax = false;
+  UsesELFSectionDirectiveForBSS = false;
   AlignDirective = "\t.align\t";
   AlignmentIsInBytes = true;
   TextAlignFillValue = 0;
index edc9ed3ba43e4b338c907ff0d47d4e05d7f253c1..7cb87efd4042060cfba2fdd94c21304e36408292 100644 (file)
@@ -298,8 +298,8 @@ getELFSection(StringRef Section, unsigned Type, unsigned Flags,
   const MCSectionELF *&Entry = Map[Section];
   if (Entry) return Entry;
   
-  return Entry = MCSectionELF::Create(Section, Type, Flags, Kind, HasCrazyBSS, 
-                                      IsExplicit, getContext());
+  return Entry = MCSectionELF::Create(Section, Type, Flags, Kind, IsExplicit,
+                                      getContext());
 }
 
 void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
diff --git a/test/CodeGen/PowerPC/sections.ll b/test/CodeGen/PowerPC/sections.ll
new file mode 100644 (file)
index 0000000..21374d0
--- /dev/null
@@ -0,0 +1,8 @@
+; Test to make sure that bss sections are printed with '.section' directive.
+; RUN: llvm-as < %s | llc -mtriple=powerpc-unknown-linux-gnu | FileCheck %s
+
+@A = global i32 0
+
+; CHECK:  .section  .bss,"aw",@nobits
+; CHECK:  .global A
+