llvm.org GIT mirror llvm / 603e103
lto/addAsmGlobalSymbols: fail fracefully when the target does not define AsmParser. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139283 91177308-0d34-0410-b5e6-96231b3b80d8 Ivan Krasin 8 years ago
2 changed file(s) with 13 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
164164 std::string CPU;
165165 TargetMachine *target = march->createTargetMachine(Triple, CPU, FeatureStr);
166166 LTOModule *Ret = new LTOModule(m.take(), target);
167 bool Err = Ret->ParseSymbols();
167 bool Err = Ret->ParseSymbols(errMsg);
168168 if (Err) {
169169 delete Ret;
170170 return NULL;
612612 };
613613 }
614614
615 bool LTOModule::addAsmGlobalSymbols(MCContext &Context) {
615 bool LTOModule::addAsmGlobalSymbols(MCContext &Context, std::string &errMsg) {
616616 const std::string &inlineAsm = _module->getModuleInlineAsm();
617617
618618 OwningPtr Streamer(new RecordStreamer(Context));
628628 _target->getTargetFeatureString()));
629629 OwningPtr
630630 TAP(_target->getTarget().createMCAsmParser(*STI, *Parser.get()));
631 if (!TAP) {
632 errMsg = "target " + std::string(_target->getTarget().getName()) +
633 " does not define AsmParser.";
634 return true;
635 }
636
631637 Parser->setTargetParser(*TAP);
632638 int Res = Parser->Run(false);
633639 if (Res)
660666 return isDeclaration(*V.getAliasedGlobal());
661667 }
662668
663 bool LTOModule::ParseSymbols() {
669 bool LTOModule::ParseSymbols(std::string &errMsg) {
664670 // Use mangler to add GlobalPrefix to names to match linker names.
665671 MCContext Context(*_target->getMCAsmInfo(), *_target->getRegisterInfo(),NULL);
666672 Mangler mangler(Context, *_target->getTargetData());
683689 }
684690
685691 // add asm globals
686 if (addAsmGlobalSymbols(Context))
692 if (addAsmGlobalSymbols(Context, errMsg))
687693 return true;
688694
689695 // add aliases
7575 private:
7676 LTOModule(llvm::Module* m, llvm::TargetMachine* t);
7777
78 bool ParseSymbols();
78 bool ParseSymbols(std::string &errMsg);
7979 void addDefinedSymbol(llvm::GlobalValue* def,
8080 llvm::Mangler& mangler,
8181 bool isFunction);
8585 llvm::Mangler &mangler);
8686 void addDefinedDataSymbol(llvm::GlobalValue* v,
8787 llvm::Mangler &mangler);
88 bool addAsmGlobalSymbols(llvm::MCContext &Context);
88 bool addAsmGlobalSymbols(llvm::MCContext &Context,
89 std::string &errMsg);
8990 void addAsmGlobalSymbol(const char *,
9091 lto_symbol_attributes scope);
9192 void addAsmGlobalSymbolUndef(const char *);