1414#include " bolt/Rewrite/MetadataRewriter.h"
1515#include " bolt/Rewrite/MetadataRewriters.h"
1616#include " bolt/Utils/CommandLineOpts.h"
17+ #include " bolt/Utils/Utils.h"
1718#include " llvm/IR/Function.h"
1819#include " llvm/MC/MCPseudoProbe.h"
1920#include " llvm/Support/CommandLine.h"
@@ -133,10 +134,16 @@ void PseudoProbeRewriter::parsePseudoProbe() {
133134
134135 MCPseudoProbeDecoder::Uint64Set GuidFilter;
135136 MCPseudoProbeDecoder::Uint64Map FuncStartAddrs;
137+ SmallVector<StringRef, 3 > Suffixes ({" .destroy" , " .resume" , " .llvm." });
136138 for (const BinaryFunction *F : BC.getAllBinaryFunctions ()) {
137139 for (const MCSymbol *Sym : F->getSymbols ()) {
138- FuncStartAddrs[Function::getGUID (NameResolver::restore (Sym->getName ()))] =
139- F->getAddress ();
140+ StringRef SymName = NameResolver::restore (Sym->getName ());
141+ if (std::optional<StringRef> CommonName =
142+ getCommonName (SymName, false , Suffixes)) {
143+ SymName = *CommonName;
144+ }
145+ uint64_t GUID = Function::getGUID (SymName);
146+ FuncStartAddrs[GUID] = F->getAddress ();
140147 }
141148 }
142149 Contents = PseudoProbeSection->getContents ();
@@ -155,13 +162,25 @@ void PseudoProbeRewriter::parsePseudoProbe() {
155162 ProbeDecoder.printProbesForAllAddresses (outs ());
156163 }
157164
158- for (const auto &FuncDesc : ProbeDecoder.getGUID2FuncDescMap ()) {
159- uint64_t GUID = FuncDesc.FuncGUID ;
160- if (!FuncStartAddrs.contains (GUID))
161- continue ;
162- BinaryFunction *BF = BC.getBinaryFunctionAtAddress (FuncStartAddrs[GUID]);
163- assert (BF);
164- BF->setGUID (GUID);
165+ const GUIDProbeFunctionMap &GUID2Func = ProbeDecoder.getGUID2FuncDescMap ();
166+ // Checks GUID in GUID2Func and returns it if it's present or null otherwise.
167+ auto checkGUID = [&](StringRef SymName) {
168+ uint64_t GUID = Function::getGUID (SymName);
169+ if (GUID2Func.find (GUID) == GUID2Func.end ())
170+ return 0ull ;
171+ return GUID;
172+ };
173+ for (BinaryFunction *F : BC.getAllBinaryFunctions ()) {
174+ for (const MCSymbol *Sym : F->getSymbols ()) {
175+ StringRef SymName = NameResolver::restore (Sym->getName ());
176+ uint64_t GUID = checkGUID (SymName);
177+ std::optional<StringRef> CommonName =
178+ getCommonName (SymName, false , Suffixes);
179+ if (!GUID && CommonName)
180+ GUID = checkGUID (*CommonName);
181+ if (GUID)
182+ F->setGUID (GUID);
183+ }
165184 }
166185}
167186
0 commit comments