public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Giant executables.. what am I doing wrong?
@ 2002-10-14 19:00 Dockeen
  0 siblings, 0 replies; 15+ messages in thread
From: Dockeen @ 2002-10-14 19:00 UTC (permalink / raw)
  To: gcc-help

Have you tried to do a "strip" on the exe?

Wayne

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
@ 2002-10-15  5:31 Ruppert
  0 siblings, 0 replies; 15+ messages in thread
From: Ruppert @ 2002-10-15  5:31 UTC (permalink / raw)
  To: gcc-help


...


> If you run 'nm' on your pre-stripped executable you will see all the
> compiled in functions from the C library and any other libraries. When you
> do a static compile it doesn't just include only the needed function(s), but
> the entire C library .a file. That's why I recommended going with a smaller
> or more base-functionality C library such as newlib.
> 
...

No. The linker will extract the modules from the archive file (.a)
on a "per object" base. Thus if you use strcpy in your program the
module which contains the definition of strcpy (usually strcpy.o)
gets copied from the archive file to your executable. A archive file
is, in fact, only a collection of individual objects pasted together
and augmented by a common table of symbols.

I would also recommend using 'nm'. This provides detailed insight into
what constitutes your executable.


-- D.Ruppert

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-15  5:12         ` Joshua Nye
  2002-10-15  5:19           ` Joshua Nye
@ 2002-10-15  5:20           ` Michiel Buddingh'
  1 sibling, 0 replies; 15+ messages in thread
From: Michiel Buddingh' @ 2002-10-15  5:20 UTC (permalink / raw)
  To: gcc-help

On Tue, Oct 15, 2002 at 08:12:12AM -0400, Joshua Nye wrote:
> If you run 'nm' on your pre-stripped executable you will
> see all the compiled in functions from the C library and
> any other libraries. When you do a static compile it 
> doesn't just include only the needed function(s), but the 
> entire C library .a file.

I see. But that's a bit ridiculous, don't you agree? Are
you sure there isn't a way to link only the functions my
program needs, rather than all the functions in the library?

-- 
		-- Michiel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-15  5:12         ` Joshua Nye
@ 2002-10-15  5:19           ` Joshua Nye
  2002-10-15  5:20           ` Michiel Buddingh'
  1 sibling, 0 replies; 15+ messages in thread
From: Joshua Nye @ 2002-10-15  5:19 UTC (permalink / raw)
  To: Michiel Buddingh', gcc-help

> If you run 'nm' on your pre-stripped executable you will see all the
> compiled in functions from the C library and any other libraries. When you
> do a static compile it doesn't just include only the needed function(s),
but
> the entire C library .a file. That's why I recommended going with a
smaller
      ^^^^^^^^^^^^^^^^^^^^^^^^


Whoops. That's not entirely correct. Only all the other functions in the C
object file that the needed function happened to be in.

--josh


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-15  2:38         ` Claudio Bley
@ 2002-10-15  5:15           ` Michiel Buddingh'
  0 siblings, 0 replies; 15+ messages in thread
From: Michiel Buddingh' @ 2002-10-15  5:15 UTC (permalink / raw)
  To: gcc-help

On Tue, Oct 15, 2002 at 11:38:13AM +0200, Claudio Bley wrote:
> Of course, write(2) is a system call, but nonetheless you need an
> entry point somewhere to call that function from your program. That's
> why gcc links in the C library which defines write as a weak symbol
> (at least on my machine).

Then again, 332 kB seems a lot of overhead for adding something like an
entry point. I'm starting to get the idea that this problem is related to
my gcc installation. Compiling the same program on a FreeBSD system using
gcc 2.95 leaves me with an executable of 15 kB. Still rather hefty, but a
lot better.

-- 
		-- Michiel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-14 18:50       ` Michiel Buddingh'
  2002-10-15  2:38         ` Claudio Bley
@ 2002-10-15  5:12         ` Joshua Nye
  2002-10-15  5:19           ` Joshua Nye
  2002-10-15  5:20           ` Michiel Buddingh'
  1 sibling, 2 replies; 15+ messages in thread
From: Joshua Nye @ 2002-10-15  5:12 UTC (permalink / raw)
  To: Michiel Buddingh', gcc-help

If you run 'nm' on your pre-stripped executable you will see all the
compiled in functions from the C library and any other libraries. When you
do a static compile it doesn't just include only the needed function(s), but
the entire C library .a file. That's why I recommended going with a smaller
or more base-functionality C library such as newlib.

--josh

----- Original Message -----
From: "Michiel Buddingh'" <ajuin+mail@stack.nl>
To: <gcc-help@gcc.gnu.org>
Sent: Monday, October 14, 2002 9:49 PM
Subject: Re: Giant executables.. what am I doing wrong?


> On Mon, Oct 14, 2002 at 08:34:55PM -0400, Joshua Nye wrote:
> > Sounds like you might need a smaller C library then. Check out
> > newlib or some other library and see if that fits your problem.
> > I'm not that familiar with shrinking the C library. =)
>
> Although newlib does look interesting, I doubt the problem lies
> with the C library. Unless I'm mistaken, system calls should have
> little to do with the C library, as the program calls the kernel
> directly.
> This supports my suspicion that gcc is linking in a lot of stuff
> I could do without.
> --
> -- Michiel
>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-15  3:53 ` Steve Dondley
  2002-10-15  4:15   ` Claudio Bley
@ 2002-10-15  5:09   ` Michiel Buddingh'
  1 sibling, 0 replies; 15+ messages in thread
From: Michiel Buddingh' @ 2002-10-15  5:09 UTC (permalink / raw)
  To: gcc-help

On Tue, Oct 15, 2002 at 06:58:12AM -0400, Steve Dondley wrote:
> > I'm currently trying to write a program for a linux system with limited
> > memory, and as such I'd like gcc to generate small, statically linked
> > executables.
> 
> As someone new to C, I'm a little confused by the above.
> According to GNU C tutorial I'm reading, using static 
> libraries INCREASES the amount of memory used.

And for a normal system, that is correct. On a normal desktop or server
system, many processes will run at the same time. If a number of those
processes make use of the printf() function at one point in time, it makes
sense to share the function between those processes.
  However, the system I'm building will probably run 3 or 4 processes on
average, each of which will use only a small subset of the c library. As
I'm limited in memory, I simply can't afford the (otherwise perfectly
acceptable) overhead shared libraries impose.

-- 
		-- Michiel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: Giant executables.. what am I doing wrong?
  2002-10-15  3:53 ` Steve Dondley
@ 2002-10-15  4:15   ` Claudio Bley
  2002-10-15  5:09   ` Michiel Buddingh'
  1 sibling, 0 replies; 15+ messages in thread
From: Claudio Bley @ 2002-10-15  4:15 UTC (permalink / raw)
  To: Steve Dondley; +Cc: Michiel Buddingh', gcc-help

>>>>> "Steve" == Steve Dondley <stevedondley@attbi.com> writes:

    >> with the --static option, then strip it with "--strip-all" I
    >> get a program worth 332 kB(!).

    Steve> This confuses me as well.  I can't find any documentation
    Steve> about the --strip-all option in the GCC manual.  (Maybe
    Steve> because I'm new to Linux/gcc?  I did 'info gcc' and then
    Steve> did a search for '--strip' and 'strip' but could not find
    Steve> any reference to this option.)  I also did a google search
    Steve> but that turned up nothing.  How/where can I find out what
    Steve> this does?

strip is a program provided by binutils. 'man 1 strip':

STRIP(1)

   strip - Discard symbols from object files.

SYNOPSIS
       strip [-F bfdname |--target=bfdname ]
             [-I bfdname |--input-target=bfdname ]
             [-O bfdname |--output-target=bfdname ]
             [-s|--strip-all] {...} objfile...
              ^^^^^^^^^^^^^^^

-- 
Claudio Bley                                 ASCII ribbon campaign (")
Debian GNU/Linux advocate                     - against HTML email  X 
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \

^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: Giant executables.. what am I doing wrong?
  2002-10-14 16:49 Michiel Buddingh'
  2002-10-14 17:08 ` Joshua Nye
@ 2002-10-15  3:53 ` Steve Dondley
  2002-10-15  4:15   ` Claudio Bley
  2002-10-15  5:09   ` Michiel Buddingh'
  1 sibling, 2 replies; 15+ messages in thread
From: Steve Dondley @ 2002-10-15  3:53 UTC (permalink / raw)
  To: Michiel Buddingh', gcc-help

> I'm currently trying to write a program for a linux system with limited
> memory, and as such I'd like gcc to generate small, statically linked
> executables.

As someone new to C, I'm a little confused by the above.  According to GNU C
tutorial I'm reading, using static libraries INCREASES the amount of memory
used.  A direct quote: "An executable created with a shared library can
therefore be far smaller than one created with a static library."  Of
course, once the shared libraries are loaded into memory, the entire program
will take up just as much memory as a statically compiled executable (I
assume).  My understanding is that the real memory savings come when a
second program is started that uses some of the same libraries as the first
program and now they can share the code.  So instead of the same code
occupying two locations in memory, it only occupies one location.  This
saves memory.

I'm not saying you are wrong for wanting to use a static library, I just
don't understand why and I'm trying to learn.

> with the --static option, then strip it with "--strip-all" I get a
> program worth 332 kB(!).

This confuses me as well.  I can't find any documentation about
the --strip-all option in the GCC manual.  (Maybe because I'm new to
Linux/gcc?  I did 'info gcc' and then did a search for '--strip' and 'strip'
but could not find any reference to this option.)  I also did a google
search but that turned up nothing.  How/where can I find out what this does?

Thanks.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-14 18:50       ` Michiel Buddingh'
@ 2002-10-15  2:38         ` Claudio Bley
  2002-10-15  5:15           ` Michiel Buddingh'
  2002-10-15  5:12         ` Joshua Nye
  1 sibling, 1 reply; 15+ messages in thread
From: Claudio Bley @ 2002-10-15  2:38 UTC (permalink / raw)
  To: Michiel Buddingh'; +Cc: gcc-help

>>>>> "Michiel" == Michiel Buddingh' <ajuin+mail@stack.nl> writes:

    Michiel> On Mon, Oct 14, 2002 at 08:34:55PM -0400, Joshua Nye
    Michiel> wrote:
    >> Sounds like you might need a smaller C library then. Check out
    >> newlib or some other library and see if that fits your problem.
    >> I'm not that familiar with shrinking the C library. =)

    Michiel> Although newlib does look interesting, I doubt the
    Michiel> problem lies with the C library. Unless I'm mistaken,
    Michiel> system calls should have little to do with the C library,
    Michiel> as the program calls the kernel directly.  This supports
    Michiel> my suspicion that gcc is linking in a lot of stuff I
    Michiel> could do without.  -- -- Michiel

Of course, write(2) is a system call, but nonetheless you need an
entry point somewhere to call that function from your program. That's
why gcc links in the C library which defines write as a weak symbol
(at least on my machine).

-- 
Claudio Bley                                 ASCII ribbon campaign (")
Debian GNU/Linux advocate                     - against HTML email  X 
http://www.cs.uni-magdeburg.de/~bley/                     & vCards / \

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-14 17:35     ` Joshua Nye
@ 2002-10-14 18:50       ` Michiel Buddingh'
  2002-10-15  2:38         ` Claudio Bley
  2002-10-15  5:12         ` Joshua Nye
  0 siblings, 2 replies; 15+ messages in thread
From: Michiel Buddingh' @ 2002-10-14 18:50 UTC (permalink / raw)
  To: gcc-help

On Mon, Oct 14, 2002 at 08:34:55PM -0400, Joshua Nye wrote:
> Sounds like you might need a smaller C library then. Check out
> newlib or some other library and see if that fits your problem.
> I'm not that familiar with shrinking the C library. =)

Although newlib does look interesting, I doubt the problem lies
with the C library. Unless I'm mistaken, system calls should have
little to do with the C library, as the program calls the kernel
directly.
This supports my suspicion that gcc is linking in a lot of stuff
I could do without.
-- 
		-- Michiel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-14 17:21   ` Michiel Buddingh'
@ 2002-10-14 17:35     ` Joshua Nye
  2002-10-14 18:50       ` Michiel Buddingh'
  0 siblings, 1 reply; 15+ messages in thread
From: Joshua Nye @ 2002-10-14 17:35 UTC (permalink / raw)
  To: Michiel Buddingh', gcc-help

Sounds like you might need a smaller C library then. Check out newlib or
some other library and see if that fits your problem. I'm not that familiar
with shrinking the C library. =)

http://sources.redhat.com/newlib/

--josh

----- Original Message -----
From: "Michiel Buddingh'" <ajuin+mail@stack.nl>
To: <gcc-help@gcc.gnu.org>
Sent: Monday, October 14, 2002 8:21 PM
Subject: Re: Giant executables.. what am I doing wrong?


> On Mon, Oct 14, 2002 at 08:08:06PM -0400, Joshua Nye wrote:
> > Are you sure you want to create a static executable?
>
> Yes. :)
>
> > If you are trying to
> > save memory, shared executables are probably better.
>
> True. But the system I'm programming for is going to be severely
> limited in memory. Limited to 4 MB of RAM, to be exact. It is not
> going to have virtual memory, and disk space will be less than 1 MB.
>   Furthermore, I expect it's perfectly feasible to implement the
> program I'm writing using system calls only. Given that, it doesn't
> make sense to build it as a shared executable.
>
> --
> -- Michiel
>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-14 17:08 ` Joshua Nye
@ 2002-10-14 17:21   ` Michiel Buddingh'
  2002-10-14 17:35     ` Joshua Nye
  0 siblings, 1 reply; 15+ messages in thread
From: Michiel Buddingh' @ 2002-10-14 17:21 UTC (permalink / raw)
  To: gcc-help

On Mon, Oct 14, 2002 at 08:08:06PM -0400, Joshua Nye wrote:
> Are you sure you want to create a static executable?

Yes. :)

> If you are trying to
> save memory, shared executables are probably better.

True. But the system I'm programming for is going to be severely 
limited in memory. Limited to 4 MB of RAM, to be exact. It is not
going to have virtual memory, and disk space will be less than 1 MB.
  Furthermore, I expect it's perfectly feasible to implement the 
program I'm writing using system calls only. Given that, it doesn't
make sense to build it as a shared executable.

-- 
		-- Michiel

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: Giant executables.. what am I doing wrong?
  2002-10-14 16:49 Michiel Buddingh'
@ 2002-10-14 17:08 ` Joshua Nye
  2002-10-14 17:21   ` Michiel Buddingh'
  2002-10-15  3:53 ` Steve Dondley
  1 sibling, 1 reply; 15+ messages in thread
From: Joshua Nye @ 2002-10-14 17:08 UTC (permalink / raw)
  To: Michiel Buddingh', gcc-help

Are you sure you want to create a static executable? If you are trying to
save memory, shared executables are probably better. With shared executables
the C library will get loaded into memory once and can be used by multiple
programs at the same time. Static programs will eat up more memory by
loading effectively multiple copies of the C library, one for each program
running.

--josh

----- Original Message -----
From: "Michiel Buddingh'" <ajuin+mail@stack.nl>
To: <gcc-help@gcc.gnu.org>
Sent: Monday, October 14, 2002 7:49 PM
Subject: Giant executables.. what am I doing wrong?


> I'm currently trying to write a program for a linux system with limited
> memory, and as such I'd like gcc to generate small, statically linked
> executables.
>
> However, if I compile even a simple program like:
>
> int main() { write(2,"Hello world.\n", 13); return 0; }
>
> with the --static option, then strip it with "--strip-all" I get a
> program worth 332 kB(!).
>
> Needless to say, this is not exactly what I want.
>
> I have tried both gcc 2.95 and gcc 3.2, but the results differ only by
> a few bytes.
>
> Am I missing something really obvious here?
> --
> -- Michiel
>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Giant executables.. what am I doing wrong?
@ 2002-10-14 16:49 Michiel Buddingh'
  2002-10-14 17:08 ` Joshua Nye
  2002-10-15  3:53 ` Steve Dondley
  0 siblings, 2 replies; 15+ messages in thread
From: Michiel Buddingh' @ 2002-10-14 16:49 UTC (permalink / raw)
  To: gcc-help

I'm currently trying to write a program for a linux system with limited
memory, and as such I'd like gcc to generate small, statically linked 
executables.

However, if I compile even a simple program like:

int main() { write(2,"Hello world.\n", 13); return 0; }

with the --static option, then strip it with "--strip-all" I get a 
program worth 332 kB(!).

Needless to say, this is not exactly what I want.

I have tried both gcc 2.95 and gcc 3.2, but the results differ only by
a few bytes.

Am I missing something really obvious here?
-- 
		-- Michiel

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2002-10-15 12:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-14 19:00 Giant executables.. what am I doing wrong? Dockeen
  -- strict thread matches above, loose matches on Subject: below --
2002-10-15  5:31 Ruppert
2002-10-14 16:49 Michiel Buddingh'
2002-10-14 17:08 ` Joshua Nye
2002-10-14 17:21   ` Michiel Buddingh'
2002-10-14 17:35     ` Joshua Nye
2002-10-14 18:50       ` Michiel Buddingh'
2002-10-15  2:38         ` Claudio Bley
2002-10-15  5:15           ` Michiel Buddingh'
2002-10-15  5:12         ` Joshua Nye
2002-10-15  5:19           ` Joshua Nye
2002-10-15  5:20           ` Michiel Buddingh'
2002-10-15  3:53 ` Steve Dondley
2002-10-15  4:15   ` Claudio Bley
2002-10-15  5:09   ` Michiel Buddingh'

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).