Skip to content

Commit cef8fc7

Browse files
committed
[BOLT][NFC] Keep FILE symbols in a vector
In discoverFileObjects, replace mapping from every local symbol to associated file name with a vector of symbol data for FILE symbols only. This cuts down on memory needed to resolve local file names. Test Plan: NFC
1 parent 2b86fb2 commit cef8fc7

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -813,14 +813,8 @@ 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;
817816
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;
824818
for (const ELFSymbolRef &Symbol : InputFile->symbols()) {
825819
Expected<StringRef> NameOrError = Symbol.getName();
826820
if (NameOrError && NameOrError->starts_with("__asan_init")) {
@@ -846,13 +840,10 @@ void RewriteInstance::discoverFileObjects() {
846840
// and this uncertainty is causing havoc in function name matching.
847841
if (Name == "ld-temp.o")
848842
continue;
849-
FileSymbolName = Name;
843+
FileSymbols.emplace_back(Symbol.getRawDataRefImpl(), Name);
850844
SeenFileName = true;
851845
continue;
852846
}
853-
if (!FileSymbolName.empty() &&
854-
!(cantFail(Symbol.getFlags()) & SymbolRef::SF_Global))
855-
SymbolToFileName[Symbol] = FileSymbolName;
856847
}
857848

858849
// Sort symbols in the file by value. Ignore symbols from non-allocatable
@@ -1027,14 +1018,18 @@ void RewriteInstance::discoverFileObjects() {
10271018
// The <id> field is used for disambiguation of local symbols since there
10281019
// could be identical function names coming from identical file names
10291020
// (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());
10341031

10351032
UniqueName = NR.uniquify(Name);
1036-
if (!AltPrefix.empty())
1037-
AlternativeName = NR.uniquify(AltPrefix);
10381033
}
10391034

10401035
uint64_t SymbolSize = ELFSymbolRef(Symbol).getSize();

0 commit comments

Comments
 (0)