lto/addAsmGlobalSymbols: fail fracefully when the target does not define AsmParser.
authorIvan Krasin <krasin@chromium.org>
Thu, 8 Sep 2011 07:36:39 +0000 (07:36 +0000)
committerIvan Krasin <krasin@chromium.org>
Thu, 8 Sep 2011 07:36:39 +0000 (07:36 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139283 91177308-0d34-0410-b5e6-96231b3b80d8

tools/lto/LTOModule.cpp
tools/lto/LTOModule.h

index f6dc7d90bce66f1f9d6d4d39d5e1e4ceca3235bf..6b4e2d2a65913fba1941fada7d18d3aea7c61ba2 100644 (file)
@@ -165,7 +165,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
   std::string CPU;
   TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr);
   LTOModule *Ret = new LTOModule(m.take(), target);
-  bool Err = Ret->ParseSymbols();
+  bool Err = Ret->ParseSymbols(errMsg);
   if (Err) {
     delete Ret;
     return NULL;
@@ -613,7 +613,7 @@ namespace {
   };
 }
 
-bool LTOModule::addAsmGlobalSymbols(MCContext &Context) {
+bool LTOModule::addAsmGlobalSymbols(MCContext &Context, std::string &errMsg) {
   const std::string &inlineAsm = _module->getModuleInlineAsm();
 
   OwningPtr<RecordStreamer> Streamer(new RecordStreamer(Context));
@@ -629,6 +629,12 @@ bool LTOModule::addAsmGlobalSymbols(MCContext &Context) {
                                             _target->getTargetFeatureString()));
   OwningPtr<MCTargetAsmParser>
     TAP(_target->getTarget().createMCAsmParser(*STI, *Parser.get()));
+  if (!TAP) {
+    errMsg = "target " + std::string(_target->getTarget().getName()) +
+        " does not define AsmParser.";
+    return true;
+  }
+
   Parser->setTargetParser(*TAP);
   int Res = Parser->Run(false);
   if (Res)
@@ -661,7 +667,7 @@ static bool isAliasToDeclaration(const GlobalAlias &V) {
   return isDeclaration(*V.getAliasedGlobal());
 }
 
-bool LTOModule::ParseSymbols() {
+bool LTOModule::ParseSymbols(std::string &errMsg) {
   // Use mangler to add GlobalPrefix to names to match linker names.
   MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL);
   Mangler mangler(Context, *_target->getTargetData());
@@ -684,7 +690,7 @@ bool LTOModule::ParseSymbols() {
   }
 
   // add asm globals
-  if (addAsmGlobalSymbols(Context))
+  if (addAsmGlobalSymbols(Context, errMsg))
     return true;
 
   // add aliases
index 0b64a902f91642927e0337a1ac65575b5639fc52..ca08aea90adba0e8f0eee2db1c5ed2bb3fa618f2 100644 (file)
@@ -76,7 +76,7 @@ struct LTOModule {
 private:
                             LTOModule(llvm::Module* m, llvm::TargetMachine* t);
 
-    bool                    ParseSymbols();
+    bool                    ParseSymbols(std::string &errMsg);
     void                    addDefinedSymbol(llvm::GlobalValue* def, 
                                                     llvm::Mangler& mangler, 
                                                     bool isFunction);
@@ -86,7 +86,8 @@ private:
                                                         llvm::Mangler &mangler);
     void                    addDefinedDataSymbol(llvm::GlobalValue* v, 
                                                         llvm::Mangler &mangler);
-    bool                    addAsmGlobalSymbols(llvm::MCContext &Context);
+    bool                    addAsmGlobalSymbols(llvm::MCContext &Context,
+                                                std::string &errMsg);
     void                    addAsmGlobalSymbol(const char *,
                                                lto_symbol_attributes scope);
     void                    addAsmGlobalSymbolUndef(const char *);