[PATCH] D22666: Frontend: Fix mcount inlining bug

Honggyu Kim via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 22 01:39:38 PDT 2016


honggyu.kim created this revision.
honggyu.kim added reviewers: rjmccall, hans.
honggyu.kim added a subscriber: cfe-commits.

Since some profiling tools, such as gprof, ftrace, and uftrace, use
-pg option to generate a mcount function call at the entry of each
function. Function invocation can be detected by this hook function.

But mcount insertion is done before function inlining phase in clang,
sometime a function that already has a mcount call can be inlined in the
middle of another function. So this patch fixes it by disabling
inline-functions when -pg option is enabled.

Link: https://llvm.org/bugs/show_bug.cgi?id=28660
Signed-off-by: Honggyu Kim <hong.gyu.kim at lge.com>

https://reviews.llvm.org/D22666

Files:
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -442,7 +442,7 @@
     (Opts.OptimizationLevel > 1) ? CodeGenOptions::NormalInlining
                                  : CodeGenOptions::OnlyAlwaysInlining);
   // -fno-inline-functions overrides OptimizationLevel > 1.
-  Opts.NoInline = Args.hasArg(OPT_fno_inline);
+  Opts.NoInline = Args.hasArg(OPT_fno_inline) || Args.hasArg(OPT_pg);
   if (Arg* InlineArg = Args.getLastArg(options::OPT_finline_functions,
                                        options::OPT_finline_hint_functions,
                                        options::OPT_fno_inline_functions)) {
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6102,10 +6102,14 @@
   if (SplitDwarf && Output.getType() == types::TY_Object)
     SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output, SplitDwarfOut);
 
-  if (Arg *A = Args.getLastArg(options::OPT_pg))
+  if (Arg *A = Args.getLastArg(options::OPT_pg)) {
     if (Args.hasArg(options::OPT_fomit_frame_pointer))
       D.Diag(diag::err_drv_argument_not_allowed_with) << "-fomit-frame-pointer"
                                                       << A->getAsString(Args);
+    if (Args.hasArg(options::OPT_finline_functions))
+      D.Diag(diag::err_drv_argument_not_allowed_with) << "-finline-functions"
+                                                      << A->getAsString(Args);
+  }
 
   // Claim some arguments which clang supports automatically.
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22666.65034.patch
Type: text/x-patch
Size: 1673 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160722/1eb61828/attachment.bin>


More information about the cfe-commits mailing list