aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <dvlasenk@redhat.com>2010-09-01 12:01:17 +0200
committerDenys Vlasenko <dvlasenk@redhat.com>2010-09-01 12:01:17 +0200
commit0004e994934374b5695e004bbcb7b1fd67a170f2 (patch)
tree6cbf7c0042fbd265b34f28111726b0f04c536818
parent9dc04124d5a3f0c9be249287817a964691e187b0 (diff)
downloadbusybox-0004e994934374b5695e004bbcb7b1fd67a170f2.tar.gz
better shared strings trick
text data bss dec hex filename 861980 441 7540 869961 d4649 busybox_old 861914 441 7540 869895 d4607 busybox_unstripped Signed-off-by: Denys Vlasenko <dvlasenk@redhat.com>
-rw-r--r--include/libbb.h35
-rw-r--r--libbb/Kbuild.src1
-rw-r--r--libbb/inet_common.c6
-rw-r--r--libbb/messages.c9
-rw-r--r--libbb/mtab_file.c15
-rw-r--r--networking/ifconfig.c2
-rw-r--r--networking/libiproute/utils.c4
-rw-r--r--networking/route.c4
8 files changed, 33 insertions, 43 deletions
diff --git a/include/libbb.h b/include/libbb.h
index 6fb0438f5..4b69c855f 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1573,12 +1573,22 @@ void bb_progress_update(bb_progress_t *p, const char *curfile,
off_t totalsize) FAST_FUNC;
extern const char *applet_name;
+
+/* Some older linkers don't perform string merging, we used to have common strings
+ * as global arrays to do it by hand. But:
+ * (1) newer linkers do it themselves,
+ * (2) however, they DONT merge string constants with global arrays,
+ * even if the value is the same (!). Thus global arrays actually
+ * increased size a bit: for example, "/etc/passwd" string from libc
+ * wasn't merged with bb_path_passwd_file[] array!
+ * Therefore now we use #defines.
+ */
/* "BusyBox vN.N.N (timestamp or extra_version)" */
extern const char bb_banner[];
extern const char bb_msg_memory_exhausted[];
extern const char bb_msg_invalid_date[];
-extern const char bb_msg_read_error[];
-extern const char bb_msg_write_error[];
+#define bb_msg_read_error "read error"
+#define bb_msg_write_error "write error"
extern const char bb_msg_unknown[];
extern const char bb_msg_can_not_create_raw_socket[];
extern const char bb_msg_perm_denied_are_you_root[];
@@ -1588,18 +1598,23 @@ extern const char bb_msg_invalid_arg[];
extern const char bb_msg_standard_input[];
extern const char bb_msg_standard_output[];
-extern const char bb_str_default[];
/* NB: (bb_hexdigits_upcase[i] | 0x20) -> lowercase hex digit */
extern const char bb_hexdigits_upcase[];
-extern const char bb_path_mtab_file[];
-extern const char bb_path_passwd_file[];
-extern const char bb_path_shadow_file[];
-extern const char bb_path_gshadow_file[];
-extern const char bb_path_group_file[];
-extern const char bb_path_motd_file[];
extern const char bb_path_wtmp_file[];
-extern const char bb_dev_null[];
+
+/* Busybox mount uses either /proc/mounts or /etc/mtab to
+ * get the list of currently mounted filesystems */
+#define bb_path_mtab_file IF_FEATURE_MTAB_SUPPORT("/etc/mtab")IF_NOT_FEATURE_MTAB_SUPPORT("/proc/mounts")
+
+#define bb_path_passwd_file "/etc/passwd"
+#define bb_path_shadow_file "/etc/shadow"
+#define bb_path_gshadow_file "/etc/gshadow"
+#define bb_path_group_file "/etc/group"
+
+#define bb_path_motd_file "/etc/motd"
+
+#define bb_dev_null "/dev/null"
extern const char bb_busybox_exec_path[];
/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
* but I want to save a few bytes here */
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
index 5db4d8a62..b02fcfe74 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -64,7 +64,6 @@ lib-y += md5.o
#lib-y += md5prime.o
lib-y += messages.o
lib-y += mode_string.o
-lib-y += mtab_file.o
lib-y += obscure.o
lib-y += parse_mode.o
lib-y += parse_config.o
diff --git a/libbb/inet_common.c b/libbb/inet_common.c
index b47259089..e031ddf9b 100644
--- a/libbb/inet_common.c
+++ b/libbb/inet_common.c
@@ -23,7 +23,7 @@ int FAST_FUNC INET_resolve(const char *name, struct sockaddr_in *s_in, int hostf
s_in->sin_port = 0;
/* Default is special, meaning 0.0.0.0. */
- if (!strcmp(name, bb_str_default)) {
+ if (strcmp(name, "default") == 0) {
s_in->sin_addr.s_addr = INADDR_ANY;
return 1;
}
@@ -109,7 +109,7 @@ char* FAST_FUNC INET_rresolve(struct sockaddr_in *s_in, int numeric, uint32_t ne
if (ad == INADDR_ANY) {
if ((numeric & 0x0FFF) == 0) {
if (numeric & 0x8000)
- return xstrdup(bb_str_default);
+ return xstrdup("default");
return xstrdup("*");
}
}
@@ -205,7 +205,7 @@ char* FAST_FUNC INET6_rresolve(struct sockaddr_in6 *sin6, int numeric)
}
if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
if (numeric & 0x8000)
- return xstrdup(bb_str_default);
+ return xstrdup("default");
return xstrdup("*");
}
diff --git a/libbb/messages.c b/libbb/messages.c
index 44b39942f..66e466ffa 100644
--- a/libbb/messages.c
+++ b/libbb/messages.c
@@ -24,8 +24,6 @@ const char bb_banner[] ALIGN1 = BANNER;
const char bb_msg_memory_exhausted[] ALIGN1 = "memory exhausted";
const char bb_msg_invalid_date[] ALIGN1 = "invalid date '%s'";
-const char bb_msg_write_error[] ALIGN1 = "write error";
-const char bb_msg_read_error[] ALIGN1 = "read error";
const char bb_msg_unknown[] ALIGN1 = "(unknown)";
const char bb_msg_can_not_create_raw_socket[] ALIGN1 = "can't create raw socket";
const char bb_msg_perm_denied_are_you_root[] ALIGN1 = "permission denied (are you root?)";
@@ -35,15 +33,8 @@ const char bb_msg_invalid_arg[] ALIGN1 = "invalid argument '%s' to '%s'";
const char bb_msg_standard_input[] ALIGN1 = "standard input";
const char bb_msg_standard_output[] ALIGN1 = "standard output";
-const char bb_str_default[] ALIGN1 = "default";
const char bb_hexdigits_upcase[] ALIGN1 = "0123456789ABCDEF";
-const char bb_path_passwd_file[] ALIGN1 = "/etc/passwd";
-const char bb_path_shadow_file[] ALIGN1 = "/etc/shadow";
-const char bb_path_group_file[] ALIGN1 = "/etc/group";
-const char bb_path_gshadow_file[] ALIGN1 = "/etc/gshadow";
-const char bb_path_motd_file[] ALIGN1 = "/etc/motd";
-const char bb_dev_null[] ALIGN1 = "/dev/null";
const char bb_busybox_exec_path[] ALIGN1 = CONFIG_BUSYBOX_EXEC_PATH;
const char bb_default_login_shell[] ALIGN1 = LIBBB_DEFAULT_LOGIN_SHELL;
/* util-linux manpage says /sbin:/bin:/usr/sbin:/usr/bin,
diff --git a/libbb/mtab_file.c b/libbb/mtab_file.c
deleted file mode 100644
index add990ded..000000000
--- a/libbb/mtab_file.c
+++ /dev/null
@@ -1,15 +0,0 @@
-/* vi: set sw=4 ts=4: */
-/*
- * Utility routines.
- *
- * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
- *
- * Licensed under GPLv2 or later, see file LICENSE in this source tree.
- */
-
-#include "libbb.h"
-
-/* Busybox mount uses either /proc/mounts or /etc/mtab to
- * get the list of currently mounted filesystems */
-const char bb_path_mtab_file[] ALIGN1 =
-IF_FEATURE_MTAB_SUPPORT("/etc/mtab")IF_NOT_FEATURE_MTAB_SUPPORT("/proc/mounts");
diff --git a/networking/ifconfig.c b/networking/ifconfig.c
index 853910f67..da2635ce0 100644
--- a/networking/ifconfig.c
+++ b/networking/ifconfig.c
@@ -370,7 +370,7 @@ int ifconfig_main(int argc UNUSED_PARAM, char **argv)
#endif
sai.sin_family = AF_INET;
sai.sin_port = 0;
- if (!strcmp(host, bb_str_default)) {
+ if (strcmp(host, "default") == 0) {
/* Default is special, meaning 0.0.0.0. */
sai.sin_addr.s_addr = INADDR_ANY;
}
diff --git a/networking/libiproute/utils.c b/networking/libiproute/utils.c
index 5125617c7..2b646f0ea 100644
--- a/networking/libiproute/utils.c
+++ b/networking/libiproute/utils.c
@@ -64,7 +64,7 @@ int get_addr_1(inet_prefix *addr, char *name, int family)
{
memset(addr, 0, sizeof(*addr));
- if (strcmp(name, bb_str_default) == 0
+ if (strcmp(name, "default") == 0
|| strcmp(name, "all") == 0
|| strcmp(name, "any") == 0
) {
@@ -103,7 +103,7 @@ static int get_prefix_1(inet_prefix *dst, char *arg, int family)
memset(dst, 0, sizeof(*dst));
- if (strcmp(arg, bb_str_default) == 0
+ if (strcmp(arg, "default") == 0
|| strcmp(arg, "all") == 0
|| strcmp(arg, "any") == 0
) {
diff --git a/networking/route.c b/networking/route.c
index c72e9457f..98567aaee 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -185,7 +185,7 @@ static NOINLINE void INET_setroute(int action, char **args)
#endif
} else {
/* Default netmask. */
- netmask = bb_str_default;
+ netmask = "default";
}
/* Prefer hostname lookup is -host flag (xflag==1) was given. */
isnet = INET_resolve(target, (struct sockaddr_in *) &rt.rt_dst,
@@ -346,7 +346,7 @@ static NOINLINE void INET6_setroute(int action, char **args)
/* We know args isn't NULL from the check in route_main. */
const char *target = *args++;
- if (strcmp(target, bb_str_default) == 0) {
+ if (strcmp(target, "default") == 0) {
prefix_len = 0;
memset(&sa6, 0, sizeof(sa6));
} else {