summaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorDenys Vlasenko2016-04-21 16:26:30 +0200
committerDenys Vlasenko2016-04-21 17:39:11 +0200
commite6a2f4cc5a47d3022bdf5ca2cacbaa5a8c5baf7a (patch)
tree0962142ac9830312cd3df52994db41e8ac47c73c /libbb
parent5598bdf0d3d46a865a4d23785e2d09e6db9be420 (diff)
downloadbusybox-e6a2f4cc5a47d3022bdf5ca2cacbaa5a8c5baf7a.zip
busybox-e6a2f4cc5a47d3022bdf5ca2cacbaa5a8c5baf7a.tar.gz
libbb: make bb_common_bufsiz1 1 kbyte, add capability to use bss tail for it
The config item is FEATURE_USE_BSS_TAIL. When it is off (default): function old new delta read_config 210 228 +18 doCommands 2279 2294 +15 ipneigh_list_or_flush 763 772 +9 ipaddr_list_or_flush 1256 1261 +5 display_process_list 1301 1306 +5 conspy_main 1378 1383 +5 do_lzo_compress 352 355 +3 do_lzo_decompress 565 567 +2 push 46 44 -2 inetd_main 2136 2134 -2 uevent_main 421 418 -3 addLines 97 92 -5 bb_common_bufsiz1 8193 1024 -7169 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 8/5 up/down: 62/-7181) Total: -7119 bytes text data bss dec hex filename 829850 4086 9080 843016 cdd08 busybox_old 829901 4086 1904 835891 cc133 busybox_unstripped FEATURE_USE_BSS_TAIL=y: read_config 210 228 +18 doCommands 2279 2294 +15 ipneigh_list_or_flush 763 772 +9 ipaddr_list_or_flush 1256 1261 +5 display_process_list 1301 1306 +5 conspy_main 1378 1383 +5 do_lzo_compress 352 355 +3 do_lzo_decompress 565 567 +2 inetd_main 2136 2134 -2 bb_common_bufsiz1 8193 - -8193 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 8/1 up/down: 62/-8195) Total: -8133 bytes text data bss dec hex filename 829850 4086 9080 843016 cdd08 busybox_old 829911 4086 880 834877 cbd3d busybox_unstripped FIXME: setup_common_bufsiz() calls are missing. Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r--libbb/common_bufsiz.c74
-rw-r--r--libbb/messages.c5
2 files changed, 74 insertions, 5 deletions
diff --git a/libbb/common_bufsiz.c b/libbb/common_bufsiz.c
new file mode 100644
index 0000000..c16c361
--- /dev/null
+++ b/libbb/common_bufsiz.c
@@ -0,0 +1,74 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 2016 Denys Vlasenko
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ */
+//config:config FEATURE_USE_BSS_TAIL
+//config: bool "Use the end of BSS page"
+//config: default n
+//config: help
+//config: Attempt to reclaim a small unused part of BSS.
+//config:
+//config: Executables have the following parts:
+//config: = read-only executable code and constants, also known as "text"
+//config: = read-write data
+//config: = non-initialized (zeroed on demand) data, also known as "bss"
+//config:
+//config: At link time, "text" is padded to a full page. At runtime, all "text"
+//config: pages are mapped RO and executable.
+//config: "Data" starts on the next page boundary, but is not padded
+//config: to a full page at the end. "Bss" starts wherever "data" ends.
+//config: At runtime, "data" pages are mapped RW and they are file-backed
+//config: (this includes a small portion of "bss" which may live in the last
+//config: partial page of "data").
+//config: Pages which are fully in "bss" are mapped to anonymous memory.
+//config:
+//config: "Bss" end is usually not page-aligned. There is an unused space
+//config: in the last page. Linker marks its start with the "_end" symbol.
+//config:
+//config: This option will attempt to use that space for bb_common_bufsiz1[]
+//config: array. If it fits after _end, it will be used, and COMMON_BUFSIZE
+//config: will be enlarged from its guaranteed minimum size of 1 kbyte.
+//config: This may require recompilation a second time, since value of _end
+//config: is known only after final link.
+//config:
+//config: If you are getting a build error like this:
+//config: appletlib.c:(.text.main+0xd): undefined reference to '_end'
+//config: disable this option.
+
+//kbuild:lib-y += common_bufsiz.o
+
+#include "libbb.h"
+#include "common_bufsiz.h"
+
+#if !ENABLE_FEATURE_USE_BSS_TAIL
+
+/* We use it for "global" data via *(struct global*)bb_common_bufsiz1.
+ * Since gcc insists on aligning struct global's members, it would be a pity
+ * (and an alignment fault on some CPUs) to mess it up. */
+char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
+
+#else
+
+# ifndef setup_common_bufsiz
+/*
+ * It is not a "((void)0)" macro. It means we have to provide this function.
+ */
+char* bb_common_bufsiz1;
+char* setup_common_bufsiz(void)
+{
+ if (!bb_common_bufsiz1)
+ bb_common_bufsiz1 = xzalloc(COMMON_BUFSIZE);
+ return bb_common_bufsiz1;
+}
+# else
+# ifndef bb_common_bufsiz1
+ /* bb_common_bufsiz1[] is not aliased to _end[] */
+char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
+# endif
+# endif
+
+#endif
diff --git a/libbb/messages.c b/libbb/messages.c
index 23e440b..cb0836d 100644
--- a/libbb/messages.c
+++ b/libbb/messages.c
@@ -59,8 +59,3 @@ const char bb_path_wtmp_file[] ALIGN1 =
# error unknown path to wtmp file
# endif
#endif
-
-/* We use it for "global" data via *(struct global*)&bb_common_bufsiz1.
- * Since gcc insists on aligning struct global's members, it would be a pity
- * (and an alignment fault on some CPUs) to mess it up. */
-char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));