linker: reduce size by nearly 20KB

This patch adds a trivial implementation of snprintf() that calls
our internal vsnprintf().

Inspection of the generated machine code showed that the linker
contained a full implementation of stdio's vfprintf. It was pulled
in because the pthread implementation uses snprintf() somewhere.

ProTip: It's possible to see why specific objects files are included
in a final binary by adding the following to your Android.mk, then
looking at the content of /tmp/MAP.TXT:

  LOCAL_LDFLAGS += -Wl,-Map=/tmp/MAP.TXT

Change-Id: I325e71b0cad1d01116a2e00c09e30a80cb716aa3
This commit is contained in:
David 'Digit' Turner 2012-06-19 02:02:32 +02:00
parent ece8f502ed
commit 166b7dbd4a

View File

@ -172,6 +172,21 @@ vsnprintf(char *buff, size_t bufsize, const char *format, va_list args)
return format_buffer(buff, bufsize, format, args);
}
/* The pthread implementation uses snprintf(). If we define it here, we
* avoid pulling the stdio vfprintf() implementation into the linker
* saving about 19KB of machine code.
*/
int
snprintf(char* buff, size_t bufsize, const char* format, ...)
{
va_list args;
int ret;
va_start(args, format);
ret = vsnprintf(buff, bufsize, format, args);
va_end(args);
return ret;
}
#if LINKER_DEBUG
#if !LINKER_DEBUG_TO_LOG