[llvm] r203001 - Always print the implicit .text at the start of an asm file.

Rafael Espindola rafael.espindola at gmail.com
Wed Mar 5 12:09:16 PST 2014


Author: rafael
Date: Wed Mar  5 14:09:15 2014
New Revision: 203001

URL: http://llvm.org/viewvc/llvm-project?rev=203001&view=rev
Log:
Always print the implicit .text at the start of an asm file.

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.

Added:
    llvm/trunk/test/CodeGen/X86/pr19049.ll
Modified:
    llvm/trunk/include/llvm/MC/MCELFStreamer.h
    llvm/trunk/include/llvm/MC/MCStreamer.h
    llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/MC/MCELFStreamer.cpp
    llvm/trunk/lib/MC/MCStreamer.cpp
    llvm/trunk/lib/MC/WinCOFFStreamer.cpp
    llvm/trunk/test/CodeGen/X86/GC/ocaml-gc.ll

Modified: llvm/trunk/include/llvm/MC/MCELFStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCELFStreamer.h?rev=203001&r1=203000&r2=203001&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCELFStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCELFStreamer.h Wed Mar  5 14:09:15 2014
@@ -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);

Modified: llvm/trunk/include/llvm/MC/MCStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCStreamer.h?rev=203001&r1=203000&r2=203001&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCStreamer.h (original)
+++ llvm/trunk/include/llvm/MC/MCStreamer.h Wed Mar  5 14:09:15 2014
@@ -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.
   ///

Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=203001&r1=203000&r2=203001&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Wed Mar  5 14:09:15 2014
@@ -175,7 +175,7 @@ bool AsmPrinter::doInitialization(Module
   const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
     .Initialize(OutContext, TM);
 
-  OutStreamer.InitSections(false);
+  OutStreamer.InitSections();
 
   Mang = new Mangler(TM.getDataLayout());
 

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=203001&r1=203000&r2=203001&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Wed Mar  5 14:09:15 2014
@@ -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);
 

Modified: llvm/trunk/lib/MC/MCELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCELFStreamer.cpp?rev=203001&r1=203000&r2=203001&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCELFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCELFStreamer.cpp Wed Mar  5 14:09:15 2014
@@ -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());

Modified: llvm/trunk/lib/MC/MCStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCStreamer.cpp?rev=203001&r1=203000&r2=203001&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCStreamer.cpp Wed Mar  5 14:09:15 2014
@@ -205,7 +205,7 @@ void MCStreamer::EmitEHSymAttributes(con
                                      MCSymbol *EHSymbol) {
 }
 
-void MCStreamer::InitSections(bool Force) {
+void MCStreamer::InitSections() {
   SwitchSection(getContext().getObjectFileInfo()->getTextSection());
 }
 

Modified: llvm/trunk/lib/MC/WinCOFFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WinCOFFStreamer.cpp?rev=203001&r1=203000&r2=203001&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WinCOFFStreamer.cpp (original)
+++ llvm/trunk/lib/MC/WinCOFFStreamer.cpp Wed Mar  5 14:09:15 2014
@@ -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(MC
 
 // 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.

Modified: llvm/trunk/test/CodeGen/X86/GC/ocaml-gc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/GC/ocaml-gc.ll?rev=203001&r1=203000&r2=203001&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/GC/ocaml-gc.ll (original)
+++ llvm/trunk/test/CodeGen/X86/GC/ocaml-gc.ll Wed Mar  5 14:09:15 2014
@@ -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"

Added: llvm/trunk/test/CodeGen/X86/pr19049.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/pr19049.ll?rev=203001&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/pr19049.ll (added)
+++ llvm/trunk/test/CodeGen/X86/pr19049.ll Wed Mar  5 14:09:15 2014
@@ -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,"", at progbits
+; CHECK: .text





More information about the llvm-commits mailing list