@@ -813,14 +813,7 @@ void RewriteInstance::discoverFileObjects() {
813813
814814 // For local symbols we want to keep track of associated FILE symbol name for
815815 // disambiguation by combined name.
816- StringRef FileSymbolName;
817- bool SeenFileName = false ;
818- struct SymbolRefHash {
819- size_t operator ()(SymbolRef const &S) const {
820- return std::hash<decltype (DataRefImpl::p)>{}(S.getRawDataRefImpl ().p );
821- }
822- };
823- std::unordered_map<SymbolRef, StringRef, SymbolRefHash> SymbolToFileName;
816+ std::vector<DataRefImpl> FileSymbols;
824817 for (const ELFSymbolRef &Symbol : InputFile->symbols ()) {
825818 Expected<StringRef> NameOrError = Symbol.getName ();
826819 if (NameOrError && NameOrError->starts_with (" __asan_init" )) {
@@ -846,13 +839,8 @@ void RewriteInstance::discoverFileObjects() {
846839 // and this uncertainty is causing havoc in function name matching.
847840 if (Name == " ld-temp.o" )
848841 continue ;
849- FileSymbolName = Name;
850- SeenFileName = true ;
851- continue ;
842+ FileSymbols.emplace_back (Symbol.getRawDataRefImpl ());
852843 }
853- if (!FileSymbolName.empty () &&
854- !(cantFail (Symbol.getFlags ()) & SymbolRef::SF_Global))
855- SymbolToFileName[Symbol] = FileSymbolName;
856844 }
857845
858846 // Sort symbols in the file by value. Ignore symbols from non-allocatable
@@ -1027,14 +1015,18 @@ void RewriteInstance::discoverFileObjects() {
10271015 // The <id> field is used for disambiguation of local symbols since there
10281016 // could be identical function names coming from identical file names
10291017 // (e.g. from different directories).
1030- std::string AltPrefix;
1031- auto SFI = SymbolToFileName.find (Symbol);
1032- if (SymbolType == SymbolRef::ST_Function && SFI != SymbolToFileName.end ())
1033- AltPrefix = Name + " /" + std::string (SFI->second );
1018+ auto CompareSymsByIdx = [](const DataRefImpl &A, const DataRefImpl &B) {
1019+ return A.d .b < B.d .b ;
1020+ };
1021+ DataRefImpl SymDataRef = Symbol.getRawDataRefImpl ();
1022+ auto SFI = llvm::upper_bound (FileSymbols, SymDataRef, CompareSymsByIdx);
1023+ if (SymbolType == SymbolRef::ST_Function && SFI != FileSymbols.begin ()) {
1024+ SymbolRef FileSymbol (SFI[-1 ], InputFile);
1025+ StringRef FileName = cantFail (FileSymbol.getName ());
1026+ AlternativeName = NR.uniquify (Name + " /" + FileName.str ());
1027+ }
10341028
10351029 UniqueName = NR.uniquify (Name);
1036- if (!AltPrefix.empty ())
1037- AlternativeName = NR.uniquify (AltPrefix);
10381030 }
10391031
10401032 uint64_t SymbolSize = ELFSymbolRef (Symbol).getSize ();
@@ -1285,7 +1277,7 @@ void RewriteInstance::discoverFileObjects() {
12851277 FDE->getAddressRange ());
12861278 }
12871279
1288- BC->setHasSymbolsWithFileName (SeenFileName );
1280+ BC->setHasSymbolsWithFileName (!FileSymbols. empty () );
12891281
12901282 // Now that all the functions were created - adjust their boundaries.
12911283 adjustFunctionBoundaries ();
0 commit comments