[llvm] [llvm-profgen][NFC] Fix dereference of empty function range when --disassemble-functions for symbols with no range (PR #219117)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 26 22:36:30 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-pgo

Author: Wei Wang (apolloww)

<details>
<summary>Changes</summary>

When `--show-disassembly-only` is combined with `--disassemble-functions`, `decodePseudoProbe()` looks up each requested function's start address. If the start address has no entry in `StartAddrToFuncRangeMap`, `[]` operator returns an empty function range which causes crash when `getFuncName()` dereferences it. Look the range up instead of creating one, and fall back to the symbol's own GUID when there is none, so the requested function is still decoded.

Also fix a typo in `--disassemble-functions` help text. `SymbolStartAddrs` is keyed by the GUID of the raw symbol name, so mangled names are what actually resolve. 

---
Full diff: https://github.com/llvm/llvm-project/pull/219117.diff


1 Files Affected:

- (modified) llvm/tools/llvm-profgen/ProfiledBinary.cpp (+8-7) 


``````````diff
diff --git a/llvm/tools/llvm-profgen/ProfiledBinary.cpp b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
index 2d147d0af7353..9c70529f1e92a 100644
--- a/llvm/tools/llvm-profgen/ProfiledBinary.cpp
+++ b/llvm/tools/llvm-profgen/ProfiledBinary.cpp
@@ -72,7 +72,7 @@ static cl::opt<std::string>
 
 static cl::list<std::string> DisassembleFunctions(
     "disassemble-functions", cl::CommaSeparated,
-    cl::desc("List of functions to print disassembly for. Accept demangled "
+    cl::desc("List of functions to print disassembly for. Accept mangled "
              "names only. Only work with show-disassembly-only"),
     cl::cat(ProfGenCategory));
 
@@ -167,9 +167,8 @@ void BinarySizeContextTracker::trackInlineesOptimizedAway(
     for (auto &ProbeFrame : reverse(ProbeContext)) {
       StringRef CallerName = ProbeFrame.first;
       LineLocation CallsiteLoc(ProbeFrame.second, 0);
-      SizeContext =
-          SizeContext->getOrCreateChildContext(CallsiteLoc,
-                                               FunctionId(CallerName));
+      SizeContext = SizeContext->getOrCreateChildContext(
+          CallsiteLoc, FunctionId(CallerName));
     }
     // Add 0 size to make known.
     SizeContext->addFunctionSize(0);
@@ -501,9 +500,11 @@ void ProfiledBinary::decodePseudoProbe(const ObjectFile *Obj) {
         auto GUID = Function::getGUIDAssumingExternalLinkage(F.first());
         if (auto StartAddr = SymbolStartAddrs.lookup(GUID)) {
           FuncStartAddresses[GUID] = StartAddr;
-          FuncRange &Range = StartAddrToFuncRangeMap[StartAddr];
-          GuidFilter.insert(
-              Function::getGUIDAssumingExternalLinkage(Range.getFuncName()));
+          if (FuncRange *Range = findFuncRangeForStartAddr(StartAddr))
+            GuidFilter.insert(
+                Function::getGUIDAssumingExternalLinkage(Range->getFuncName()));
+          else
+            GuidFilter.insert(GUID);
         }
       }
     }

``````````

</details>


https://github.com/llvm/llvm-project/pull/219117


More information about the llvm-commits mailing list