tech-userlevel archive

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

Re: Trivial program size inflation



Taylor R Campbell wrote:

> A quicker way to address most of it is to just define your own malloc:
>
> $ cat null.o
> #include <stddef.h>
> void *malloc(size_t n) { return NULL; }
> void *realloc(void *p, size_t n) { return NULL; }
> void *calloc(size_t n, size_t sz) { return NULL; }
> void free(void *p) {}
> int main(void) { return 0; }
> $ cc -g -O2 -static -o null null.c
> $ size null
>    text	   data	    bss	    dec	    hex	filename
>   26724	   3208	   3184	  33116	   815c	null

I'm sorta curious why linking against one of our small malloc
implementations still pulls in jemalloc:

	thoreau 3633> echo 'int main(void) { return 0; }' > null.c

	thoreau 3634> cc -g -O2 -static -o null null.c -lgnumalloc
	thoreau 3635> size null
	   text    data     bss     dec     hex filename
	 582263   28928 2176553 2787744  2a89a0 null
	thoreau 3636> nm null | grep -c je_malloc
	30

	thoreau 3637> cc -g -O2 -static -o null null.c -lbsdmalloc
	thoreau 3638> size null
	   text    data     bss     dec     hex filename
	 582263   28928 2176553 2787744  2a89a0 null

	thoreau 3639> cat >> malloc.c
	#include <stddef.h>
	void *malloc(size_t n) { return NULL; }
	void *realloc(void *p, size_t n) { return NULL; }
	void *calloc(size_t n, size_t sz) { return NULL; }
	void free(void *p) {}
	thoreau 3640> cc -g -O2 -static -o null null.c malloc.c
	thoreau 3641> size null
	   text    data     bss     dec     hex filename
	  33096    3224     3152  39472    9a30 null

Is this something to do with the jemalloc constructor still getting
called somehow?  Using cc -v shows that libbsdmalloc is being linked
against before libc:

	thoreau 3648> cc -v -g -O2 -static -o null null.c -lbsdmalloc
	   ...
	 ld -plugin ... -lbsdmalloc -lgcc -lc -lgcc ...

Cheers,
Simon.


Home | Main Index | Thread Index | Old Index