public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Michael Eager <eager@eagercon.com>
To: Steve Kreyer <steve.kreyer@web.de>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Symbols which were not used, still in binary
Date: Wed, 28 Jun 2006 20:17:00 -0000	[thread overview]
Message-ID: <44A2E3C9.90201@eagercon.com> (raw)
In-Reply-To: <44A2DF65.8010704@web.de>

Steve Kreyer wrote:
> Hi,
> 
> I have a question about an optimization issue.
> 
> I have compiled the follwing code with the command ''gcc file.c''
> 
> ---------------------------------------------------------------
> int add(int a, int b){
>    return a + b;
> }
> 
> int main(){
> }
> --------------------------------------------------------------
> 
> My question is:
> Why does the symbol "add" appear in the outcoming binary file?
> nm gives me:
> --------------------------------------------------------------
> redwing@euklid:~ $ nm a.out | grep add
> 08048324 T add
> --------------------------------------------------------------
> 
> Neither is it used in this piece of code, nor is it compiled into an 
> object file,
> so in my opinion it should be optimized away by gcc.
> So perhaps anybody can tell me whats wrong with my thought...

add is a global symbol.  GCC has no way of knowing whether or not
this object file will be linked with another file which contains
a reference to the function.  Arguably, the linker should know
that add is not referenced and could remove it, but linkers are not
usually able to slice and dice object files.

[If you declare add to be static, then GCC should be able
to eliminate it.  But it doesn't.]

Programs often contain functions which are designed
to be called by someone using a debugger but are otherwise
not referenced.

-- 
Michael Eager	 eager@eagercon.com
1960 Park Blvd., Palo Alto, CA 94306  650-325-8077

  parent reply	other threads:[~2006-06-28 20:17 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-06-28 19:58 Steve Kreyer
2006-06-28 20:17 ` Brian Dessent
2006-06-28 21:21   ` Steve Kreyer
2006-06-28 20:17 ` Michael Eager [this message]
2006-06-28 21:20   ` Brian Dessent
2006-06-29  5:16     ` Ingo Krabbe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44A2E3C9.90201@eagercon.com \
    --to=eager@eagercon.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=steve.kreyer@web.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).