From: Manoj Gupta Date: Fri, 2 Mar 2018 23:52:44 +0000 (+0000) Subject: Do not generate calls to fentry with __attribute__((no_instrument_function)) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=284236c047631c8b0eabac3ddd3d0c95253f4361;p=clang Do not generate calls to fentry with __attribute__((no_instrument_function)) Summary: Currently only calls to mcount were suppressed with no_instrument_function attribute. Linux kernel requires that calls to fentry should also not be generated. This is an extended fix for PR PR33515. Reviewers: hfinkel, rengolin, srhines, rnk, rsmith, rjmccall, hans Reviewed By: rjmccall Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D43995 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@326639 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 38c679abf6..2f814a7165 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -1016,10 +1016,12 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, // The attribute "counting-function" is set to mcount function name which is // architecture dependent. if (CGM.getCodeGenOpts().InstrumentForProfiling) { - if (CGM.getCodeGenOpts().CallFEntry) - Fn->addFnAttr("fentry-call", "true"); - else { - if (!CurFuncDecl || !CurFuncDecl->hasAttr()) { + // Calls to fentry/mcount should not be generated if function has + // the no_instrument_function attribute. + if (!CurFuncDecl || !CurFuncDecl->hasAttr()) { + if (CGM.getCodeGenOpts().CallFEntry) + Fn->addFnAttr("fentry-call", "true"); + else { Fn->addFnAttr("instrument-function-entry-inlined", getTarget().getMCountName()); } diff --git a/test/CodeGen/fentry.c b/test/CodeGen/fentry.c index b9133184e4..43586c4563 100644 --- a/test/CodeGen/fentry.c +++ b/test/CodeGen/fentry.c @@ -7,5 +7,12 @@ int foo(void) { return 0; } -//CHECK: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"="true"{{.*}} } -//NOPG-NOT: attributes #{{[0-9]+}} = { {{.*}}"fentry-call"{{.*}} } +int __attribute__((no_instrument_function)) no_instrument(void) { + return foo(); +} + +//CHECK: attributes #0 = { {{.*}}"fentry-call"="true"{{.*}} } +//CHECK: attributes #1 = { {{.*}} } +//CHECK-NOT: attributes #1 = { {{.*}}"fentry-call"="true"{{.*}} } +//NOPG-NOT: attributes #0 = { {{.*}}"fentry-call"{{.*}} } +//NOPG-NOT: attributes #1 = { {{.*}}"fentry-call"{{.*}} }