[PATCH] D149721: EntryExitInstrumenter: skip naked functions

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue May 2 21:44:55 PDT 2023


MaskRay updated this revision to Diff 518967.
MaskRay added a comment.

add a comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D149721

Files:
  llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
  llvm/test/Transforms/EntryExitInstrumenter/mcount.ll


Index: llvm/test/Transforms/EntryExitInstrumenter/mcount.ll
===================================================================
--- llvm/test/Transforms/EntryExitInstrumenter/mcount.ll
+++ llvm/test/Transforms/EntryExitInstrumenter/mcount.ll
@@ -99,6 +99,13 @@
 ; CHECK: ret
 }
 
+;; naked functions are not instrumented, otherwise the argument registers
+;; and the return address register (if present) would be clobbered.
+define void @naked() naked { entry: ret void }
+; CHECK-LABEL:      define void @naked(
+; CHECK-LABEL-NEXT: entry:
+; CHECK-LABEL-NEXT:   ret void
+
 ; The attributes are "consumed" when the instrumentation is inserted.
 ; CHECK: attributes
 ; CHECK-NOT: instrument-function
Index: llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
===================================================================
--- llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
+++ llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
@@ -80,6 +80,13 @@
 }
 
 static bool runOnFunction(Function &F, bool PostInlining) {
+  // The asm in a naked function may reasonably expect the argument registers
+  // and the return address register (if present) to be live. An inserted
+  // function call will clobber these registers. Simply skip naked functions for
+  // all targets.
+  if (F.hasFnAttribute(Attribute::Naked))
+    return false;
+
   StringRef EntryAttr = PostInlining ? "instrument-function-entry-inlined"
                                      : "instrument-function-entry";
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149721.518967.patch
Type: text/x-patch
Size: 1491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230503/78f7f559/attachment.bin>


More information about the llvm-commits mailing list