[PATCH] D129009: [llvm.analysis] Fix LTO for aliased IFuncs.As https://github.com/llvm/llvm-project/issues/56290 indicates, when an ifunc is aliased in LTO, clang will attempt to createan alias summary; however, as ifunc is not included in the module summary...

Schrodinger ZHU Yifan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 1 11:38:54 PDT 2022


SchrodingerZhu updated this revision to Diff 441756.
SchrodingerZhu retitled this revision from "[llvm.analysis] Fix LTO for aliased IFuncs." to "[llvm.analysis] Fix LTO for aliased IFuncs.

As https://github.com/llvm/llvm-project/issues/56290 indicates, 
when an ifunc is aliased in LTO, clang will attempt to create
an alias summary; however, as ifunc is not included in the 
module summary...".
SchrodingerZhu edited the summary of this revision.
SchrodingerZhu added a comment.



Updating D129009: [llvm.analysis] Fix LTO for aliased IFuncs.
=============================================================

As https://github.com/llvm/llvm-project/issues/56290 indicates, 
when an ifunc is aliased in LTO, clang will attempt to create
an alias summary; however, as ifunc is not included in the 
module summary...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129009/new/

https://reviews.llvm.org/D129009

Files:
  clang/test/Analysis/alias-indirect-function-lto.c
  llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp


Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===================================================================
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -4103,8 +4103,10 @@
 
   for (const GlobalAlias &A : M.aliases()) {
     auto *Aliasee = A.getAliaseeObject();
-    if (!Aliasee->hasName())
-      // Nameless function don't have an entry in the summary, skip it.
+    if (!Aliasee->hasName() ||
+        Aliasee->getValueID() == Value::ValueTy::GlobalIFuncVal)
+      // IFunc function and Nameless function don't have an entry in the
+      // summary, skip it.
       continue;
     auto AliasId = VE.getValueID(&A);
     auto AliaseeId = VE.getValueID(Aliasee);
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -646,23 +646,26 @@
   Index.addGlobalValueSummary(V, std::move(GVarSummary));
 }
 
-static void
-computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
-                    DenseSet<GlobalValue::GUID> &CantBePromoted) {
-  bool NonRenamableLocal = isNonRenamableLocal(A);
-  GlobalValueSummary::GVFlags Flags(
-      A.getLinkage(), A.getVisibility(), NonRenamableLocal,
-      /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
-  auto AS = std::make_unique<AliasSummary>(Flags);
+static void computeAliasSummary(ModuleSummaryIndex &Index, const GlobalAlias &A,
+                                DenseSet<GlobalValue::GUID> &CantBePromoted) {
   auto *Aliasee = A.getAliaseeObject();
-  auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
-  assert(AliaseeVI && "Alias expects aliasee summary to be available");
-  assert(AliaseeVI.getSummaryList().size() == 1 &&
-         "Expected a single entry per aliasee in per-module index");
-  AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
-  if (NonRenamableLocal)
-    CantBePromoted.insert(A.getGUID());
-  Index.addGlobalValueSummary(A, std::move(AS));
+  // Currently, skip summary for indirect function aliases as
+  // summary for aliasee will not be emitted.
+  if (Aliasee->getValueID() != Value::ValueTy::GlobalIFuncVal) {
+    bool NonRenamableLocal = isNonRenamableLocal(A);
+    GlobalValueSummary::GVFlags Flags(
+        A.getLinkage(), A.getVisibility(), NonRenamableLocal,
+        /* Live = */ false, A.isDSOLocal(), A.canBeOmittedFromSymbolTable());
+    auto AS = std::make_unique<AliasSummary>(Flags);
+    auto AliaseeVI = Index.getValueInfo(Aliasee->getGUID());
+    assert(AliaseeVI && "Alias expects aliasee summary to be available");
+    assert(AliaseeVI.getSummaryList().size() == 1 &&
+           "Expected a single entry per aliasee in per-module index");
+    AS->setAliasee(AliaseeVI, AliaseeVI.getSummaryList()[0].get());
+    if (NonRenamableLocal)
+      CantBePromoted.insert(A.getGUID());
+    Index.addGlobalValueSummary(A, std::move(AS));
+  }
 }
 
 // Set LiveRoot flag on entries matching the given value name.
Index: clang/test/Analysis/alias-indirect-function-lto.c
===================================================================
--- /dev/null
+++ clang/test/Analysis/alias-indirect-function-lto.c
@@ -0,0 +1,4 @@
+// RUN: %clang_analyze_cc1 -flto -c
+void f() __attribute__((ifunc("g")));
+static void *g() { return 0; };
+void h() __attribute__((alias("f")));
\ No newline at end of file


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129009.441756.patch
Type: text/x-patch
Size: 3482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220701/a0cd2f46/attachment.bin>


More information about the cfe-commits mailing list