[llvm] r199843 - Provide a dummy section to fix a crash with inline assembly in LTO.

Rafael Espindola rafael.espindola at gmail.com
Wed Jan 22 14:11:14 PST 2014


Author: rafael
Date: Wed Jan 22 16:11:14 2014
New Revision: 199843

URL: http://llvm.org/viewvc/llvm-project?rev=199843&view=rev
Log:
Provide a dummy section to fix a crash with inline assembly in LTO.

Fixes pr18508.

Added:
    llvm/trunk/test/LTO/current-section.ll
Modified:
    llvm/trunk/lib/LTO/LTOModule.cpp

Modified: llvm/trunk/lib/LTO/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOModule.cpp?rev=199843&r1=199842&r2=199843&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOModule.cpp (original)
+++ llvm/trunk/lib/LTO/LTOModule.cpp Wed Jan 22 16:11:14 2014
@@ -24,6 +24,7 @@
 #include "llvm/MC/MCInst.h"
 #include "llvm/MC/MCInstrInfo.h"
 #include "llvm/MC/MCParser/MCAsmParser.h"
+#include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSubtargetInfo.h"
 #include "llvm/MC/MCSymbol.h"
@@ -532,10 +533,32 @@ LTOModule::addPotentialUndefinedSymbol(c
 }
 
 namespace {
+
+// Common infrastructure is allowed to assume the existence of a current
+// section. Since this streamer doesn't need one itself, we just provide
+// a dummy one.
+class DummySection : public MCSection {
+public:
+  DummySection() : MCSection(SV_ELF, SectionKind::getText()) {}
+
+  virtual void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS,
+                                    const MCExpr *Subsection) const {}
+
+  virtual std::string getLabelBeginName() const { return ""; }
+
+  virtual std::string getLabelEndName() const { return ""; }
+
+  virtual bool UseCodeAlign() const { return false; }
+
+  virtual bool isVirtualSection() const { return false; }
+};
+
   class RecordStreamer : public MCStreamer {
   public:
     enum State { NeverSeen, Global, Defined, DefinedGlobal, Used };
 
+    DummySection TheSection;
+
   private:
     StringMap<State> Symbols;
 
@@ -621,7 +644,9 @@ namespace {
       return Symbols.end();
     }
 
-    RecordStreamer(MCContext &Context) : MCStreamer(Context, 0) {}
+    RecordStreamer(MCContext &Context) : MCStreamer(Context, 0) {
+      SwitchSection(&TheSection);
+    }
 
     virtual void EmitInstruction(const MCInst &Inst) {
       // Scan for values.

Added: llvm/trunk/test/LTO/current-section.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LTO/current-section.ll?rev=199843&view=auto
==============================================================================
--- llvm/trunk/test/LTO/current-section.ll (added)
+++ llvm/trunk/test/LTO/current-section.ll Wed Jan 22 16:11:14 2014
@@ -0,0 +1,4 @@
+; RUN: llvm-as < %s >%t1
+; RUN: llvm-lto -o %t2 %t1
+
+module asm ".align 4"





More information about the llvm-commits mailing list