[BOLT] Store FileSymRefs in a multimap
With aggressive ICF, it's possible to have different local symbols (under different FILE symbols) to be mapped to the same address. FileSymRefs only keeps a single SymbolRef per address, which prevents fragment matching from finding the correct symbol to perform parent function lookup. Work around this issue by switching FileSymRefs to a multimap. In future, uses of FileSymRefs can be replaced with SortedSymbols which keeps essentially the same information. Test Plan: added ambiguous_fragment.test Reviewers: dcci, ayermolo, maksfb, rafaelauler Reviewed By: rafaelauler Pull Request: https://github.com/llvm/llvm-project/pull/98992
This commit is contained in:
@@ -886,7 +886,7 @@ void RewriteInstance::discoverFileObjects() {
|
||||
if (SymName == "__hot_start" || SymName == "__hot_end")
|
||||
continue;
|
||||
|
||||
FileSymRefs[SymbolAddress] = Symbol;
|
||||
FileSymRefs.emplace(SymbolAddress, Symbol);
|
||||
|
||||
// Skip section symbols that will be registered by disassemblePLT().
|
||||
if (SymbolType == SymbolRef::ST_Debug) {
|
||||
@@ -1052,7 +1052,9 @@ void RewriteInstance::discoverFileObjects() {
|
||||
|
||||
// Remove the symbol from FileSymRefs so that we can skip it from
|
||||
// in the future.
|
||||
auto SI = FileSymRefs.find(SymbolAddress);
|
||||
auto SI = llvm::find_if(
|
||||
llvm::make_range(FileSymRefs.equal_range(SymbolAddress)),
|
||||
[&](auto SymIt) { return SymIt.second == Symbol; });
|
||||
assert(SI != FileSymRefs.end() && "symbol expected to be present");
|
||||
assert(SI->second == Symbol && "wrong symbol found");
|
||||
FileSymRefs.erase(SI);
|
||||
@@ -1260,6 +1262,7 @@ void RewriteInstance::discoverFileObjects() {
|
||||
|
||||
registerFragments();
|
||||
FileSymbols.clear();
|
||||
FileSymRefs.clear();
|
||||
|
||||
discoverBOLTReserved();
|
||||
}
|
||||
@@ -1433,7 +1436,11 @@ void RewriteInstance::registerFragments() {
|
||||
const uint64_t Address = BF->getAddress();
|
||||
|
||||
// Get fragment's own symbol
|
||||
const auto SymIt = FileSymRefs.find(Address);
|
||||
const auto SymIt = llvm::find_if(
|
||||
llvm::make_range(FileSymRefs.equal_range(Address)), [&](auto SI) {
|
||||
StringRef Name = cantFail(SI.second.getName());
|
||||
return Name.contains(ParentName);
|
||||
});
|
||||
if (SymIt == FileSymRefs.end()) {
|
||||
BC->errs()
|
||||
<< "BOLT-ERROR: symbol lookup failed for function at address 0x"
|
||||
|
||||
Reference in New Issue
Block a user