This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

A static binary patch


Here is a patch for glibc 2.2. It can be used to minimize the static
binary size together with the c_stubs addon. You can use

# gcc -static ..... -lc_stubs

It will stub out the gconv stuff. Not everything will work when
-lc_stubs is used. __libc_c_stubs is needed since we have to make
sure libcc_stubs.a is loaded even if nothing is referenced yet.
You can the c_stubs addon at

ftp://ftp.valinux.com/pub/support/hjl/glibc/glibc-c_stubs-2.1.tar.gz

We can add more stuff to c_stubs if necessary.


-- 
H.J. Lu (hjl@gnu.org)
--
Mon Aug 23 17:22:53 1999  H.J. Lu  <hjl@gnu.org>

	* Makeconfig (FILE): Define.

	* Rules (%.out): Run $(FILE) on the binary before running it
	and don't use the dynamic linker if it is not dynamically
	linked.

	* csu/init.c (__libc_c_stubs): New extern.
	(dummy): Reference it.

	* misc/Versions (__libc_c_stubs): Added to GLIBC_2.2.

	* misc/init-misc.c (__libc_c_stubs): New defined.

Index: Makeconfig
===================================================================
RCS file: /work/cvs/gnu/glibc/Makeconfig,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 Makeconfig
--- Makeconfig	1999/08/08 17:01:06	1.1.1.1
+++ Makeconfig	1999/08/23 23:20:28
@@ -493,6 +493,10 @@ ifndef	RANLIB
 RANLIB = ranlib
 endif
 
+ifndef FILE
+FILE := file
+endif
+
 # Extra flags to pass to GCC.
 +gccwarn := -Wall -Wwrite-strings -Winline -Wstrict-prototypes
 
Index: Rules
===================================================================
RCS file: /work/cvs/gnu/glibc/Rules,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 Rules
--- Rules	1999/08/23 16:16:40	1.1.1.2
+++ Rules	1999/08/23 23:26:41
@@ -119,13 +119,33 @@ ifneq "$(strip $(tests) $(test-srcs))" "
 # These are the implicit rules for making test outputs
 # from the test programs and whatever input files are present.
 $(objpfx)%.out: %.args $(objpfx)% %.input
-	$($*-ENV) $(built-program-cmd) `cat $(word 1,$^)` < $(word 3,$^) > $@
+	$(FILE) $(built-program-file) | grep dynamically > /dev/null 2>&1; \
+	if [ $$? = 0 ]; then \
+	  $($*-ENV) $(built-program-cmd) `cat $(word 1,$^)` < $(word 3,$^) > $@; \
+	else \
+	  $($*-ENV) $(built-program-file) `cat $(word 1,$^)` < $(word 3,$^) > $@; \
+	fi
 $(objpfx)%.out: %.args $(objpfx)%
-	$($*-ENV) $(built-program-cmd) `cat $(word 1,$^)` > $@
+	$(FILE) $(built-program-file) | grep dynamically > /dev/null 2>&1; \
+	if [ $$? = 0 ]; then \
+	  $($*-ENV) $(built-program-cmd) `cat $(word 1,$^)` > $@; \
+	else \
+	  $($*-ENV) $(built-program-file) `cat $(word 1,$^)` > $@; \
+	fi
 $(objpfx)%.out: %.input $(objpfx)%
-	$($*-ENV) $(built-program-cmd) < $(word 1,$^) > $@
+	$(FILE) $(built-program-file) | grep dynamically > /dev/null 2>&1; \
+	if [ $$? = 0 ]; then \
+	  $($*-ENV) $(built-program-cmd) < $(word 1,$^) > $@; \
+	else \
+	  $($*-ENV) $(built-program-file) < $(word 1,$^) > $@; \
+	fi
 $(objpfx)%.out: /dev/null $(objpfx)%	# Make it 2nd arg for canned sequence.
-	$($*-ENV) $(built-program-cmd) > $@
+	$(FILE) $(built-program-file) | grep dynamically > /dev/null 2>&1; \
+	if [ $$? = 0 ]; then \
+	  $($*-ENV) $(built-program-cmd) > $@; \
+	else \
+	  $($*-ENV) $(built-program-file) > $@; \
+	fi
 endif	# tests
 
 .PHONY: distclean realclean subdir_distclean subdir_realclean \
Index: csu/init.c
===================================================================
RCS file: /work/cvs/gnu/glibc/csu/init.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 init.c
--- csu/init.c	1999/08/08 17:01:09	1.1.1.1
+++ csu/init.c	1999/08/24 01:18:41
@@ -34,3 +34,6 @@
 const int _IO_stdin_used = _G_IO_IO_FILE_VERSION;
 
 #endif
+
+extern int __libc_c_stubs;
+static int *dummy = &__libc_c_stubs;
Index: misc/Versions
===================================================================
RCS file: /work/cvs/gnu/glibc/misc/Versions,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 Versions
--- misc/Versions	1999/08/08 17:01:57	1.1.1.1
+++ misc/Versions	1999/08/24 01:21:55
@@ -103,6 +103,9 @@ libc {
     tdestroy; truncate64;
   }
   GLIBC_2.2 {
+    # global variables
+    __libc_c_stubs;
+
     # m*
     mkdtemp;
   }
Index: misc/init-misc.c
===================================================================
RCS file: /work/cvs/gnu/glibc/misc/init-misc.c,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 init-misc.c
--- misc/init-misc.c	1999/08/08 17:01:57	1.1.1.1
+++ misc/init-misc.c	1999/08/24 01:17:56
@@ -52,3 +52,5 @@ __init_misc (int argc, char **argv, char
 #ifdef HAVE_GNU_LD
 text_set_element (__libc_subinit, __init_misc);
 #endif
+
+int __libc_c_stubs;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]