[llvm] [MergeFunctions] keep the symbol of a function an alias points at on COFF (PR #222024)

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 10:55:07 PDT 2026


================
@@ -864,6 +864,43 @@ static bool canCreateAliasFor(Function *F) {
   return true;
 }
 
+/// Returns true if an alias that is visible to other objects points at \p F.
+static bool hasNonLocalAlias(const Function *F) {
+  for (const GlobalAlias &GA : F->getParent()->aliases())
+    if (!GA.hasLocalLinkage() && GA.getAliaseeObject() == F)
+      return true;
+  return false;
+}
+
+/// COFF names the fallback symbol of a local alias target after unrelated
+/// contents of the object, so two objects defining the alias disagree
+/// (LNK1227).
+static bool needsStableSymbolForAlias(const Function *F) {
+  return F->getParent()->getTargetTriple().isOSBinFormatCOFF();
+}
+
+/// Names \p F after its structural hash, so that every object merging this body
+/// agrees, and folds the copies with a COMDAT. Returns false if it could not.
+static bool giveStableSymbolForAlias(Function *F) {
+  Module *M = F->getParent();
+  if (F->hasLocalLinkage() || !F->hasName()) {
+    std::string Name =
+        ("__llvm_mergefunc_" + Twine::utohexstr(StructuralHash(*F))).str();
+    if (M->getNamedValue(Name))
+      return false;
----------------
compnerd wrote:

Is this for collision detection or does this indicate that the function already exists and should be used? If so, this should perhaps be `getOrCreateStableLabel`?

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


More information about the llvm-commits mailing list