From owner-freebsd-hackers@FreeBSD.ORG Sat Mar 20 23:23:28 2004 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B1A2416A4CE for ; Sat, 20 Mar 2004 23:23:28 -0800 (PST) Received: from gabby.gsicomp.on.ca (CPE00062566c7bb-CM000039c69a66.cpe.net.cable.rogers.com [67.60.54.142]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0582C43D2D for ; Sat, 20 Mar 2004 23:23:28 -0800 (PST) (envelope-from matt@gsicomp.on.ca) Received: from hermes (hermes.gsicomp.on.ca [192.168.0.18]) by gabby.gsicomp.on.ca (8.12.9p2/8.12.9) with ESMTP id i2L7efpU069593; Sun, 21 Mar 2004 02:40:41 -0500 (EST) (envelope-from matt@gsicomp.on.ca) Message-ID: <002f01c40f14$f4406540$1200a8c0@gsicomp.on.ca> From: "Matt Emmerton" To: , "Garance A Drosihn" References: Date: Sun, 21 Mar 2004 02:20:13 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Subject: Re: Adventures with gcc: code vs object-code size X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 21 Mar 2004 07:23:28 -0000 ----- Original Message ----- From: "Garance A Drosihn" To: Sent: Saturday, March 20, 2004 5:45 PM Subject: Adventures with gcc: code vs object-code size > I have written a fairly major set of changes to the `ps' command, > which is available as: > http://people.freebsd.org/~gad/ps-susv3.diff > > Debate/discussion about the changes themselves actual changes should > be going on in the freebsd-standards mailing list. So for purposes > of this mailing list, please ignore most of that. > > But while doing it, I was somewhat obsessed about making sure that > my changes wouldn't cause a dramatic increase in the size of the > executable for `ps'. Due to that, I tripped over one example of > "code" vs "object-code produced" which makes no sense to me. So, > consider just this section of the update (with some reformatting > so it is easy to see the code): > > char elemcopy[PATH_MAX]; > ...do stuff... > #if !defined(ADD_PS_LISTRESET) > inf->addelem(inf, elemcopy); > #else > /* > * We now have a single element. Add it to the > * list, unless the element is ":". In that case, > * reset the list so previous entries are ignored. > */ > if (strcmp(elemcopy, ":") == 0) > inf->count = 0; > else > inf->addelem(inf, elemcopy); > #endif > > Now, here is what I noticed: > > * XXX - Adding this check increases the total size of `ps' by > * 3940 bytes on i386! That's 12% of the entire program! > * { using gcc (GCC) 3.3.3 [FreeBSD] 20031106 } > * > * When compiling for sparc, adding this option causes NO > * change in the size of the `ps' executable. And on alpha, > * adding this option adds only 8 bytes to the executable. > > So, by adding one call to strcmp() to check for a ":" string, I end > up with /bin/ps (the stripped-object-file) which has grown by 12.6% !! > This is for a program which is almost 2500 lines spread out over > 5 '.c'-files. How is that possible? What am I missing here? > > I am not a compilier guru, so I suspect it would take me hours to > pin this down. I don't want to do that, so I'm wondering if anyone > understands how such a minor code-change can POSSIBLY cause such a > huge change in resulting object file... I also wonder if this same > issue pops up in other programs, too. I don't know why the code bloats so much on i386, but I do question the use of strcmp() for a single-character compare. Something like the following would probably be better (and would avoid your problem): if (elemcopy[0] == ':') inf->count = 0; else inf->addelem(inf, elemcopy); -- Matt Emmerton