aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-07 20:46:34 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-07 20:46:34 +0000
commitd62fd84d4b309bc5fa6548288b82f21189d4f53f (patch)
tree323ecf50e92a496908b6749c1e0cc41a0669d8c3
parent7930bcf7368e42b327b2a234f4e1be897fc25b1d (diff)
downloadbusybox-w32-d62fd84d4b309bc5fa6548288b82f21189d4f53f.tar.gz
busybox-w32-d62fd84d4b309bc5fa6548288b82f21189d4f53f.tar.bz2
busybox-w32-d62fd84d4b309bc5fa6548288b82f21189d4f53f.zip
libbusybox: move (possibly compressed) help stuff into libbusybox.
Makes individual binaries much smaller.
-rw-r--r--Config.in13
-rw-r--r--applets/Kbuild6
-rw-r--r--applets/applets.c116
-rw-r--r--include/busybox.h3
-rw-r--r--libbb/Kbuild1
-rwxr-xr-xscripts/trylink39
6 files changed, 25 insertions, 153 deletions
diff --git a/Config.in b/Config.in
index b046812c7..74f8beae9 100644
--- a/Config.in
+++ b/Config.in
@@ -283,14 +283,15 @@ config STATIC
283config BUILD_LIBBUSYBOX 283config BUILD_LIBBUSYBOX
284 bool "Build shared libbusybox" 284 bool "Build shared libbusybox"
285 default n 285 default n
286 depends on !FEATURE_PREFER_APPLETS
286 help 287 help
287 Build a shared library libbusybox.so which contains all 288 Build a shared library libbusybox.so.N.N.N which contains all
288 libraries used inside busybox. 289 busybox code.
289 290
290 This is an experimental feature intended to support the upcoming 291 This feature allows every applet to be built as a tiny
291 "make standalone" mode. Enabling it against the one big busybox 292 separate executable. Enabling it for "one big busybox binary"
292 binary serves no purpose (and increases the size). You should 293 approach serves no purpose and increases code size.
293 almost certainly say "no" to this right now. 294 You should almost certainly say "no" to this.
294 295
295### config FEATURE_FULL_LIBBUSYBOX 296### config FEATURE_FULL_LIBBUSYBOX
296### bool "Feature-complete libbusybox" 297### bool "Feature-complete libbusybox"
diff --git a/applets/Kbuild b/applets/Kbuild
index cf7d29751..289c5def4 100644
--- a/applets/Kbuild
+++ b/applets/Kbuild
@@ -4,13 +4,13 @@
4# 4#
5# Licensed under the GPL v2, see the file LICENSE in this tarball. 5# Licensed under the GPL v2, see the file LICENSE in this tarball.
6 6
7obj-y:= 7obj-y :=
8obj-y += applets.o 8obj-y += applets.o
9 9
10hostprogs-y:= 10hostprogs-y:=
11hostprogs-y += usage 11hostprogs-y += usage
12 12
13always:= $(hostprogs-y) 13always:= $(hostprogs-y)
14 14
15# Generated files need additional love 15# Generated files need additional love
16 16
diff --git a/applets/applets.c b/applets/applets.c
index f91884b13..49ad8599f 100644
--- a/applets/applets.c
+++ b/applets/applets.c
@@ -15,6 +15,7 @@
15#include <assert.h> 15#include <assert.h>
16#include "busybox.h" 16#include "busybox.h"
17 17
18
18/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */ 19/* Apparently uclibc defines __GLIBC__ (compat trick?). Oh well. */
19#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__) 20#if ENABLE_STATIC && defined(__GLIBC__) && !defined(__UCLIBC__)
20#warning Static linking against glibc produces buggy executables 21#warning Static linking against glibc produces buggy executables
@@ -27,32 +28,8 @@
27#endif 28#endif
28 29
29 30
30/* Declare <applet>_main() */
31#define PROTOTYPES
32#include "applets.h"
33#undef PROTOTYPES
34
35#if ENABLE_SHOW_USAGE && !ENABLE_FEATURE_COMPRESS_USAGE
36/* Define usage_messages[] */
37static const char usage_messages[] ALIGN1 = ""
38#define MAKE_USAGE
39#include "usage.h"
40#include "applets.h"
41;
42#undef MAKE_USAGE
43#else
44#define usage_messages 0
45#endif /* SHOW_USAGE */
46
47/* Define struct bb_applet applets[] */
48#include "applets.h"
49/* The -1 arises because of the {0,NULL,0,-1} entry. */
50
51#if ENABLE_FEATURE_SH_STANDALONE
52const unsigned short NUM_APPLETS = ARRAY_SIZE(applets);
53#endif
54const struct bb_applet *current_applet; 31const struct bb_applet *current_applet;
55const char *applet_name ATTRIBUTE_EXTERNALLY_VISIBLE; 32const char *applet_name;
56#if !BB_MMU 33#if !BB_MMU
57bool re_execed; 34bool re_execed;
58#endif 35#endif
@@ -419,82 +396,6 @@ static void check_suid(const struct bb_applet *applet)
419#endif /* FEATURE_SUID */ 396#endif /* FEATURE_SUID */
420 397
421 398
422#if ENABLE_FEATURE_COMPRESS_USAGE
423
424#include "usage_compressed.h"
425#include "unarchive.h"
426
427static const char *unpack_usage_messages(void)
428{
429 char *outbuf = NULL;
430 bunzip_data *bd;
431 int i;
432
433 i = start_bunzip(&bd,
434 /* src_fd: */ -1,
435 /* inbuf: */ packed_usage,
436 /* len: */ sizeof(packed_usage));
437 /* read_bunzip can longjmp to start_bunzip, and ultimately
438 * end up here with i != 0 on read data errors! Not trivial */
439 if (!i) {
440 /* Cannot use xmalloc: will leak bd in NOFORK case! */
441 outbuf = malloc_or_warn(SIZEOF_usage_messages);
442 if (outbuf)
443 read_bunzip(bd, outbuf, SIZEOF_usage_messages);
444 }
445 dealloc_bunzip(bd);
446 return outbuf;
447}
448#define dealloc_usage_messages(s) free(s)
449
450#else
451
452#define unpack_usage_messages() usage_messages
453#define dealloc_usage_messages(s) ((void)(s))
454
455#endif /* FEATURE_COMPRESS_USAGE */
456
457
458void bb_show_usage(void)
459{
460 if (ENABLE_SHOW_USAGE) {
461 const char *format_string;
462 const char *p;
463 const char *usage_string = p = unpack_usage_messages();
464 int i;
465
466 i = current_applet - applets;
467 while (i) {
468 while (*p++) continue;
469 i--;
470 }
471
472 fprintf(stderr, "%s multi-call binary\n", bb_banner);
473 format_string = "\nUsage: %s %s\n\n";
474 if (*p == '\b')
475 format_string = "\nNo help available.\n\n";
476 fprintf(stderr, format_string, applet_name, p);
477 dealloc_usage_messages((char*)usage_string);
478 }
479 xfunc_die();
480}
481
482
483static int applet_name_compare(const void *name, const void *vapplet)
484{
485 const struct bb_applet *applet = vapplet;
486
487 return strcmp(name, applet->name);
488}
489
490const struct bb_applet *find_applet_by_name(const char *name)
491{
492 /* Do a binary search to find the applet entry given the name. */
493 return bsearch(name, applets, ARRAY_SIZE(applets)-1, sizeof(applets[0]),
494 applet_name_compare);
495}
496
497
498#if ENABLE_FEATURE_INSTALLER 399#if ENABLE_FEATURE_INSTALLER
499/* create (sym)links for each applet */ 400/* create (sym)links for each applet */
500static void install_links(const char *busybox, int use_symbolic_links) 401static void install_links(const char *busybox, int use_symbolic_links)
@@ -635,16 +536,9 @@ void run_applet_and_exit(const char *name, char **argv)
635} 536}
636 537
637 538
638#ifdef __GLIBC__
639/* Make it reside in R/W memory: */
640int *const bb_errno __attribute__ ((section (".data")));
641#endif
642
643int main(int argc, char **argv) 539int main(int argc, char **argv)
644{ 540{
645#ifdef __GLIBC__ 541 bbox_prepare_main();
646 (*(int **)&bb_errno) = __errno_location();
647#endif
648 542
649#if !BB_MMU 543#if !BB_MMU
650 /* NOMMU re-exec trick sets high-order bit in first byte of name */ 544 /* NOMMU re-exec trick sets high-order bit in first byte of name */
@@ -660,10 +554,6 @@ int main(int argc, char **argv)
660 554
661 parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */ 555 parse_config_file(); /* ...maybe, if FEATURE_SUID_CONFIG */
662 556
663 /* Set locale for everybody except 'init' */
664 if (ENABLE_LOCALE_SUPPORT && getpid() != 1)
665 setlocale(LC_ALL, "");
666
667 run_applet_and_exit(applet_name, argv); 557 run_applet_and_exit(applet_name, argv);
668 bb_error_msg_and_die("applet not found"); 558 bb_error_msg_and_die("applet not found");
669} 559}
diff --git a/include/busybox.h b/include/busybox.h
index 8b3647f57..3ab90d5c7 100644
--- a/include/busybox.h
+++ b/include/busybox.h
@@ -48,8 +48,9 @@ struct bb_applet {
48#endif 48#endif
49}; 49};
50 50
51/* Defined in applet.c */ 51/* Defined in appletlib.c */
52extern const struct bb_applet applets[]; 52extern const struct bb_applet applets[];
53extern const unsigned short NUM_APPLETS; 53extern const unsigned short NUM_APPLETS;
54void bbox_prepare_main(void);
54 55
55#endif /* _BB_INTERNAL_H_ */ 56#endif /* _BB_INTERNAL_H_ */
diff --git a/libbb/Kbuild b/libbb/Kbuild
index 55b3658b4..c6c33bd6b 100644
--- a/libbb/Kbuild
+++ b/libbb/Kbuild
@@ -6,6 +6,7 @@
6 6
7lib-y:= 7lib-y:=
8 8
9lib-y += appletlib.o
9lib-y += ask_confirmation.o 10lib-y += ask_confirmation.o
10lib-y += bb_askpass.o 11lib-y += bb_askpass.o
11lib-y += bb_basename.o 12lib-y += bb_basename.o
diff --git a/scripts/trylink b/scripts/trylink
index a87d67225..e756461c8 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -128,6 +128,7 @@ if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then
128 exit 1 128 exit 1
129 } 129 }
130 strip -s --remove-section=.note --remove-section=.comment $EXE -o "$sharedlib_dir/libbusybox.so.$BB_VER" 130 strip -s --remove-section=.note --remove-section=.comment $EXE -o "$sharedlib_dir/libbusybox.so.$BB_VER"
131 chmod a+x "$sharedlib_dir/libbusybox.so.$BB_VER"
131 echo "libbusybox: $sharedlib_dir/libbusybox.so.$BB_VER" 132 echo "libbusybox: $sharedlib_dir/libbusybox.so.$BB_VER"
132fi 133fi
133 134
@@ -160,41 +161,15 @@ if test "$CONFIG_FEATURE_INDIVIDUAL" = y; then
160 test x"$cname" = "x[[" && cname=test 161 test x"$cname" = "x[[" && cname=test
161 162
162 echo "\ 163 echo "\
163#include <errno.h> 164void bbox_prepare_main(void);
164#include <unistd.h> 165int $main(int argc, char **argv);
165#include <stdlib.h>
166#include <stdio.h>
167#include \"../include/autoconf.h\"
168#include \"../include/usage.h\"
169
170#ifdef __GLIBC__
171/* Make it reside in R/W memory: */
172int *const bb_errno __attribute__ ((section (\".data\")));
173#endif
174 166
175const char *applet_name = \"$name\"; 167const char *applet_name = \"$name\";
176 168
177void bb_show_usage(void)
178{
179 fprintf(stderr, \"Usage: $name \"
180#ifdef ${cname}_trivial_usage
181 ${cname}_trivial_usage
182#endif
183#ifdef ${cname}_full_usage
184 \"\\n\\n\" ${cname}_full_usage
185#endif
186 \"\\n\\n\");
187 exit(1);
188}
189
190int $main(int argc, char **argv);
191
192int main(int argc, char **argv) 169int main(int argc, char **argv)
193{ 170{
194#ifdef __GLIBC__ 171 bbox_prepare_main();
195 (*(int **)&bb_errno) = __errno_location(); 172 return $main(argc, argv);
196#endif
197 return $main(argc, argv);
198} 173}
199" >"$sharedlib_dir/applet.c" 174" >"$sharedlib_dir/applet.c"
200 175
@@ -215,3 +190,7 @@ int main(int argc, char **argv)
215 190
216 done <applet.lst 191 done <applet.lst
217fi 192fi
193
194# libbusybox.so is needed only for -lbusybox at link time,
195# it is not needed at runtime. Deleting to reduce confusion.
196rm "$sharedlib_dir"/libbusybox.so >/dev/null