Slim down static binaries by avoiding stdio.

It's okay for a program to choose to drag in stdio, but it's unfortunate
if even the minimal "int main() { return 42; }" drags in stdio...

This brings the minimal static binary on ARM down from 78KiB to 46KiB.

Given that we don't have a separate -lpthread it's not obvious to me that
we can shave this down any further. I'm not sure whether this is a worthwhile
change for that reason. (And the fact that dynamic binaries, the usual case,
are unaffected either way.)

Change-Id: I02f91dcff37d14354314a30b72fed2563f431c88
This commit is contained in:
Elliott Hughes
2014-07-10 12:34:23 -07:00
parent f0f8cd1ff3
commit 91570ce987
9 changed files with 19 additions and 16 deletions

View File

@@ -268,7 +268,7 @@ extern "C" int fill_posix_memalign(void** memptr, size_t alignment, size_t size)
}
extern "C" void* fill_pvalloc(size_t bytes) {
size_t pagesize = sysconf(_SC_PAGESIZE);
size_t pagesize = getpagesize();
size_t size = BIONIC_ALIGN(bytes, pagesize);
if (size < bytes) { // Overflow
return NULL;
@@ -277,7 +277,7 @@ extern "C" void* fill_pvalloc(size_t bytes) {
}
extern "C" void* fill_valloc(size_t size) {
return fill_memalign(sysconf(_SC_PAGESIZE), size);
return fill_memalign(getpagesize(), size);
}
// =============================================================================
@@ -477,7 +477,7 @@ extern "C" int leak_posix_memalign(void** memptr, size_t alignment, size_t size)
}
extern "C" void* leak_pvalloc(size_t bytes) {
size_t pagesize = sysconf(_SC_PAGESIZE);
size_t pagesize = getpagesize();
size_t size = BIONIC_ALIGN(bytes, pagesize);
if (size < bytes) { // Overflow
return NULL;
@@ -486,5 +486,5 @@ extern "C" void* leak_pvalloc(size_t bytes) {
}
extern "C" void* leak_valloc(size_t size) {
return leak_memalign(sysconf(_SC_PAGESIZE), size);
return leak_memalign(getpagesize(), size);
}