printf: reduce stack usage in the common case.
clang was inlining the function that creates a temporary on-stack buffer
for the unbuffered case.
Change-Id: I261f7ef09ed2939c66354aa245deb4e2e48d5dc6
diff --git a/libc/Android.bp b/libc/Android.bp
index 2141e67..30e201a 100644
--- a/libc/Android.bp
+++ b/libc/Android.bp
@@ -624,10 +624,12 @@
"upstream-openbsd/lib/libc/string/wcslcpy.c",
"upstream-openbsd/lib/libc/string/wcswidth.c",
- // This file is originally from OpenBSD, and benefits from
- // being compiled with openbsd-compat.h.
- // TODO: clean this up instead.
+ // These files are originally from OpenBSD,
+ // and benefit from being compiled with openbsd-compat.h.
+ // TODO: clean them up instead.
"bionic/fts.c",
+ "stdio/vfprintf.cpp",
+ "stdio/vfwprintf.cpp",
],
// Each architecture has optimized versions of some routines,
@@ -686,9 +688,11 @@
local_include_dirs: [
"private",
- "upstream-openbsd/android/include",
"stdio",
- "upstream-openbsd/lib/libc/include",
+ "upstream-openbsd/android/include/",
+ "upstream-openbsd/lib/libc/gdtoa/",
+ "upstream-openbsd/lib/libc/include/",
+ "upstream-openbsd/lib/libc/stdio/",
],
name: "libc_openbsd",
@@ -698,8 +702,6 @@
name: "libc_openbsd_large_stack",
defaults: ["libc_defaults"],
srcs: [
- "stdio/vfprintf.cpp",
- "stdio/vfwprintf.cpp",
"upstream-openbsd/lib/libc/string/memmem.c",
"upstream-openbsd/lib/libc/string/strstr.c",
],
@@ -710,11 +712,7 @@
],
local_include_dirs: [
- "private",
"upstream-openbsd/android/include/",
- "upstream-openbsd/lib/libc/gdtoa/",
- "upstream-openbsd/lib/libc/include/",
- "upstream-openbsd/lib/libc/stdio/",
],
}
diff --git a/libc/stdio/printf_common.h b/libc/stdio/printf_common.h
index 702f8d3..653bba2 100644
--- a/libc/stdio/printf_common.h
+++ b/libc/stdio/printf_common.h
@@ -85,6 +85,10 @@
// Helper function for `fprintf to unbuffered unix file': creates a
// temporary buffer. We only work on write-only files; this avoids
// worries about ungetc buffers and so forth.
+//
+// We prevent inlining because this massively increases the printf()
+// family's stack usage to support a rare case.
+__attribute__((__noinline__))
static int __sbprintf(FILE* fp, const CHAR_TYPE* fmt, va_list ap) {
FILE fake;
struct __sfileext fakeext;