@@ -813,14 +813,7 @@ void RewriteInstance::discoverFileObjects() {
813
813
814
814
// For local symbols we want to keep track of associated FILE symbol name for
815
815
// 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;
824
817
for (const ELFSymbolRef &Symbol : InputFile->symbols ()) {
825
818
Expected<StringRef> NameOrError = Symbol.getName ();
826
819
if (NameOrError && NameOrError->starts_with (" __asan_init" )) {
@@ -846,13 +839,9 @@ void RewriteInstance::discoverFileObjects() {
846
839
// and this uncertainty is causing havoc in function name matching.
847
840
if (Name == " ld-temp.o" )
848
841
continue ;
849
- FileSymbolName = Name;
850
- SeenFileName = true ;
842
+ FileSymbols.emplace_back (Symbol.getRawDataRefImpl ());
851
843
continue ;
852
844
}
853
- if (!FileSymbolName.empty () &&
854
- !(cantFail (Symbol.getFlags ()) & SymbolRef::SF_Global))
855
- SymbolToFileName[Symbol] = FileSymbolName;
856
845
}
857
846
858
847
// Sort symbols in the file by value. Ignore symbols from non-allocatable
@@ -1027,14 +1016,18 @@ void RewriteInstance::discoverFileObjects() {
1027
1016
// The <id> field is used for disambiguation of local symbols since there
1028
1017
// could be identical function names coming from identical file names
1029
1018
// (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 );
1019
+ auto CompareSymsByIdx = [](const DataRefImpl &A, const DataRefImpl &B) {
1020
+ return A.d .b < B.d .b ;
1021
+ };
1022
+ DataRefImpl SymDataRef = Symbol.getRawDataRefImpl ();
1023
+ auto SFI = llvm::upper_bound (FileSymbols, SymDataRef, CompareSymsByIdx);
1024
+ if (SymbolType == SymbolRef::ST_Function && SFI != FileSymbols.begin ()) {
1025
+ SymbolRef FileSymbol (SFI[-1 ], InputFile);
1026
+ StringRef FileName = cantFail (FileSymbol.getName ());
1027
+ AlternativeName = NR.uniquify (Name + " /" + FileName.str ());
1028
+ }
1034
1029
1035
1030
UniqueName = NR.uniquify (Name);
1036
- if (!AltPrefix.empty ())
1037
- AlternativeName = NR.uniquify (AltPrefix);
1038
1031
}
1039
1032
1040
1033
uint64_t SymbolSize = ELFSymbolRef (Symbol).getSize ();
@@ -1285,7 +1278,7 @@ void RewriteInstance::discoverFileObjects() {
1285
1278
FDE->getAddressRange ());
1286
1279
}
1287
1280
1288
- BC->setHasSymbolsWithFileName (SeenFileName );
1281
+ BC->setHasSymbolsWithFileName (!FileSymbols. empty () );
1289
1282
1290
1283
// Now that all the functions were created - adjust their boundaries.
1291
1284
adjustFunctionBoundaries ();
0 commit comments