From mday@mithril.fjarlq.com  Sat Jun 17 06:18:27 2006
Return-Path: <mday@mithril.fjarlq.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id BB05E16A47A
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 Jun 2006 06:18:27 +0000 (UTC)
	(envelope-from mday@mithril.fjarlq.com)
Received: from mithril.fjarlq.com (ip-64-139-9-163.dsl.sca.megapath.net [64.139.9.163])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6DF8A43D48
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 Jun 2006 06:18:27 +0000 (GMT)
	(envelope-from mday@mithril.fjarlq.com)
Received: by mithril.fjarlq.com (Postfix, from userid 1000)
	id E889DF20036; Fri, 16 Jun 2006 23:18:26 -0700 (PDT)
Message-Id: <20060617061826.E889DF20036@mithril.fjarlq.com>
Date: Fri, 16 Jun 2006 23:18:26 -0700 (PDT)
From: Matt <freebsdbugs@fjarlq.com>
Reply-To: Matt <freebsdbugs@fjarlq.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: biere@jku.at
Subject: ccmalloc: no backtraces on amd64 when compiled with -O
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         99070
>Category:       ports
>Synopsis:       ccmalloc: no backtraces on amd64 when compiled with -O
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jun 17 06:20:14 GMT 2006
>Closed-Date:    Tue Jul 11 18:03:11 GMT 2006
>Last-Modified:  Tue Jul 11 18:03:11 GMT 2006
>Originator:     
>Release:        FreeBSD 6.1-RELEASE
>Organization:
>Environment:
Platform: amd64

% gcc -v
Using built-in specs.
Configured with: FreeBSD/amd64 system compiler
Thread model: posix
gcc version 3.4.4 [FreeBSD] 20050518

>Description:
When compiled with the -O optimization flag on the amd64 platform,
devel/ccmalloc version 0.4.0 does not generate backtraces in its
memory leak reports. The reports are created, but the helpful
backtraces are missing.

On i386 I could not reproduce this problem, ccmalloc on that platform
works fine when compiled with -O.

>How-To-Repeat:
1) Add the -O option to CFLAGS in /etc/make.conf.
   The exact line I had was:

CFLAGS=         -O -pipe

   I've built everything on my system, including hundreds of packages,
   with this setting without any problem until now.

2) Build and install devel/ccmalloc from ports.

3) Build a test program using ccmalloc:

% cat > testmalloc.c
char *addr;
leak() { addr = malloc(4096); }
call() { leak(); }
main() { call(); }
^D
% ccmalloc cc -g testmalloc.c -o testmalloc

4) Run the testmalloc program you built; a report with a valid
   summary will be generated, but the backtrace of the malloc caller
   will be missing:

% testmalloc
file-name=a.out does not contain valid symbols
trying to find executable in current directory ...
(to speed up this search specify `file testmalloc'
 in the startup file `.ccmalloc (but not found)')
.--------------------------------------------------------------------------.
|================ ccmalloc-0.4.0 (C) 1997-2003 Armin Biere ================|
+--------------------------------------------------------------------------+
| executable       = testmalloc                                            |
| startup file     = .ccmalloc (but not found)                             |
| log file         = stderr                                                |
| start time       = Fri Jun 16 23:03:22 2006                              |
| operating system = FreeBSD 6.1-RELEASE amd64 on example.com              |
+--------------------------------------------------------------------------+
| only-count        = 0            keep-deallocated-data = 0               |
| check-interval    = 0            check-free-space      = 0               |
| check-start       = 0            file-info             = 1               |
| chain-length      = 0            additional-line       = 1               |
| check-underwrites = 0            print-addresses       = 0               |
| check-overwrites  = 0            print-on-one-line     = 0               |
| sort-by-wasted    = 1            sort-by-size          = 1               |
| # only-log-chain  = 0            continue              = 0               |
| # dont-log-chain  = 0            statistics            = 0               |
| debug             = 0            library-chains        = 0               |
| load-dynlibs      = 0            align-8-byte          = 0               |
| only-wasting-alloc= 1                                                    |
`--------------------------------------------------------------------------'

.---------------.
|ccmalloc report|
=======================================================
| total # of|   allocated | deallocated |     garbage |
+-----------+-------------+-------------+-------------+
|      bytes|        4096 |           0 |        4096 |
+-----------+-------------+-------------+-------------+
|allocations|           1 |           0 |           1 |
+-----------------------------------------------------+
| number of checks: 1                                 |
| number of counts: 1                                 |
| retrieving function names for addresses ... done.   |
| reading file info from gdb ... done.                |
| sorting by number of not reclaimed bytes ... done.  |
| number of call chains: 0                            |
| number of ignored call chains: 0                    |
| number of reported call chains: 0                   |
| number of internal call chains: 0                   |
| number of library call chains: 1                    |
`------------------------------------------------------

>Fix:
I added this to my /etc/make.conf to override CFLAGS for devel/ccmalloc:

.if ${.CURDIR:M*/devel/ccmalloc}
CFLAGS=         -pipe
.endif

Reinstall devel/ccmalloc, rebuild your test program, and it should
generate a backtrace in the report now:

% testmalloc
file-name=a.out does not contain valid symbols
trying to find executable in current directory ...
(to speed up this search specify `file testmalloc'
 in the startup file `.ccmalloc (but not found)')
.--------------------------------------------------------------------------.
|================ ccmalloc-0.4.0 (C) 1997-2003 Armin Biere ================|
+--------------------------------------------------------------------------+
| executable       = testmalloc                                            |
| startup file     = .ccmalloc (but not found)                             |
| log file         = stderr                                                |
| start time       = Fri Jun 16 23:09:17 2006                              |
| operating system = FreeBSD 6.1-RELEASE amd64 on example.com              |
+--------------------------------------------------------------------------+
| only-count        = 0            keep-deallocated-data = 0               |
| check-interval    = 0            check-free-space      = 0               |
| check-start       = 0            file-info             = 1               |
| chain-length      = 0            additional-line       = 1               |
| check-underwrites = 0            print-addresses       = 0               |
| check-overwrites  = 0            print-on-one-line     = 0               |
| sort-by-wasted    = 1            sort-by-size          = 1               |
| # only-log-chain  = 0            continue              = 0               |
| # dont-log-chain  = 0            statistics            = 0               |
| debug             = 0            library-chains        = 0               |
| load-dynlibs      = 0            align-8-byte          = 0               |
| only-wasting-alloc= 1                                                    |
`--------------------------------------------------------------------------'

.---------------.
|ccmalloc report|
=======================================================
| total # of|   allocated | deallocated |     garbage |
+-----------+-------------+-------------+-------------+
|      bytes|        4096 |           0 |        4096 |
+-----------+-------------+-------------+-------------+
|allocations|           1 |           0 |           1 |
+-----------------------------------------------------+
| number of checks: 1                                 |
| number of counts: 1                                 |
| retrieving function names for addresses ... done.   |
| reading file info from gdb ... done.                |
| sorting by number of not reclaimed bytes ... done.  |
| number of call chains: 1                            |
| number of ignored call chains: 0                    |
| number of reported call chains: 1                   |
| number of internal call chains: 1                   |
| number of library call chains: 0                    |
=======================================================
|
*100.0% = 4096 Bytes of garbage allocated in 1 allocation
|       |
|       |       0x0040162e in <main>
|       |                  at testmalloc.c:4
|       |
|       |       0x0040161e in <call>
|       |                  at testmalloc.c:3
|       |
|       |       0x004015fe in <leak>
|       |                  at testmalloc.c:2
|       |
|       `-----> 0x0040193e in <malloc>
|        
`------------------------------------------------------
>Release-Note:
>Audit-Trail:

From: Matt <freebsdbugs@fjarlq.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: ports/99070: ccmalloc: no backtraces on amd64 when compiled with -O
Date: Sat, 17 Jun 2006 14:02:40 -0700

 I should have clarified above: when I said I couldn't reproduce
 this on i386 with gcc -O, that was using gcc version 2.95.4 on
 FreeBSD 4.10-STABLE. I don't have an i386 system running 6.1-RELEASE
 to test it on the more recent stuff. So in other words, it's possible
 this is due to a bug/issue introduced by gcc 3.x.
State-Changed-From-To: open->closed 
State-Changed-By: arved 
State-Changed-When: Tue Jul 11 18:02:54 UTC 2006 
State-Changed-Why:  
I have committed a workaround, thanks for your report. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=99070 
>Unformatted:
