<div dir="ltr">Folks,<br><div class="gmail_quote"><div dir="ltr"><div><br></div><div>I'm trying to profile a code compiled with Clang and I'm getting a segfault on mcount independently of the program I run:</div><div>
<div><br></div><div>Program received signal SIGSEGV, Segmentation fault.</div>
<div>0x00007ffff7b1245b in mcount () from /lib/x86_64-linux-gnu/libc.so.6</div><div>(gdb) bt</div><div>#0  0x00007ffff7b1245b in mcount () from /lib/x86_64-linux-gnu/libc.so.6</div><div>#1  0x00007ffff7dd6588 in ?? () from /lib/x86_64-linux-gnu/libc.so.6</div>

<div>#2  0x0000000000000000 in ?? ()</div></div><div>(gdb) disas<br></div><div><div>Dump of assembler code for function mcount:</div><div>   0x00007ffff7b12430 <+0>:<span style="white-space:pre-wrap">      </span>sub    $0x38,%rsp</div>

<div>   0x00007ffff7b12434 <+4>:<span style="white-space:pre-wrap"> </span>mov    %rax,(%rsp)</div><div>   0x00007ffff7b12438 <+8>:<span style="white-space:pre-wrap">      </span>mov    %rcx,0x8(%rsp)</div>
<div>   0x00007ffff7b1243d <+13>:<span style="white-space:pre-wrap">        </span>mov    %rdx,0x10(%rsp)</div><div>   0x00007ffff7b12442 <+18>:<span style="white-space:pre-wrap"> </span>mov    %rsi,0x18(%rsp)</div>

<div>   0x00007ffff7b12447 <+23>:<span style="white-space:pre-wrap">        </span>mov    %rdi,0x20(%rsp)</div><div>   0x00007ffff7b1244c <+28>:<span style="white-space:pre-wrap"> </span>mov    %r8,0x28(%rsp)</div>
<div>   0x00007ffff7b12451 <+33>:<span style="white-space:pre-wrap">        </span>mov    %r9,0x30(%rsp)</div><div>   0x00007ffff7b12456 <+38>:<span style="white-space:pre-wrap">  </span>mov    0x38(%rsp),%rsi</div>
<div>=> 0x00007ffff7b1245b <+43>:<span style="white-space:pre-wrap">     </span>mov    0x8(%rbp),%rdi</div><div>   0x00007ffff7b1245f <+47>:<span style="white-space:pre-wrap">  </span>callq  0x7ffff7b116a0</div>

<div>   0x00007ffff7b12464 <+52>:<span style="white-space:pre-wrap">        </span>mov    0x30(%rsp),%r9</div><div>   0x00007ffff7b12469 <+57>:<span style="white-space:pre-wrap">  </span>mov    0x28(%rsp),%r8</div>
<div>   0x00007ffff7b1246e <+62>:<span style="white-space:pre-wrap">        </span>mov    0x20(%rsp),%rdi</div><div>   0x00007ffff7b12473 <+67>:<span style="white-space:pre-wrap"> </span>mov    0x18(%rsp),%rsi</div>

<div>   0x00007ffff7b12478 <+72>:<span style="white-space:pre-wrap">        </span>mov    0x10(%rsp),%rdx</div><div>   0x00007ffff7b1247d <+77>:<span style="white-space:pre-wrap"> </span>mov    0x8(%rsp),%rcx</div>
<div>   0x00007ffff7b12482 <+82>:<span style="white-space:pre-wrap">        </span>mov    (%rsp),%rax</div><div>   0x00007ffff7b12486 <+86>:<span style="white-space:pre-wrap">     </span>add    $0x38,%rsp</div><div>
   0x00007ffff7b1248a <+90>:<span style="white-space:pre-wrap">   </span>retq   </div><div>End of assembler dump.</div><div>(gdb) p $rdi</div><div>$1 = 1</div><div>(gdb) p $rsp</div><div>$2 = (void *) 0x7fffffffded0</div>

<div>(gdb) p $rbp</div><div>$3 = (void *) 0x0</div></div><div><br></div><div>This is Ubuntu 12.10, libc6 2.15, gcc 4.7.2, and of course, it works with gcc.</div><div><br></div><div>I'm not sure how to begin debugging it, since mcount was probably compiled with gcc, but it looks like LLVM is generating the wrong call standard.</div>
<div><br></div><div>It only appears in -O1 upwards, but there's not stack trace, and I suspect this is due to how the profiling instrumentation work... Any pointers?</div>
<div><br></div><div>cheers,</div><div>--renato</div></div>
</div><br></div>