From c2aec57c63a8551cef27025dc7f0d2d9e56db013 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Wed, 16 Jul 2008 18:06:52 +0000 Subject: [PATCH] Do not forget global definitions from inline asm code block. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53693 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/lto/LTOModule.cpp | 39 +++++++++++++++++++++++++++++++++++++++ tools/lto/LTOModule.h | 1 + 2 files changed, 40 insertions(+) diff --git a/tools/lto/LTOModule.cpp b/tools/lto/LTOModule.cpp index f31f0dfb739..ac38d244c40 100644 --- a/tools/lto/LTOModule.cpp +++ b/tools/lto/LTOModule.cpp @@ -238,6 +238,19 @@ void LTOModule::addDefinedSymbol(GlobalValue* def, Mangler &mangler, _defines[info.name] = 1; } +void LTOModule::addAsmGlobalSymbol(const char *name) { + // string is owned by _defines + const char *symbolName = ::strdup(name); + uint32_t attr = LTO_SYMBOL_DEFINITION_REGULAR; + attr |= LTO_SYMBOL_SCOPE_DEFAULT; + + // add to table of symbols + NameAndAttributes info; + info.name = symbolName; + info.attributes = (lto_symbol_attributes)attr; + _symbols.push_back(info); + _defines[info.name] = 1; +} void LTOModule::addPotentialUndefinedSymbol(GlobalValue* decl, Mangler &mangler) { @@ -297,6 +310,32 @@ void LTOModule::lazyParseSymbols() addDefinedDataSymbol(v, mangler); } + // add asm globals + const std::string &inlineAsm = _module->getModuleInlineAsm(); + const std::string glbl = ".globl"; + std::string asmSymbolName; + std::string::size_type pos = inlineAsm.find(glbl, 0); + while (pos != std::string::npos) { + // eat .globl + pos = pos + 6; + + // skip white space between .globl and symbol name + std::string::size_type pbegin = inlineAsm.find_first_not_of(' ', pos); + if (pbegin == std::string::npos) + break; + + // find end-of-line + std::string::size_type pend = inlineAsm.find_first_of('\n', pbegin); + if (pend == std::string::npos) + break; + + asmSymbolName.assign(inlineAsm, pbegin, pbegin-pend); + addAsmGlobalSymbol(asmSymbolName.c_str()); + + // search next .globl + pos = inlineAsm.find(glbl, pend); + } + // make symbols for all undefines for (StringSet::iterator it=_undefines.begin(); it != _undefines.end(); ++it) { diff --git a/tools/lto/LTOModule.h b/tools/lto/LTOModule.h index 40f92f98165..0cb9cdc8b0c 100644 --- a/tools/lto/LTOModule.h +++ b/tools/lto/LTOModule.h @@ -76,6 +76,7 @@ private: llvm::Mangler &mangler); void addDefinedDataSymbol(llvm::GlobalValue* v, llvm::Mangler &mangler); + void addAsmGlobalSymbol(const char *); static bool isTargetMatch(llvm::MemoryBuffer* memBuffer, const char* triplePrefix);