[llvm] [llvm-profgen] Loading binary functions from .symtab when DWARF info is incomplete (PR #163654)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Tue Oct 21 11:06:15 PDT 2025
    
    
  
================
@@ -820,6 +822,48 @@ void ProfiledBinary::populateSymbolAddressList(const ObjectFile *Obj) {
   }
 }
 
+void ProfiledBinary::populateSymbolsFromBinary(const ObjectFile *Obj) {
+  // Load binary functions from symbol table when Debug info is incomplete
+  StringRef FileName = Obj->getFileName();
+  for (const SymbolRef &Symbol : Obj->symbols()) {
+    const SymbolRef::Type Type = unwrapOrError(Symbol.getType(), FileName);
+    const uint64_t Addr = unwrapOrError(Symbol.getAddress(), FileName);
+    const StringRef Name = unwrapOrError(Symbol.getName(), FileName);
+    const uint64_t Size = Symbol.getSize();
+
+    if (Size == 0 || Type != SymbolRef::ST_Function)
+      continue;
+
+    const char *Suffixes[] = {".destroy", ".resume", ".llvm.",
+                              ".cold",    ".warm",   nullptr};
+    const StringRef SymName =
+        FunctionSamples::getCanonicalFnName(Name, Suffixes);
+
+    auto Ret = BinaryFunctions.emplace(SymName, BinaryFunction());
+    auto &Func = Ret.first->second;
+    if (Ret.second)
+      Func.FuncName = Ret.first->first;
+
+    if (auto Range = findFuncRange(Addr)) {
+      if (Ret.second && ShowDetailedWarning)
+        WithColor::warning()
----------------
HighW4y2H3ll wrote:
I think the `Ret.second` check shall skip all the symbols that already obtained from DWARF. (the symbol name will exists in the `BinaryFunctions` and the `emplace` shall prevent the insertation and `Ret.second` will be set to "false")
https://github.com/llvm/llvm-project/blob/e12e694c1b9e3563dd8351e225b7acec05e12d5a/llvm/tools/llvm-profgen/ProfiledBinary.cpp#L842
https://github.com/llvm/llvm-project/pull/163654
    
    
More information about the llvm-commits
mailing list