[llvm] EntryExitInstrumenter: skip available_externally linkage (PR #121452)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 1 21:17:25 PST 2025


https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/121452

>From 9d4dab48b232c250d7f890f6f1a288476796c7bf Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Wed, 1 Jan 2025 21:03:28 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5-bogner
---
 llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp  | 6 ++++++
 llvm/test/Transforms/EntryExitInstrumenter/mcount.ll | 7 +++++++
 2 files changed, 13 insertions(+)

diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
index 5b33edd51cffa6..8dd54a0bc25ebd 100644
--- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
+++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
@@ -103,6 +103,12 @@ static bool runOnFunction(Function &F, bool PostInlining) {
   if (F.hasFnAttribute(Attribute::Naked))
     return false;
 
+  // available_externally functions may not have definitions external to the
+  // module (e.g. gnu::always_inline). Instrumenting them would lead to linker
+  // errors. Skip them like GCC.
+  if (F.hasAvailableExternallyLinkage())
+    return false;
+
   StringRef EntryAttr = PostInlining ? "instrument-function-entry-inlined"
                                      : "instrument-function-entry";
 
diff --git a/llvm/test/Transforms/EntryExitInstrumenter/mcount.ll b/llvm/test/Transforms/EntryExitInstrumenter/mcount.ll
index bd5f4c2b51a896..56ccfb9ed2e7e0 100644
--- a/llvm/test/Transforms/EntryExitInstrumenter/mcount.ll
+++ b/llvm/test/Transforms/EntryExitInstrumenter/mcount.ll
@@ -129,6 +129,13 @@ define void @naked() naked {
   ret void
 }
 
+define available_externally void @always_inline() {
+; CHECK-LABEL: define available_externally void @always_inline() {
+; CHECK-NEXT:    ret void
+;
+  ret void
+}
+
 ; The attributes are "consumed" when the instrumentation is inserted.
 ; CHECK: attributes
 ; CHECK-NOT: instrument-function

>From 847063cd84fc4f6de9b9c14f429728ce1dffb559 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Wed, 1 Jan 2025 21:17:16 -0800
Subject: [PATCH 2/2] .

Created using spr 1.3.5-bogner
---
 llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
index 8dd54a0bc25ebd..d47f1b4253b541 100644
--- a/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
+++ b/llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
@@ -104,8 +104,8 @@ static bool runOnFunction(Function &F, bool PostInlining) {
     return false;
 
   // available_externally functions may not have definitions external to the
-  // module (e.g. gnu::always_inline). Instrumenting them would lead to linker
-  // errors. Skip them like GCC.
+  // module (e.g. gnu::always_inline). Instrumenting them might lead to linker
+  // errors if they are optimized out. Skip them like GCC.
   if (F.hasAvailableExternallyLinkage())
     return false;
 



More information about the llvm-commits mailing list