From fd6a2498ab081a838354ecde07b540b9d071abc8 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Sun, 26 Jul 2009 22:16:39 +0000 Subject: [PATCH] Fix libLTO: * Call InitializeAllTargets on every path where we might query the TargetRegistry. This fixes PR4604. * flush the formatted_raw_ostream& or else not all of the assembly will make it to the .s file. (It doesn't do this in its destructor?!) * Due to a reversed conditional, libLTO was reporting many symbols as both defined and undefined, including two definitions of the same symbol name in its symbol list. llvm-svn: 77170 --- llvm/tools/lto/LTOCodeGenerator.cpp | 10 ++++++---- llvm/tools/lto/LTOModule.cpp | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/llvm/tools/lto/LTOCodeGenerator.cpp b/llvm/tools/lto/LTOCodeGenerator.cpp index a264e73904f9..a5023fb2f4fa 100644 --- a/llvm/tools/lto/LTOCodeGenerator.cpp +++ b/llvm/tools/lto/LTOCodeGenerator.cpp @@ -77,9 +77,8 @@ LTOCodeGenerator::LTOCodeGenerator() _codeModel(LTO_CODEGEN_PIC_MODEL_DYNAMIC), _nativeObjectFile(NULL), _gccPath(NULL), _assemblerPath(NULL) { - InitializeAllTargets(); - InitializeAllAsmPrinters(); - + InitializeAllTargets(); + InitializeAllAsmPrinters(); } LTOCodeGenerator::~LTOCodeGenerator() @@ -398,7 +397,7 @@ void LTOCodeGenerator::applyScopeRestrictions() bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out, std::string& errMsg) { - if ( this->determineTarget(errMsg) ) + if ( this->determineTarget(errMsg) ) return true; // mark which symbols can not be internalized @@ -472,6 +471,9 @@ bool LTOCodeGenerator::generateAssemblyCode(formatted_raw_ostream& out, codeGenPasses->run(*it); codeGenPasses->doFinalization(); + + out.flush(); + return false; // success } diff --git a/llvm/tools/lto/LTOModule.cpp b/llvm/tools/lto/LTOModule.cpp index 9968d488ff46..cbccfbb9b69e 100644 --- a/llvm/tools/lto/LTOModule.cpp +++ b/llvm/tools/lto/LTOModule.cpp @@ -30,6 +30,7 @@ #include "llvm/Target/TargetAsmInfo.h" #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetRegistry.h" +#include "llvm/Target/TargetSelect.h" using namespace llvm; @@ -125,6 +126,8 @@ LTOModule* LTOModule::makeLTOModule(const void* mem, size_t length, /// subtarget. It would be better if we could encode this information into the /// IR. See . std::string getFeatureString(const char *TargetTriple) { + InitializeAllTargets(); + SubtargetFeatures Features; if (strncmp(TargetTriple, "powerpc-apple-", 14) == 0) { @@ -140,6 +143,8 @@ std::string getFeatureString(const char *TargetTriple) { LTOModule* LTOModule::makeLTOModule(MemoryBuffer* buffer, std::string& errMsg) { + InitializeAllTargets(); + // parse bitcode buffer OwningPtr m(ParseBitcodeFile(buffer, getGlobalContext(), &errMsg)); if ( !m ) @@ -422,7 +427,7 @@ void LTOModule::addPotentialUndefinedSymbol(GlobalValue* decl, Mangler &mangler) -// Find exeternal symbols referenced by VALUE. This is a recursive function. +// Find external symbols referenced by VALUE. This is a recursive function. void LTOModule::findExternalRefs(Value* value, Mangler &mangler) { if (GlobalValue* gv = dyn_cast(value)) { @@ -508,7 +513,7 @@ void LTOModule::lazyParseSymbols() it != _undefines.end(); ++it) { // if this symbol also has a definition, then don't make an undefine // because it is a tentative definition - if ( _defines.count(it->getKey())) { + if ( _defines.count(it->getKey()) == 0 ) { NameAndAttributes info = it->getValue(); _symbols.push_back(info); }