Skip to content

Commit b1cbdd0

Browse files
committed
Fixup overwritten DWARF symbol name when decoding pseudo probe
1 parent b6ae0ba commit b1cbdd0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

llvm/tools/llvm-profgen/ProfiledBinary.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,14 @@ void ProfiledBinary::populateSymbolAddressList(const ObjectFile *Obj) {
828828
SymbolStartAddrs[GUID] = Addr;
829829
StartAddrToSymMap.emplace(Addr, GUID);
830830
}
831+
832+
// Load DWARF name too if they are overwritten by the symbol table
833+
for (auto [OldGUID, Func] : OverriddenBinaryFunctions) {
834+
uint64_t GUID = Function::getGUIDAssumingExternalLinkage(Func->FuncName);
835+
uint64_t Addr = SymbolStartAddrs[GUID];
836+
SymbolStartAddrs[OldGUID] = Addr;
837+
StartAddrToSymMap.emplace(Addr, OldGUID);
838+
}
831839
}
832840

833841
void ProfiledBinary::loadSymbolsFromSymtab(const ObjectFile *Obj) {
@@ -903,13 +911,16 @@ void ProfiledBinary::loadSymbolsFromSymtab(const ObjectFile *Obj) {
903911
if (!Ret.second)
904912
continue;
905913

914+
uint64_t OldGUID = MD5Hash(Range->getFuncName());
915+
906916
Func.FuncName = Ret.first->first;
907917
Func.Ranges = ErrSym->second.Ranges;
908918
Func.FromSymtab = true;
909919

910-
HashBinaryFunctions.erase(MD5Hash(Range->getFuncName()));
920+
HashBinaryFunctions.erase(OldGUID);
911921
BinaryFunctions.erase(ErrSym);
912922

923+
OverriddenBinaryFunctions[OldGUID] = &Func;
913924
HashBinaryFunctions[MD5Hash(StringRef(SymName))] = &Func;
914925
Range->Func = &Func;
915926
for (auto [RangeStart, _] : Func.Ranges) {

llvm/tools/llvm-profgen/ProfiledBinary.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ class ProfiledBinary {
232232
// GUID to symbol start address map
233233
DenseMap<uint64_t, uint64_t> SymbolStartAddrs;
234234

235+
// GUID mapping of the overridden DWARF symbol names to the binary functions
236+
// with the symbol table names
237+
std::unordered_map<uint64_t, BinaryFunction *> OverriddenBinaryFunctions;
238+
235239
// These maps are for temporary use of warning diagnosis.
236240
DenseSet<int64_t> AddrsWithMultipleSymbols;
237241
DenseSet<std::pair<uint64_t, uint64_t>> AddrsWithInvalidInstruction;

0 commit comments

Comments
 (0)