This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Statically linked binary way way too big


On Wed, Oct 16, 2002 at 12:24:12AM -0700, Kaz Kylheku wrote:
> > Say that again? It's ok for this program to occupy 400k?
> 
> Based on the relative frequency of static versus dynamic linking,
> I'd say that it's irrelevant how big or small a static binary is.
> 
> Dynamic linking amortizes the library size over hundreds and hundreds
> of programs in your system. I don't think anyone cares about minimizing
> the dependencies so that a trivial main() { } won't pull in anything.
> 
> Minimizing static footprints was important on systems with poor or
> nonexistent dynamic linking systems.

Yeah, and if you for some reason really need to cut down the size of some
important binary, then you can either use dietlibc or such, or use various
tricks to prevent linker from adding .o files from libc.a you're
sure you don't need. So e.g. you can add:

#ifndef __powerpc__
int __libc_start_main (int (*main) (void), int argc, char **argv,
                       void (*init) (void), void (*fini) (void),
                       void (*rtld_fini) (void), void * stack_end)
#else
struct startup_info
{
  void *sda_base;
  int (*main) (int, char **, char **, void *);
  int (*init) (int, char **, char **, void *);
  void (*fini) (void);
};

int __libc_start_main (int argc, char **ubp_av,
                       char **ubp_ev,
                       void *auxvec, void (*rtld_fini) (void),
                       struct startup_info *stinfo,
                       char **stack_on_entry)
#endif
{
  _exit (main());
  return 0;
}

to your binary, you can use _exit instead of full-blown exit,
avoid using functions which suck whole locale and iconv stuff
(like *printf/*scanf family) or use simple replacements for
what you exactly need, etc.

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]