[llvm-bugs] [Bug 28660] New: mcount inlining bug when -pg and -O2 enabled

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jul 21 23:11:03 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=28660

            Bug ID: 28660
           Summary: mcount inlining bug when -pg and -O2 enabled
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hong.gyu.kim at lge.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

See the simple example below.

$ cat mcount-test.c
int bar()
{
  return 0;
}

int foo()
{
  return bar();
}

int main()
{
  return foo();
}

If the example is compiled with -pg and -O2 options. It generates the code as
below:

$ clang -pg -O2 -S mcount-test.c
$ cat mcount-test.s
(shows assembly code only ...)
bar:
        pushq   %rbp
        movq    %rsp, %rbp
        callq   mcount
        xorl    %eax, %eax
        popq    %rbp
        retq

foo:
        pushq   %rbp
        movq    %rsp, %rbp
        callq   mcount
        callq   mcount       @ (1) calling bar is inlined with mcount
        xorl    %eax, %eax
        popq    %rbp
        retq

main:
        pushq   %rbp
        movq    %rsp, %rbp
        callq   mcount
        callq   mcount       @ (2) calling foo is inlined with mcount
        callq   mcount       @ (3) calling bar is inlined with mcount
        xorl    %eax, %eax
        popq    %rbp
        retq

As I put some comments, the problem is that function inlining is done with
mcount call.
bar() has a single mcount at the entry of function, but foo() has two mcount
calls. It's because bar is inlined with its mcount call into foo's body.  And
also main() has three mcount calls because the foo() is inlined its own mcount
and its body that has two mcount calls inside.

This is tested on the current trunk.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160722/5f3f7c61/attachment.html>


More information about the llvm-bugs mailing list