Skip to content

Commit

Permalink
Do not generate calls to fentry with __attribute__((no_instrument_fun…
Browse files Browse the repository at this point in the history
…ction))

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

llvm-svn: 326639
  • Loading branch information
m-gupta committed Mar 2, 2018
1 parent a4619d9 commit 886b450
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 6 additions & 4 deletions clang/lib/CodeGen/CodeGenFunction.cpp
Expand Up @@ -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<NoInstrumentFunctionAttr>()) {
// Calls to fentry/mcount should not be generated if function has
// the no_instrument_function attribute.
if (!CurFuncDecl || !CurFuncDecl->hasAttr<NoInstrumentFunctionAttr>()) {
if (CGM.getCodeGenOpts().CallFEntry)
Fn->addFnAttr("fentry-call", "true");
else {
Fn->addFnAttr("instrument-function-entry-inlined",
getTarget().getMCountName());
}
Expand Down
11 changes: 9 additions & 2 deletions clang/test/CodeGen/fentry.c
Expand Up @@ -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"{{.*}} }

0 comments on commit 886b450

Please sign in to comment.