@@ -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,8 @@ 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 ;
851
- continue ;
842
+ FileSymbols.emplace_back (Symbol.getRawDataRefImpl ());
852
843
}
853
- if (!FileSymbolName.empty () &&
854
- !(cantFail (Symbol.getFlags ()) & SymbolRef::SF_Global))
855
- SymbolToFileName[Symbol] = FileSymbolName;
856
844
}
857
845
858
846
// Sort symbols in the file by value. Ignore symbols from non-allocatable
@@ -1027,14 +1015,18 @@ void RewriteInstance::discoverFileObjects() {
1027
1015
// The <id> field is used for disambiguation of local symbols since there
1028
1016
// could be identical function names coming from identical file names
1029
1017
// (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
+ }
1034
1028
1035
1029
UniqueName = NR.uniquify (Name);
1036
- if (!AltPrefix.empty ())
1037
- AlternativeName = NR.uniquify (AltPrefix);
1038
1030
}
1039
1031
1040
1032
uint64_t SymbolSize = ELFSymbolRef (Symbol).getSize ();
@@ -1285,7 +1277,7 @@ void RewriteInstance::discoverFileObjects() {
1285
1277
FDE->getAddressRange ());
1286
1278
}
1287
1279
1288
- BC->setHasSymbolsWithFileName (SeenFileName );
1280
+ BC->setHasSymbolsWithFileName (!FileSymbols. empty () );
1289
1281
1290
1282
// Now that all the functions were created - adjust their boundaries.
1291
1283
adjustFunctionBoundaries ();
0 commit comments