Subject: toolchain/34497: profiling is broken?
To: None <,,>
From: None <>
List: netbsd-bugs
Date: 09/08/2006 20:15:00
>Number:         34497
>Category:       toolchain
>Synopsis:       programs compiled with -pg dump core
>Confidential:   no
>Severity:       critical
>Priority:       high
>Responsible:    toolchain-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Sep 08 20:15:00 +0000 2006
>Originator:     David A. Holland <>
>Release:        NetBSD 4.99.1 (20060814, & see below)
   Harvard EECS
System: NetBSD tanaqui 4.99.1 NetBSD 4.99.1 (TANAQUI) #5: Mon Aug 14 16:58:44 EDT 2006 dholland@tanaqui:/usr/src/sys/arch/i386/compile/TANAQUI i386
Architecture: i386
Machine: i386

It appears that profiling is broken with gcc4; even trivial programs
compiled with -pg dump core, at least on i386 and probably more

It appears that the problem is that gcc thinks __mcount preserves
caller-save registers, and it doesn't:

0804833c <main>:
 804833c:       8d 4c 24 04             lea    0x4(%esp),%ecx
 8048340:       83 e4 f0                and    $0xfffffff0,%esp
 8048343:       ff 71 fc                pushl  0xfffffffc(%ecx)
 8048346:       55                      push   %ebp
 8048347:       89 e5                   mov    %esp,%ebp
 8048349:       51                      push   %ecx
 804834a:       e8 b9 03 00 00          call   8048708 <__mcount>
 804834f:       8b 01                   mov    (%ecx),%eax         <--------

while __mcount has an ordinary function prologue:

08048708 <__mcount>:
 8048708:       55                      push   %ebp
 8048709:       89 e5                   mov    %esp,%ebp
 804870b:       57                      push   %edi
 804870c:       56                      push   %esi
 804870d:       53                      push   %ebx
 804870e:       83 ec 0c                sub    $0xc,%esp
 8048711:       8b 45 04                mov    0x4(%ebp),%eax

Note that while my system is nearly a month old (20060814) and I don't
have time to rebuild the world right now, I did update my source tree
to today (20060908) and recompile gcc4, and that didn't help.
Meanwhile, neither mcount.c nor i386/profile.h has changed since last
winter. So I believe this is still current.


tanaqui% cat empty.c
int main(int argc, char *argv[]) { return argc; }
tanaqui% gcc -pg empty.c -o empty
tanaqui% ./empty 
Segmentation fault
Exit 139


No idea, but I imagine there's a setting somewhere in the gcc configs.