Provide a dummy section to fix a crash with inline assembly in LTO.
Fixes pr18508.
llvm-svn: 199843
diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp
index f73a608e3..b648982 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -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 @@
}
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 @@
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.