Always print the implicit .text at the start of an asm file.
authorRafael Espindola <rafael.espindola@gmail.com>
Wed, 5 Mar 2014 20:09:15 +0000 (20:09 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Wed, 5 Mar 2014 20:09:15 +0000 (20:09 +0000)
Before llvm-mc would print it, but llc was assuming that it would produce
another section changing directive before one was needed. That assumption is
false with inline asm.

Fixes PR19049.

Another option would be to always create the section, but in the asm printer
avoid printing sections changes during initialization. That would work, but
* We do use the fact that llvm-mc prints it in testing. The tests can be changed
  if needed.
* A quick poll on IRC suggest that most developers prefer the implicit .text to
  be printed.

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

include/llvm/MC/MCELFStreamer.h
include/llvm/MC/MCStreamer.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/MC/MCAsmStreamer.cpp
lib/MC/MCELFStreamer.cpp
lib/MC/MCStreamer.cpp
lib/MC/WinCOFFStreamer.cpp
test/CodeGen/X86/GC/ocaml-gc.ll
test/CodeGen/X86/pr19049.ll [new file with mode: 0644]

index 46b32d0de6f364ab031ac328873ffe90f9148b24..ad25e2ce7d436674e53177f1951a342080ae9eba 100644 (file)
@@ -44,7 +44,7 @@ public:
   /// @name MCStreamer Interface
   /// @{
 
-  virtual void InitSections(bool Force);
+  virtual void InitSections();
   virtual void ChangeSection(const MCSection *Section,
                              const MCExpr *Subsection);
   virtual void EmitLabel(MCSymbol *Symbol);
index 43fa42ba812f808b4732b8938ca965ec578e48cf..e9f6196063f941ee25874894861a6318f8e1da7e 100644 (file)
@@ -352,10 +352,7 @@ public:
   }
 
   /// Create the default sections and set the initial one.
-  ///
-  /// @param Force - If false, a text streamer implementation can be a nop.
-  /// Used by CodeGen to avoid starting every file with '.text'.
-  virtual void InitSections(bool Force = true);
+  virtual void InitSections();
 
   /// AssignSection - Sets the symbol's section.
   ///
index 4d35e863106376a18cd2e1428d059f3b614ad9d7..fb1d42c06f47a12021592e44ebb144762c1b50d4 100644 (file)
@@ -175,7 +175,7 @@ bool AsmPrinter::doInitialization(Module &M) {
   const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
     .Initialize(OutContext, TM);
 
-  OutStreamer.InitSections(false);
+  OutStreamer.InitSections();
 
   Mang = new Mangler(TM.getDataLayout());
 
index 31f5de56d74f9348660dde4065b3b3cfc749ed07..8f0a702fb1cdbef57ffc03a42566cfdc8c3595f4 100644 (file)
@@ -127,11 +127,6 @@ public:
   virtual void ChangeSection(const MCSection *Section,
                              const MCExpr *Subsection);
 
-  virtual void InitSections(bool Force) {
-    if (Force)
-      SwitchSection(getContext().getObjectFileInfo()->getTextSection());
-  }
-
   virtual void EmitLabel(MCSymbol *Symbol);
   virtual void EmitDebugLabel(MCSymbol *Symbol);
 
index 9ff9665d52d60f6319f048b4402bbb2346a6a62c..5f6a889769dffba60df45ad95349a9b0d5b17bb6 100644 (file)
@@ -38,7 +38,7 @@ using namespace llvm;
 MCELFStreamer::~MCELFStreamer() {
 }
 
-void MCELFStreamer::InitSections(bool Force) {
+void MCELFStreamer::InitSections() {
   // This emulates the same behavior of GNU as. This makes it easier
   // to compare the output as the major sections are in the same order.
   SwitchSection(getContext().getObjectFileInfo()->getTextSection());
index 02065daf247fc993d89f02477a2f3e4ddda23c78..0837389581482bcac18b17cae38c7a663c065cb8 100644 (file)
@@ -205,7 +205,7 @@ void MCStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
                                      MCSymbol *EHSymbol) {
 }
 
-void MCStreamer::InitSections(bool Force) {
+void MCStreamer::InitSections() {
   SwitchSection(getContext().getObjectFileInfo()->getTextSection());
 }
 
index 445d26106ad1a733e1abb7764183808f8409cb5a..55ae2fe23b3d794ead352ae5f0ee2cbf2a12edfa 100644 (file)
@@ -50,7 +50,7 @@ public:
 
   // MCStreamer interface
 
-  virtual void InitSections(bool Force);
+  virtual void InitSections();
   virtual void EmitLabel(MCSymbol *Symbol);
   virtual void EmitDebugLabel(MCSymbol *Symbol);
   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
@@ -123,7 +123,7 @@ void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
 
 // MCStreamer interface
 
-void WinCOFFStreamer::InitSections(bool Force) {
+void WinCOFFStreamer::InitSections() {
   // FIXME: this is identical to the ELF one.
   // This emulates the same behavior of GNU as. This makes it easier
   // to compare the output as the major sections are in the same order.
index 6d5f8aebe1399bedc0db4f9ef569b358fcd9ec7d..37ddaf90bf6715aae332ff5533211aff0c78b53b 100644 (file)
@@ -1,8 +1,10 @@
 ; RUN: llc < %s -mtriple=x86_64-linux-gnu | FileCheck %s
 
-define i32 @main(i32 %x) nounwind gc "ocaml" {
 ; CHECK:        .text
-; CHECK-NEXT:   .globl "caml<stdin>__code_begin"
+; CHECK-NEXT:   .file   "<stdin>"
+
+define i32 @main(i32 %x) nounwind gc "ocaml" {
+; CHECK:   .globl "caml<stdin>__code_begin"
 ; CHECK-NEXT: "caml<stdin>__code_begin":
 ; CHECK-NEXT:   .data
 ; CHECK-NEXT:   .globl  "caml<stdin>__data_begin"
diff --git a/test/CodeGen/X86/pr19049.ll b/test/CodeGen/X86/pr19049.ll
new file mode 100644 (file)
index 0000000..027c981
--- /dev/null
@@ -0,0 +1,7 @@
+; RUN: llc -mtriple x86_64-pc-linux %s -o - | FileCheck %s
+
+module asm ".pushsection foo"
+module asm ".popsection"
+
+; CHECK: .section      foo,"",@progbits
+; CHECK: .text