From 99a5e24d346b188f3df2a5256f7244e6e492f978 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 19 Feb 2015 00:45:02 +0000 Subject: [PATCH] Introduce Target::createNullTargetStreamer and use it from IRObjectFile. A null MCTargetStreamer allows IRObjectFile to ignore target-specific directives. Previously we were crashing. Differential Revision: http://reviews.llvm.org/D7711 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@229797 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/TargetRegistry.h | 17 +++++++++++++++++ lib/Object/IRObjectFile.cpp | 1 + lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp | 4 ++++ lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp | 10 ++++++++++ lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h | 3 +++ test/LTO/ARM/inline-asm.ll | 9 +++++++++ 6 files changed, 44 insertions(+) create mode 100644 test/LTO/ARM/inline-asm.ll diff --git a/include/llvm/Support/TargetRegistry.h b/include/llvm/Support/TargetRegistry.h index ffedac73796..3c5371e8612 100644 --- a/include/llvm/Support/TargetRegistry.h +++ b/include/llvm/Support/TargetRegistry.h @@ -47,6 +47,7 @@ namespace llvm { class MCRelocationInfo; class MCTargetAsmParser; class MCTargetOptions; + class MCTargetStreamer; class TargetMachine; class TargetOptions; class raw_ostream; @@ -139,6 +140,7 @@ namespace llvm { MCAsmBackend *TAB, bool ShowInst); typedef MCStreamer *(*NullStreamerCtorTy)(MCContext &Ctx); + typedef MCTargetStreamer *(*NullTargetStreamerCtorTy)(MCStreamer &S); typedef MCRelocationInfo *(*MCRelocationInfoCtorTy)(StringRef TT, MCContext &Ctx); typedef MCSymbolizer *(*MCSymbolizerCtorTy)( @@ -227,6 +229,10 @@ namespace llvm { /// (default = llvm::createNullStreamer). NullStreamerCtorTy NullStreamerCtorFn; + /// Construction function for this target's null TargetStreamer, if + /// registered (default = nullptr). + NullTargetStreamerCtorTy NullTargetStreamerCtorFn; + /// MCRelocationInfoCtorFn - Construction function for this target's /// MCRelocationInfo, if registered (default = llvm::createMCRelocationInfo) MCRelocationInfoCtorTy MCRelocationInfoCtorFn; @@ -453,6 +459,12 @@ namespace llvm { return llvm::createNullStreamer(Ctx); } + MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) const { + if (NullTargetStreamerCtorFn) + return NullTargetStreamerCtorFn(S); + return nullptr; + } + /// createMCRelocationInfo - Create a target specific MCRelocationInfo. /// /// \param TT The target triple. @@ -783,6 +795,11 @@ namespace llvm { T.NullStreamerCtorFn = Fn; } + static void + RegisterNullTargetStreamer(Target &T, Target::NullTargetStreamerCtorTy Fn) { + T.NullTargetStreamerCtorFn = Fn; + } + /// RegisterMCRelocationInfo - Register an MCRelocationInfo /// implementation for the given target. /// diff --git a/lib/Object/IRObjectFile.cpp b/lib/Object/IRObjectFile.cpp index 423ed9e9a64..a2cbdcd0380 100644 --- a/lib/Object/IRObjectFile.cpp +++ b/lib/Object/IRObjectFile.cpp @@ -73,6 +73,7 @@ IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr Mod) MCContext MCCtx(MAI.get(), MRI.get(), &MOFI); MOFI.InitMCObjectFileInfo(Triple, Reloc::Default, CodeModel::Default, MCCtx); std::unique_ptr Streamer(new RecordStreamer(MCCtx)); + T->createNullTargetStreamer(*Streamer); std::unique_ptr Buffer(MemoryBuffer::getMemBuffer(InlineAsm)); SourceMgr SrcMgr; diff --git a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index d698feabec8..7a302374378 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -1360,6 +1360,10 @@ MCStreamer *createARMNullStreamer(MCContext &Ctx) { return S; } +MCTargetStreamer *createARMNullTargetStreamer(MCStreamer &S) { + return new ARMTargetStreamer(S); +} + MCELFStreamer *createARMELFStreamer(MCContext &Context, MCAsmBackend &TAB, raw_ostream &OS, MCCodeEmitter *Emitter, bool RelaxAll, bool IsThumb) { diff --git a/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp b/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp index a6310e5093b..ad96717da8c 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp +++ b/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp @@ -461,6 +461,16 @@ extern "C" void LLVMInitializeARMTargetMC() { TargetRegistry::RegisterNullStreamer(TheThumbLETarget, createARMNullStreamer); TargetRegistry::RegisterNullStreamer(TheThumbBETarget, createARMNullStreamer); + // Register the null TargetStreamer. + TargetRegistry::RegisterNullTargetStreamer(TheARMLETarget, + createARMNullTargetStreamer); + TargetRegistry::RegisterNullTargetStreamer(TheARMBETarget, + createARMNullTargetStreamer); + TargetRegistry::RegisterNullTargetStreamer(TheThumbLETarget, + createARMNullTargetStreamer); + TargetRegistry::RegisterNullTargetStreamer(TheThumbBETarget, + createARMNullTargetStreamer); + // Register the MCInstPrinter. TargetRegistry::RegisterMCInstPrinter(TheARMLETarget, createARMMCInstPrinter); TargetRegistry::RegisterMCInstPrinter(TheARMBETarget, createARMMCInstPrinter); diff --git a/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h b/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h index a6c20d5f94d..e534b131bac 100644 --- a/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h +++ b/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.h @@ -29,6 +29,7 @@ class MCRegisterInfo; class MCSubtargetInfo; class MCStreamer; class MCRelocationInfo; +class MCTargetStreamer; class StringRef; class Target; class raw_ostream; @@ -53,6 +54,8 @@ MCStreamer *createMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS, MCStreamer *createARMNullStreamer(MCContext &Ctx); +MCTargetStreamer *createARMNullTargetStreamer(MCStreamer &S); + MCCodeEmitter *createARMLEMCCodeEmitter(const MCInstrInfo &MCII, const MCRegisterInfo &MRI, const MCSubtargetInfo &STI, diff --git a/test/LTO/ARM/inline-asm.ll b/test/LTO/ARM/inline-asm.ll new file mode 100644 index 00000000000..23fb90457c1 --- /dev/null +++ b/test/LTO/ARM/inline-asm.ll @@ -0,0 +1,9 @@ +; Check that we don't crash on target-specific inline asm directives. +; +; RUN: llvm-as < %s > %t +; RUN: llvm-lto -o /dev/null %t -mcpu armv4t + +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" +target triple = "armv4t-unknown-linux" + +module asm ".fnstart"