[clang] 8b9cb12 - [Driver] -pg -mfentry should respect target specific decisions for -mframe-pointer=all

Nick Desaulniers via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 18 15:39:59 PST 2020


Author: Nick Desaulniers
Date: 2020-02-18T15:33:46-08:00
New Revision: 8b9cb120812449dbe67d2252ebf619c4c9cac816

URL: https://github.com/llvm/llvm-project/commit/8b9cb120812449dbe67d2252ebf619c4c9cac816
DIFF: https://github.com/llvm/llvm-project/commit/8b9cb120812449dbe67d2252ebf619c4c9cac816.diff

LOG: [Driver] -pg -mfentry should respect target specific decisions for -mframe-pointer=all

Summary:
$ clang -O2 -pg -mfentry foo.c

was adding frame pointers to all functions. This was exposed via
compiling the Linux kernel for x86_64 with CONFIG_FUNCTION_TRACER
enabled.

-pg was unconditionally setting the equivalent of -fno-omit-frame-pointer,
regardless of the presence of -mfentry or optimization level.  After this
patch, frame pointers will only be omitted at -O0 or if
-fno-omit-frame-pointer is explicitly set for -pg -mfentry.

See also:
https://gcc.gnu.org/git/?p=gcc.git;a=commitdiff;h=3c5273a96ba8dbf98c40bc6d9d0a1587b4cfedb2;hp=c9d75a48c4ea63ab27ccdb40f993236289b243f2#patch2
(modification to ix86_frame_pointer_required())

Fixes: pr/44934

Reviewers: void, manojgupta, dberris, MaskRay, hfinkel

Reviewed By: MaskRay

Subscribers: cfe-commits, llozano, niravd, srhines

Tags: #clang

Differential Revision: https://reviews.llvm.org/D74698

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/Clang.cpp
    clang/test/Driver/mfentry.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index d1197556aeef..1d9e741f4cf8 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -526,7 +526,7 @@ static bool mustUseNonLeafFramePointerForTarget(const llvm::Triple &Triple) {
 
 static bool useFramePointerForTargetByDefault(const ArgList &Args,
                                               const llvm::Triple &Triple) {
-  if (Args.hasArg(options::OPT_pg))
+  if (Args.hasArg(options::OPT_pg) && !Args.hasArg(options::OPT_mfentry))
     return true;
 
   switch (Triple.getArch()) {
@@ -6150,7 +6150,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   }
 
   if (Arg *A = Args.getLastArg(options::OPT_pg))
-    if (FPKeepKind == CodeGenOptions::FramePointerKind::None)
+    if (FPKeepKind == CodeGenOptions::FramePointerKind::None &&
+        !Args.hasArg(options::OPT_mfentry))
       D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
                                                       << A->getAsString(Args);
 

diff  --git a/clang/test/Driver/mfentry.c b/clang/test/Driver/mfentry.c
index ee402ea1b73d..34ef9d9ca11b 100644
--- a/clang/test/Driver/mfentry.c
+++ b/clang/test/Driver/mfentry.c
@@ -1,9 +1,19 @@
 // RUN: %clang -target s390x -c -### %s -mfentry 2>&1 | FileCheck %s
 // RUN: %clang -target i386 -c -### %s -mfentry 2>&1 | FileCheck %s
 // RUN: %clang -target x86_64 -c -### %s -mfentry 2>&1 | FileCheck %s
+// RUN: %clang -target x86_64-linux-gnu -pg -mfentry -O0 -### -E %s 2>&1 | FileCheck -check-prefix=FP %s
+// RUN: %clang -target x86_64-linux-gnu -pg -mfentry -O2 -fno-omit-frame-pointer -### -E %s 2>&1 | FileCheck -check-prefix=FP %s
+// RUN: %clang -target x86_64-linux-gnu -pg -mfentry -O2 -### -E %s 2>&1 | FileCheck -check-prefix=NOFP %s
+// RUN: %clang -target x86_64 -pg -mfentry -O0 -### -E %s 2>&1 | FileCheck -check-prefix=FP %s
+// RUN: %clang -target x86_64 -pg -mfentry -O2 -fno-omit-frame-pointer -### -E %s 2>&1 | FileCheck -check-prefix=FP %s
+// RUN: %clang -target x86_64 -pg -mfentry -O2 -### -E %s 2>&1 | FileCheck -check-prefix=FP %s
 
 // CHECK: "-mfentry"
 
 // RUN: %clang -target powerpc64le -c -### %s -mfentry 2>&1 | FileCheck --check-prefix=ERR %s
 
 // ERR: error: unsupported option '-mfentry' for target 'powerpc64le'
+
+// FP: "-mframe-pointer=all"
+// NOFP: "-mframe-pointer=none"
+void foo(void) {}


        


More information about the cfe-commits mailing list