[PATCH] D149721: EntryExitInstrumenter: skip naked functions

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 4 09:21:31 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG3460f727eaa3: EntryExitInstrumenter: skip naked functions (authored by MaskRay).

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.519524.patch
Type: text/x-patch
Size: 1491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230504/6acc6a94/attachment.bin>


More information about the llvm-commits mailing list