Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 8949959

Browse files
enh-googleGerrit Code Review
authored andcommitted
Merge "printf: reduce stack usage in the common case." into main
2 parents b7c2f61 + d4c6118 commit 8949959

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

libc/Android.bp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,12 @@ cc_library_static {
624624
"upstream-openbsd/lib/libc/string/wcslcpy.c",
625625
"upstream-openbsd/lib/libc/string/wcswidth.c",
626626

627-
// This file is originally from OpenBSD, and benefits from
628-
// being compiled with openbsd-compat.h.
629-
// TODO: clean this up instead.
627+
// These files are originally from OpenBSD,
628+
// and benefit from being compiled with openbsd-compat.h.
629+
// TODO: clean them up instead.
630630
"bionic/fts.c",
631+
"stdio/vfprintf.cpp",
632+
"stdio/vfwprintf.cpp",
631633
],
632634

633635
// Each architecture has optimized versions of some routines,
@@ -686,9 +688,11 @@ cc_library_static {
686688

687689
local_include_dirs: [
688690
"private",
689-
"upstream-openbsd/android/include",
690691
"stdio",
691-
"upstream-openbsd/lib/libc/include",
692+
"upstream-openbsd/android/include/",
693+
"upstream-openbsd/lib/libc/gdtoa/",
694+
"upstream-openbsd/lib/libc/include/",
695+
"upstream-openbsd/lib/libc/stdio/",
692696
],
693697

694698
name: "libc_openbsd",
@@ -698,8 +702,6 @@ cc_library_static {
698702
name: "libc_openbsd_large_stack",
699703
defaults: ["libc_defaults"],
700704
srcs: [
701-
"stdio/vfprintf.cpp",
702-
"stdio/vfwprintf.cpp",
703705
"upstream-openbsd/lib/libc/string/memmem.c",
704706
"upstream-openbsd/lib/libc/string/strstr.c",
705707
],
@@ -710,11 +712,7 @@ cc_library_static {
710712
],
711713

712714
local_include_dirs: [
713-
"private",
714715
"upstream-openbsd/android/include/",
715-
"upstream-openbsd/lib/libc/gdtoa/",
716-
"upstream-openbsd/lib/libc/include/",
717-
"upstream-openbsd/lib/libc/stdio/",
718716
],
719717
}
720718

libc/stdio/printf_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ union arg {
8585
// Helper function for `fprintf to unbuffered unix file': creates a
8686
// temporary buffer. We only work on write-only files; this avoids
8787
// worries about ungetc buffers and so forth.
88+
//
89+
// We prevent inlining because this massively increases the printf()
90+
// family's stack usage to support a rare case.
91+
__attribute__((__noinline__))
8892
static int __sbprintf(FILE* fp, const CHAR_TYPE* fmt, va_list ap) {
8993
FILE fake;
9094
struct __sfileext fakeext;

0 commit comments

Comments
 (0)