Skip to content

[StackSafetyAnalysis] Bail out when calling ifunc #113841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Oct 27, 2024

An assertion failure arises when a call instruction calls a GlobalIFunc.
Since we cannot reason about the underlying function, just bail out.

Fix #87923

Created using spr 1.3.5-bogner
@llvmbot llvmbot added the llvm:analysis Includes value tracking, cost tables and constant folding label Oct 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2024

@llvm/pr-subscribers-llvm-analysis

Author: Fangrui Song (MaskRay)

Changes

An assertion failure arises when a call instruction calls a GlobalIFunc.
Since we cannot reason about the underlying function, just bail out.

Fix #87923


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

2 Files Affected:

  • (modified) llvm/lib/Analysis/StackSafetyAnalysis.cpp (+1-1)
  • (modified) llvm/test/Analysis/StackSafetyAnalysis/local.ll (+16)
diff --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
index 27360d0e84cb2b..5d81658409dae8 100644
--- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -528,7 +528,7 @@ void StackSafetyLocalAnalysis::analyzeAllUses(Value *Ptr,
         // dso_preemptable aliases or aliases with interposable linkage.
         const GlobalValue *Callee =
             dyn_cast<GlobalValue>(CB.getCalledOperand()->stripPointerCasts());
-        if (!Callee) {
+        if (!Callee || isa<GlobalIFunc>(Callee)) {
           US.addRange(I, UnknownRange, /*IsSafe=*/false);
           break;
         }
diff --git a/llvm/test/Analysis/StackSafetyAnalysis/local.ll b/llvm/test/Analysis/StackSafetyAnalysis/local.ll
index 4a833611c78916..02d46c8449bae5 100644
--- a/llvm/test/Analysis/StackSafetyAnalysis/local.ll
+++ b/llvm/test/Analysis/StackSafetyAnalysis/local.ll
@@ -1120,5 +1120,21 @@ define void @NonPointer(ptr %p) {
   ret void
 }
 
+@ifunc = dso_local ifunc i64 (ptr), ptr @ifunc_resolver
+
+define dso_local void @CallIfunc(ptr noundef %uaddr) local_unnamed_addr {
+; CHECK-LABEL: @CallIfunc
+; CHECK-NEXT:  args uses:
+; CHECK-NEXT:    uaddr[]: full-set
+entry:
+  tail call i64 @ifunc(ptr noundef %uaddr)
+  ret void
+}
+
+define dso_local ptr @ifunc_resolver() {
+entry:
+  ret ptr null
+}
+
 declare void @llvm.lifetime.start.p0(i64, ptr nocapture)
 declare void @llvm.lifetime.end.p0(i64, ptr nocapture)

Copy link
Collaborator

@DimitryAndric DimitryAndric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this works for me, both for the original test case, and for a full FreeBSD buildworld using WITH_ASAN.

freebsd-git pushed a commit to freebsd/freebsd-src that referenced this pull request Oct 28, 2024
Building world using WITH_ASAN results in an assertion when compiling
certain source files referencing ifuncs:

  Assertion failed: (isa<Function>(Callee) || isa<GlobalAlias>(Callee)), function analyzeAllUses, file /root/freebsd/contrib/llvm-project/llvm/lib/Analysis/StackSafetyAnalysis.cpp, line 514.

This was already reported upstream a while ago, in
<llvm/llvm-project#87923>, but now there is
finally a candidate fix, which seems trivial so I am importing it right
away.

Reported by:	markj
PR:		280936
Pull Request:	llvm/llvm-project#113841
MFC after:	3 days
@MaskRay MaskRay merged commit 318bdd0 into main Oct 29, 2024
10 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/stacksafetyanalysis-bail-out-when-calling-ifunc branch October 29, 2024 16:26
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this pull request Nov 2, 2024
Building world using WITH_ASAN results in an assertion when compiling
certain source files referencing ifuncs:

  Assertion failed: (isa<Function>(Callee) || isa<GlobalAlias>(Callee)), function analyzeAllUses, file /root/freebsd/contrib/llvm-project/llvm/lib/Analysis/StackSafetyAnalysis.cpp, line 514.

This was already reported upstream a while ago, in
<llvm/llvm-project#87923>, but now there is
finally a candidate fix, which seems trivial so I am importing it right
away.

Reported by:	markj
PR:		280936
Pull Request:	llvm/llvm-project#113841
MFC after:	3 days

(cherry picked from commit f3457ed)
freebsd-git pushed a commit to freebsd/freebsd-src that referenced this pull request Nov 2, 2024
Building world using WITH_ASAN results in an assertion when compiling
certain source files referencing ifuncs:

  Assertion failed: (isa<Function>(Callee) || isa<GlobalAlias>(Callee)), function analyzeAllUses, file /root/freebsd/contrib/llvm-project/llvm/lib/Analysis/StackSafetyAnalysis.cpp, line 514.

This was already reported upstream a while ago, in
<llvm/llvm-project#87923>, but now there is
finally a candidate fix, which seems trivial so I am importing it right
away.

Reported by:	markj
PR:		280936
Pull Request:	llvm/llvm-project#113841
MFC after:	3 days

(cherry picked from commit f3457ed)
NoumanAmir657 pushed a commit to NoumanAmir657/llvm-project that referenced this pull request Nov 4, 2024
An assertion failure arises when a call instruction calls a GlobalIFunc.
Since we cannot reason about the underlying function, just bail out.

Fix llvm#87923

Pull Request: llvm#113841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:analysis Includes value tracking, cost tables and constant folding
Projects
None yet
Development

Successfully merging this pull request may close these issues.

After 7740565f56ce, "Assertion failed: (isa<Function>(Callee) || isa<GlobalAlias>(Callee)), function analyzeAllUses" with -asan-use-stack-safety
3 participants