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
This commit is contained in:
Peter Collingbourne 2015-02-19 00:45:02 +00:00
parent 8915e014e0
commit 99a5e24d34
6 changed files with 44 additions and 0 deletions

View File

@ -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.
///

View File

@ -73,6 +73,7 @@ IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
MCContext MCCtx(MAI.get(), MRI.get(), &MOFI);
MOFI.InitMCObjectFileInfo(Triple, Reloc::Default, CodeModel::Default, MCCtx);
std::unique_ptr<RecordStreamer> Streamer(new RecordStreamer(MCCtx));
T->createNullTargetStreamer(*Streamer);
std::unique_ptr<MemoryBuffer> Buffer(MemoryBuffer::getMemBuffer(InlineAsm));
SourceMgr SrcMgr;

View File

@ -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) {

View File

@ -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);

View File

@ -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,

View File

@ -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"