[lld] [llvm] [PseudoProbe] Include function hash in descriptor COMDAT key (PR #190296)

Wei Xiao via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 01:16:00 PDT 2026


================
@@ -1339,31 +1339,37 @@ MCObjectFileInfo::getPseudoProbeSection(const MCSection &TextSec) const {
 }
 
 MCSection *
-MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName) const {
+MCObjectFileInfo::getPseudoProbeDescSection(StringRef FuncName,
+                                            uint64_t FuncHash) const {
   if (!Ctx->getTargetTriple().supportsCOMDAT() || FuncName.empty())
     return PseudoProbeDescSection;
 
   // Create a separate comdat group for each function's descriptor in order
   // for the linker to deduplicate. The duplication, must be from different
-  // tranlation unit, can come from:
+  // translation unit, can come from:
   //  1. Inline functions defined in header files;
-  //  2. ThinLTO imported funcions;
+  //  2. ThinLTO imported functions;
   //  3. Weak-linkage definitions.
-  // Use a concatenation of the section name and the function name as the
-  // group name so that descriptor-only groups won't be folded with groups of
-  // code.
+  // Use a concatenation of the section name, function name, and function hash
+  // as the group name so that descriptors with different hashes (due to user
+  // code not following ODR or compiler codegen inconsistencies) get separate
+  // COMDAT sections instead of being silently dropped (ELF) or causing linker
+  // errors (COFF). Duplicate GUIDs with mismatching hashes are detected
+  // during descriptor decoding and reported by llvm-profgen.
+  std::string HashSuffix = "." + Twine::utohexstr(FuncHash).str();
----------------
williamweixiao wrote:

Not a correctness issue — just avoids an extra allocation. 
This materializes the Twine to a `std::string` via `.str()`, then prepends `"."` creating another `std::string`. Since it's immediately concatenated into another Twine expression on lines 1366/1372, you could avoid the intermediate `std::string`:
```cpp
// Use directly in the Twine concatenation:
S->getName() + "_" + FuncName + "." + Twine::utohexstr(FuncHash)
```


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


More information about the llvm-commits mailing list