public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Melvin Blades <melvin.blades@gmail.com>
To: Andrew Haley <aph@redhat.com>
Cc: Ian Lance Taylor <iant@google.com>,
	"gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Re: removing unused functions during final link
Date: Wed, 03 Sep 2014 15:09:00 -0000	[thread overview]
Message-ID: <CAG=1SRspbFhponeoY1dajoBzvkNJmKPmQuroiggdJJx=gP7avw@mail.gmail.com> (raw)
In-Reply-To: <5406EBB5.7040903@redhat.com>

For a simple example I created 3 files.
     root.c  -- has main() which calls one function in show.c
     show.c - has two functions, one is called by main, one is not
called. ( both use puts to print a message.)
     show2.c -- has two functions. Neither are called

--------Makefile--------

OBJS := root.o show.o show2.o
SOURCE := root.c show.c show2.c

all: $(SOURCE)
        ${CC} -mips32 -fdata-sections -ffunction-sections -c $(SOURCE)
        ${CC} $(OBJS)  -Wl,--gc-sections -o root.exe
-------End --------

The resulting executable contains the texts strings and function names
from both functions in show.c and neither function of show2.c  My
usage of -fdata-section -ffunction-section and -gc-sections prevents
the  functions in show2.c from being linked in , but not the unused
functions in show.c

$home/dev1/>file root.exe
root.exe: ELF 32-bit LSB executable, MIPS, MIPS32 version 1 (SYSV),
dynamically linked (uses shared libs), not stripped

~

On Wed, Sep 3, 2014 at 3:21 AM, Andrew Haley <aph@redhat.com> wrote:
> On 09/03/2014 04:20 AM, Melvin Blades wrote:
>> Using gcc instead of ld, I was able to get it to strip unused
>>  functions if all the functions in a file are not called.
>>  But I could not get it to strip  unused functions if they  are in the
>>  same source file as used functions .
>>
>>  Is there a way to get it strip ALL the unused functions?
>
> That should have worked.  Please tell us the exact command you used.
>
> Andrew.
>
>

  reply	other threads:[~2014-09-03 15:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-27 21:02 Melvin Blades
2014-08-27 21:22 ` Ian Lance Taylor
2014-09-03  3:20   ` Melvin Blades
2014-09-03 10:21     ` Andrew Haley
2014-09-03 15:09       ` Melvin Blades [this message]
2014-09-03 15:13         ` Andrew Haley
2014-09-05 15:24           ` Melvin Blades

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='CAG=1SRspbFhponeoY1dajoBzvkNJmKPmQuroiggdJJx=gP7avw@mail.gmail.com' \
    --to=melvin.blades@gmail.com \
    --cc=aph@redhat.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=iant@google.com \
    /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).