tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Trivial program size inflation



> Date: Sat, 1 Jul 2023 06:57:40 -0700
> From: Jason Thorpe <thorpej%me.com@localhost>
> 
> Oh look, the entirety of jemalloc seems to be included in the
> binary.  WTF knows why that's happening, but apparently it is, and
> jemalloc pulls in a ton of additional stuff.

Comes in from at least two different things:

1. jemalloc.c defines a constructor which brings in most of jemalloc.

2. csu/common/crt0-common.c calls atexit, which brings in
   libc/stdlib/atexit.c, which calls malloc.

For a statically linked program that doesn't use malloc, these aren't
necessary: we don't need the jemalloc constructor, and the crt exit
handlers calls could be served by a static-only __atexit that atexit
also uses to wire up to dynamic exit handlers.

But someone would have to do the work to make this happen.

Not 100% sure this covers everything -- easy to test kicking out
atexit.c by defining __cxa_finalize, __cxa_atexit, __libc_atexit_init,
and atexit in your .c file; not sure offhand how to kick out the
jemalloc constructor without building a new libc.


Home | Main Index | Thread Index | Old Index