Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -595,9 +595,19 @@ Sym->VersionId = Version; } +static bool hasExternCpp() { + for (VersionDefinition &V : Config->VersionDefinitions) + for (SymbolVersion Sym : V.Globals) + if (Sym.IsExternCpp) + return true; + return false; +} + template std::map SymbolTable::getDemangledSyms() { std::map Result; + if (!hasExternCpp()) + return Result; for (Symbol *Sym : SymVector) { SymbolBody *B = Sym->body(); Result[demangle(B->getName())] = B; @@ -605,12 +615,12 @@ return Result; } -static bool hasExternCpp() { - for (VersionDefinition &V : Config->VersionDefinitions) - for (SymbolVersion Sym : V.Globals) - if (Sym.IsExternCpp) - return true; - return false; +static SymbolBody *findDemangled(const std::map &D, + StringRef Name) { + auto I = D.find(Name); + if (I != D.end()) + return I->second; + return nullptr; } // This function processes the --version-script option by marking all global @@ -639,16 +649,15 @@ // matching version tag in the file). // Handle exact matches and build a map of demangled externs for // quick search during next step. - std::map Demangled; - if (hasExternCpp()) - Demangled = getDemangledSyms(); + const std::map Demangled = getDemangledSyms(); for (VersionDefinition &V : Config->VersionDefinitions) { for (SymbolVersion Sym : V.Globals) { if (hasWildcard(Sym.Name)) continue; - SymbolBody *B = Sym.IsExternCpp ? Demangled[Sym.Name] : find(Sym.Name); - setVersionId(B, V.Name, Sym.Name, V.Id); + StringRef N = Sym.Name; + SymbolBody *B = Sym.IsExternCpp ? findDemangled(Demangled, N) : find(N); + setVersionId(B, V.Name, N, V.Id); } }