From owner-freebsd-hackers Mon Sep 14 15:41:54 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA09290 for freebsd-hackers-outgoing; Mon, 14 Sep 1998 15:41:54 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from mail.camalott.com (mail.camalott.com [208.203.140.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA09281 for ; Mon, 14 Sep 1998 15:41:50 -0700 (PDT) (envelope-from joelh@gnu.org) Received: from detlev.UUCP (tex-30.camalott.com [208.229.74.30]) by mail.camalott.com (8.8.7/8.8.5) with ESMTP id RAA15858; Mon, 14 Sep 1998 17:42:51 -0500 Received: (from joelh@localhost) by detlev.UUCP (8.9.1/8.9.1) id RAA09355; Mon, 14 Sep 1998 17:40:44 -0500 (CDT) (envelope-from joelh) Date: Mon, 14 Sep 1998 17:40:44 -0500 (CDT) Message-Id: <199809142240.RAA09355@detlev.UUCP> To: Terry Lambert CC: graphix@iastate.edu (Kent Vander Velden), tlambert@primenet.com, freebsd-hackers@FreeBSD.ORG In-reply-to: <199809142021.NAA26933@usr05.primenet.com> Subject: Re: Unused functions From: Joel Ray Holveck Reply-to: joelh@gnu.org References: <199809142021.NAA26933@usr05.primenet.com> Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG >> Just so I completely understand, if I truely use only one function in from >> a .o file and no other function is using anything in this .o file, the >> entire .o file is still pulled into the executable? So, there are could be >> a lot of unused, unreachable code in an executable. > Yes, if it's statically linked, and you poorly organize your code. > This is why software engineers make more money than mere programmers. This is also why most libraries tend to define one exported function per object file, or sometimes exported functions that are always used together (foodb_open, foodb_close). >> Nothing can be done to remove the bloat after the executable has >> been linked? > Not quite. But nothing *is* done... What can be done in the compiler and linker alone? If an object file contains both foo() and bar(), and foo calls bar, the linker doesn't know that. Neither does it know about static baz(), which only quux() calls. The user program doesn't call quux, and therefore doesn't call baz, but the linker doesn't know that. I don't see any way to resolve the issue without instrumenting the object file (perhaps by extending stabs?). If that were to be done, then something similar to lorder would do the trick. >> I had always assumed that unused functions and data were tosed out. > No. Only for compilers and linkers that optimize for image size > and execution speed, instead of for compiler benchmarks. > Q: Do you buy a compiler that is very fast, or do you buy the > compiler that makes very fast code? I prefer a compiler that has the choice. This isn't hard, particularly since several optimizations-- including the one under discussion-- are handled by passes over intermediate representations of the code. Given no choice, I tend towards the one that makes fast code. Best, joelh -- Joel Ray Holveck - joelh@gnu.org - http://www.wp.com/piquan Fourth law of programming: Anything that can go wrong wi sendmail: segmentation violation - core dumped To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message