@@ -813,14 +813,8 @@ 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
816
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;
817
+ std::vector<std::pair<DataRefImpl, StringRef>> FileSymbols;
824
818
for (const ELFSymbolRef &Symbol : InputFile->symbols ()) {
825
819
Expected<StringRef> NameOrError = Symbol.getName ();
826
820
if (NameOrError && NameOrError->starts_with (" __asan_init" )) {
@@ -846,13 +840,10 @@ void RewriteInstance::discoverFileObjects() {
846
840
// and this uncertainty is causing havoc in function name matching.
847
841
if (Name == " ld-temp.o" )
848
842
continue ;
849
- FileSymbolName = Name;
843
+ FileSymbols. emplace_back (Symbol. getRawDataRefImpl (), Name) ;
850
844
SeenFileName = true ;
851
845
continue ;
852
846
}
853
- if (!FileSymbolName.empty () &&
854
- !(cantFail (Symbol.getFlags ()) & SymbolRef::SF_Global))
855
- SymbolToFileName[Symbol] = FileSymbolName;
856
847
}
857
848
858
849
// Sort symbols in the file by value. Ignore symbols from non-allocatable
@@ -1027,14 +1018,18 @@ void RewriteInstance::discoverFileObjects() {
1027
1018
// The <id> field is used for disambiguation of local symbols since there
1028
1019
// could be identical function names coming from identical file names
1029
1020
// (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 );
1021
+ auto CompareSymsByIdx = [](const std::pair<DataRefImpl, StringRef> &A,
1022
+ const std::pair<DataRefImpl, StringRef> &B) {
1023
+ return A.first .d .b < B.first .d .b ;
1024
+ };
1025
+ DataRefImpl SymDataRef = Symbol.getRawDataRefImpl ();
1026
+ auto SFI = llvm::upper_bound (FileSymbols,
1027
+ std::make_pair (SymDataRef, StringRef ()),
1028
+ CompareSymsByIdx);
1029
+ if (SymbolType == SymbolRef::ST_Function && SFI != FileSymbols.begin ())
1030
+ AlternativeName = NR.uniquify (Name + " /" + SFI[-1 ].second .str ());
1034
1031
1035
1032
UniqueName = NR.uniquify (Name);
1036
- if (!AltPrefix.empty ())
1037
- AlternativeName = NR.uniquify (AltPrefix);
1038
1033
}
1039
1034
1040
1035
uint64_t SymbolSize = ELFSymbolRef (Symbol).getSize ();
0 commit comments