From 2291f8cf898be0812acd846ee1ffa83f64361460 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Fri, 4 Jul 2014 16:37:02 +0000 Subject: [PATCH] Avoid mangling names twice. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212348 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/LTO/LTOModule.h | 5 ++++- lib/LTO/LTOModule.cpp | 42 ++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/include/llvm/LTO/LTOModule.h b/include/llvm/LTO/LTOModule.h index 509b84e7e80..8208b2fb260 100644 --- a/include/llvm/LTO/LTOModule.h +++ b/include/llvm/LTO/LTOModule.h @@ -173,13 +173,16 @@ private: void addPotentialUndefinedSymbol(const GlobalValue *dcl, bool isFunc); /// Add a defined symbol to the list. - void addDefinedSymbol(const GlobalValue *def, bool isFunction); + void addDefinedSymbol(const char *Name, const GlobalValue *Def, + bool IsFunction); /// Add a function symbol as defined to the list. void addDefinedFunctionSymbol(const Function *f); + void addDefinedFunctionSymbol(const char *Name, const Function *F); /// Add a data symbol as defined to the list. void addDefinedDataSymbol(const GlobalValue *v); + void addDefinedDataSymbol(const char *Name, const GlobalValue *V); /// Add global symbols from module-level ASM to the defined or undefined /// lists. diff --git a/lib/LTO/LTOModule.cpp b/lib/LTO/LTOModule.cpp index 589ce2dd810..45e3a21df72 100644 --- a/lib/LTO/LTOModule.cpp +++ b/lib/LTO/LTOModule.cpp @@ -283,10 +283,15 @@ void LTOModule::addObjCClassRef(const GlobalVariable *clgv) { entry.setValue(info); } -/// addDefinedDataSymbol - Add a data symbol as defined to the list. -void LTOModule::addDefinedDataSymbol(const GlobalValue *v) { +void LTOModule::addDefinedDataSymbol(const GlobalValue *V) { + SmallString<64> Buffer; + _target->getNameWithPrefix(Buffer, V, _mangler); + addDefinedDataSymbol(Buffer.c_str(), V); +} + +void LTOModule::addDefinedDataSymbol(const char *Name, const GlobalValue *v) { // Add to list of defined symbols. - addDefinedSymbol(v, false); + addDefinedSymbol(Name, v, false); if (!v->hasSection() /* || !isTargetDarwin */) return; @@ -334,10 +339,15 @@ void LTOModule::addDefinedDataSymbol(const GlobalValue *v) { } } -/// addDefinedFunctionSymbol - Add a function symbol as defined to the list. -void LTOModule::addDefinedFunctionSymbol(const Function *f) { +void LTOModule::addDefinedFunctionSymbol(const Function *F) { + SmallString<64> Buffer; + _target->getNameWithPrefix(Buffer, F, _mangler); + addDefinedFunctionSymbol(Buffer.c_str(), F); +} + +void LTOModule::addDefinedFunctionSymbol(const char *Name, const Function *F) { // add to list of defined symbols - addDefinedSymbol(f, true); + addDefinedSymbol(Name, F, true); } static bool canBeHidden(const GlobalValue *GV) { @@ -364,16 +374,12 @@ static bool canBeHidden(const GlobalValue *GV) { return !GS.IsCompared; } -/// addDefinedSymbol - Add a defined symbol to the list. -void LTOModule::addDefinedSymbol(const GlobalValue *def, bool isFunction) { +void LTOModule::addDefinedSymbol(const char *Name, const GlobalValue *def, + bool isFunction) { // ignore all llvm.* symbols if (def->getName().startswith("llvm.")) return; - // string is owned by _defines - SmallString<64> Buffer; - _target->getNameWithPrefix(Buffer, def, _mangler); - // set alignment part log2() can have rounding errors uint32_t align = def->getAlignment(); uint32_t attr = align ? countTrailingZeros(align) : 0; @@ -410,14 +416,14 @@ void LTOModule::addDefinedSymbol(const GlobalValue *def, bool isFunction) { else attr |= LTO_SYMBOL_SCOPE_DEFAULT; - StringSet::value_type &entry = _defines.GetOrCreateValue(Buffer); + StringSet::value_type &entry = _defines.GetOrCreateValue(Name); entry.setValue(1); // fill information structure NameAndAttributes info; - StringRef Name = entry.getKey(); - info.name = Name.data(); - assert(info.name[Name.size()] == '\0'); + StringRef NameRef = entry.getKey(); + info.name = NameRef.data(); + assert(info.name[NameRef.size()] == '\0'); info.attributes = attr; info.isFunction = isFunction; info.symbol = def; @@ -462,9 +468,9 @@ void LTOModule::addAsmGlobalSymbol(const char *name, } if (info.isFunction) - addDefinedFunctionSymbol(cast(info.symbol)); + addDefinedFunctionSymbol(info.name, cast(info.symbol)); else - addDefinedDataSymbol(info.symbol); + addDefinedDataSymbol(info.name, info.symbol); _symbols.back().attributes &= ~LTO_SYMBOL_SCOPE_MASK; _symbols.back().attributes |= scope;