Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

stripping binaries



-----BEGIN PGP SIGNED MESSAGE-----

This patch adds an autoconf macro to test whether symbols in the main
executable are available to dynamically linked modules, replacing
the fixed system check.  It also adds autoconf macros to test whether
executables and, separately, shared objects can be stripped without losing
functionality.  Making use of these tests, any "-s" in $LDFLAGS is treated
as merely a hint, and overridden if stripping would stop things working.
Finally, the default $LDFLAGS is changed back to "-s", as it is now safe.

 -zefram

 *** aczsh.m4	1997/03/23 21:21:20	1.2
 --- aczsh.m4	1997/03/27 14:59:14
 ***************
 *** 130,132 ****
 --- 130,284 ----
   fi
   ])
   ])
 + 
 + AC_DEFUN(zsh_SYS_DYNAMIC_EXECSYMS,
 + [AC_CACHE_CHECK([whether symbols in the executable are available],
 + zsh_cv_sys_dynamic_execsyms,
 + [if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
 +     us=_
 + else
 +     us=
 + fi
 + echo 'extern int fred(); int barney () { return fred() + 27; }' > conftest1.c
 + if $CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&5 2>&5 &&
 + $DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o 1>&5 2>&5; then
 +     save_ldflags=$LDFLAGS
 +     LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS"
 +     AC_TRY_RUN([
 + #ifdef HAVE_DLFCN_H
 + #include <dlfcn.h>
 + #else
 + #include <sys/types.h>
 + #include <nlist.h>
 + #include <link.h>
 + #endif
 + #ifndef RTLD_LAZY
 + #define RTLD_LAZY 1
 + #endif
 + #ifndef RTLD_GLOBAL
 + #define RTLD_GLOBAL 0
 + #endif
 + 
 + main()
 + {
 +     void *handle;
 +     int (*barneysym)();
 +     handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
 +     if(!handle) exit(1);
 +     barneysym = (int (*)()) dlsym(handle, "${us}barney");
 +     if(!barneysym) exit(1);
 +     exit((*barneysym)() != 69);
 + }
 + 
 + int fred () { return 42; }
 + ], [zsh_cv_sys_dynamic_execsyms=yes],
 + [zsh_cv_sys_dynamic_execsyms=no],
 + [zsh_cv_sys_dynamic_execsyms=no]
 + )
 +     LDFLAGS=$save_ldflags
 + else
 +     zsh_cv_sys_dynamic_execsyms=no
 + fi
 + ])
 + ])
 + 
 + AC_DEFUN(zsh_SYS_DYNAMIC_STRIP_EXE,
 + [AC_REQUIRE([zsh_SYS_DYNAMIC_EXECSYMS])
 + AC_CACHE_CHECK([whether executables can be stripped],
 + zsh_cv_sys_dynamic_strip_exe,
 + [if test "$zsh_cv_sys_dynamic_execsyms" != yes; then
 +     zsh_cv_sys_dynamic_strip_exe=yes
 + elif
 +     if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
 + 	us=_
 +     else
 + 	us=
 +     fi
 +     echo 'extern int fred(); int barney() { return fred() + 27; }' > conftest1.c
 +     $CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&5 2>&5 &&
 +     $DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS conftest1.o 1>&5 2>&5; then
 +     save_ldflags=$LDFLAGS
 +     LDFLAGS="$LDFLAGS $EXTRA_LDFLAGS -s"
 +     AC_TRY_RUN([
 + #ifdef HAVE_DLFCN_H
 + #include <dlfcn.h>
 + #else
 + #include <sys/types.h>
 + #include <nlist.h>
 + #include <link.h>
 + #endif
 + #ifndef RTLD_LAZY
 + #define RTLD_LAZY 1
 + #endif
 + #ifndef RTLD_GLOBAL
 + #define RTLD_GLOBAL 0
 + #endif
 + 
 + main()
 + {
 +     void *handle;
 +     int (*barneysym)();
 +     handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
 +     if(!handle) exit(1);
 +     barneysym = (int (*)()) dlsym(handle, "${us}barney");
 +     if(!barneysym) exit(1);
 +     exit((*barneysym)() != 69);
 + }
 + 
 + int fred () { return 42; }
 + ], [zsh_cv_sys_dynamic_strip_exe=yes],
 + [zsh_cv_sys_dynamic_strip_exe=no],
 + [zsh_cv_sys_dynamic_strip_exe=no]
 + )
 +     LDFLAGS=$save_ldflags
 + else
 +     zsh_cv_sys_dynamic_strip_exe=no
 + fi
 + ])
 + ])
 + 
 + AC_DEFUN(zsh_SYS_DYNAMIC_STRIP_LIB,
 + [AC_CACHE_CHECK([whether libraries can be stripped],
 + zsh_cv_sys_dynamic_strip_lib,
 + [if test "$zsh_cv_func_dlsym_needs_underscore" = yes; then
 +     us=_
 + else
 +     us=
 + fi
 + echo 'int fred () { return 42; }' > conftest1.c
 + if $CC -c $CFLAGS $CPPFLAGS $DLCFLAGS conftest1.c 1>&5 2>&5 &&
 + $DLLD -o conftest1.$DL_EXT $LDFLAGS $DLLDFLAGS -s conftest1.o 1>&5 2>&5; then
 +     AC_TRY_RUN([
 + #ifdef HAVE_DLFCN_H
 + #include <dlfcn.h>
 + #else
 + #include <sys/types.h>
 + #include <nlist.h>
 + #include <link.h>
 + #endif
 + #ifndef RTLD_LAZY
 + #define RTLD_LAZY 1
 + #endif
 + #ifndef RTLD_GLOBAL
 + #define RTLD_GLOBAL 0
 + #endif
 + 
 + main()
 + {
 +     void *handle;
 +     int (*fredsym)();
 +     handle = dlopen("./conftest1.$DL_EXT", RTLD_LAZY | RTLD_GLOBAL);
 +     if(!handle) exit(1);
 +     fredsym = (int (*)()) dlsym(handle, "${us}fred");
 +     if(!fredsym) exit(1);
 +     exit((*fredsym)() != 42);
 + }
 + ], [zsh_cv_sys_dynamic_strip_lib=yes],
 + [zsh_cv_sys_dynamic_strip_lib=no],
 + [zsh_cv_sys_dynamic_strip_lib=no]
 + )
 + else
 +     zsh_cv_sys_dynamic_strip_lib=no
 + fi
 + ])
 + ])
 *** configure.in	1997/03/23 21:21:20	1.33
 --- configure.in	1997/03/27 15:21:28
 ***************
 *** 183,190 ****
   dnl CHECK THE COMPILER
   dnl ------------------
   dnl We want these before the checks, so the checks can modify their values.
 ! test -z "$CFLAGS"  && CFLAGS=  auto_cflags=1
 ! test -z "$LDFLAGS" && LDFLAGS= auto_ldflags=1
   
   AC_PROG_CC
   
 --- 183,190 ----
   dnl CHECK THE COMPILER
   dnl ------------------
   dnl We want these before the checks, so the checks can modify their values.
 ! test -z "${CFLAGS+set}"  && CFLAGS=  auto_cflags=1
 ! test -z "${LDFLAGS+set}" && LDFLAGS= auto_ldflags=1
   
   AC_PROG_CC
   
 ***************
 *** 212,217 ****
 --- 212,219 ----
         netbsd*)    LDFLAGS="" ;;
         *)          LDFLAGS=-g ;;
       esac
 +   else
 +     LDFLAGS=-s
     fi
   fi
   
 ***************
 *** 225,232 ****
 --- 227,262 ----
     CFLAGS="-D__sco $CFLAGS"
   fi
   
 + sed=':1
 +      s/ -s / /g
 +      t1
 +      s/^ *//
 +      s/ *$//'
 + 
 + case " $LDFLAGS " in
 +   *" -s "*) strip_exeldflags=true strip_libldflags=true
 +     LDFLAGS=`echo " $LDFLAGS " | sed "$sed"` ;;
 +   *) strip_exeldflags=false strip_libldflags=false ;;
 + esac
 + 
 + case " ${EXELDFLAGS+$EXELDFLAGS }" in
 +   " ") ;;
 +   *" -s "*) strip_exeldflags=true
 +     EXELDFLAGS=`echo " $EXELDFLAGS " | sed "$sed"` ;;
 +   *) strip_exeldflags=false ;;
 + esac
 + 
 + case " ${LIBLDFLAGS+$LIBLDFLAGS }" in
 +   " ") ;;
 +   *" -s "*) strip_libldflags=true
 +     LIBLDFLAGS=`echo " $LIBLDFLAGS " | sed "$sed"` ;;
 +   *) strip_libldflags=false ;;
 + esac
 + 
   AC_SUBST(CFLAGS)dnl
   AC_SUBST(LDFLAGS)dnl
 + AC_SUBST(EXELDFLAGS)dnl
 + AC_SUBST(LIBLDFLAGS)dnl
   
   AC_PROG_CPP                 dnl Figure out how to run C preprocessor.
   AC_PROG_GCC_TRADITIONAL     dnl Do we need -traditional flag for gcc.
 ***************
 *** 890,899 ****
     zsh_SYS_DYNAMIC_CLASH
     zsh_SYS_DYNAMIC_GLOBAL
     RTLD_GLOBAL_OK=$zsh_cv_sys_dynamic_rtld_global
 !   case "$host_os" in
 !     sysv4*|esix*)  L=L LIBS="$LIBS -L. -lzsh";;
 !   esac
   else
     RTLD_GLOBAL_OK=no
   fi
   
 --- 920,940 ----
     zsh_SYS_DYNAMIC_CLASH
     zsh_SYS_DYNAMIC_GLOBAL
     RTLD_GLOBAL_OK=$zsh_cv_sys_dynamic_rtld_global
 !   zsh_SYS_DYNAMIC_EXECSYMS
 !   if test "$zsh_cv_sys_dynamic_execsyms" != yes; then
 !     L=L LIBS="$LIBS -L. -lzsh"
 !   fi
 !   zsh_SYS_DYNAMIC_STRIP_EXE
 !   zsh_SYS_DYNAMIC_STRIP_LIB
 !   if $strip_exeldflags && test "$zsh_cv_sys_dynamic_strip_exe" = yes; then
 !     EXELDFLAGS="$EXELDFLAGS -s"
 !   fi
 !   if $strip_libldflags && test "$zsh_cv_sys_dynamic_strip_lib" = yes; then
 !     LIBLDFLAGS="$LIBLDFLAGS -s"
 !   fi
   else
 +   $strip_exeldflags && EXELDFLAGS="$EXELDFLAGS -s"
 +   $strip_libldflags && LIBLDFLAGS="$LIBLDFLAGS -s"
     RTLD_GLOBAL_OK=no
   fi
   
 ***************
 *** 927,939 ****
   echo "
   zsh configuration
   -----------------
 ! zsh version           : ${VERSION}
 ! host operating system : ${host_os}
 ! source code location  : ${srcdir}
 ! compiler              : ${CC}
 ! compiler flags        : ${CFLAGS}
 ! binary install path   : ${zshbin2}
 ! man page install path : ${zshman}
 ! info install path     : ${zshinfo}"
   echo ""
   
 --- 968,986 ----
   echo "
   zsh configuration
   -----------------
 ! zsh version             : ${VERSION}
 ! host operating system   : ${host_os}
 ! source code location    : ${srcdir}
 ! compiler                : ${CC}
 ! compiler flags          : ${CFLAGS}
 ! executable linker flags : ${LDFLAGS} ${EXELDFLAGS} ${EXTRA_LDFLAGS}"
 ! if test "$dynamic" = yes; then
 !   echo "\
 ! module linker flags     : ${LDFLAGS} ${LIBLDFLAGS} ${DLLDFLAGS}"
 ! fi
 ! echo "\
 ! binary install path     : ${zshbin2}
 ! man page install path   : ${zshman}
 ! info install path       : ${zshinfo}"
   echo ""
   
 *** Src/Makefile.in	1997/03/23 21:21:25	1.38
 --- Src/Makefile.in	1997/03/27 14:33:04
 ***************
 *** 52,57 ****
 --- 52,59 ----
   DLLD      = @DLLD@
   DLCFLAGS  = @DLCFLAGS@
   DLLDFLAGS = @DLLDFLAGS@
 + EXELDFLAGS = @EXELDFLAGS@
 + LIBLDFLAGS = @LIBLDFLAGS@
   EXTRA_LDFLAGS = @EXTRA_LDFLAGS@
   
   INCLUDES = -I.. -I. -I$(srcdir)
 ***************
 *** 59,65 ****
   DNCFLAGS =
   
   COMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(D@L@CFLAGS)
 ! LINK    = $(CC) $(LDFLAGS) $(EXTRA_LDFLAGS) -o $@
   
   INSTALL         = @INSTALL@
   INSTALL_PROGRAM = @INSTALL_PROGRAM@
 --- 61,69 ----
   DNCFLAGS =
   
   COMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(D@L@CFLAGS)
 ! LINK    = $(CC) $(LDFLAGS) $(EXELDFLAGS) $(EXTRA_LDFLAGS) -o $@
 ! 
 ! DLLINK    = $(DLLD) $(LDFLAGS) $(LIBLDFLAGS) $(DLLDFLAGS) -o $@
   
   INSTALL         = @INSTALL@
   INSTALL_PROGRAM = @INSTALL_PROGRAM@
 ***************
 *** 176,182 ****
   
   $(LIBZSH): $(LIBOBJS) $(NSTMP)
   	rm -f $@
 ! 	$(DLLD) $(LDFLAGS) $(DLLDFLAGS) -o $(LIBZSH) $(LIBOBJS) $(NLIST)
   	ln -sf $(LIBZSH) libzsh.so
   
   ansi2knr: ansi2knr.c
 --- 180,186 ----
   
   $(LIBZSH): $(LIBOBJS) $(NSTMP)
   	rm -f $@
 ! 	$(DLLINK) $(LIBOBJS) $(NLIST)
   	ln -sf $(LIBZSH) libzsh.so
   
   ansi2knr: ansi2knr.c
 *** Src/Modules/Makefile.in	1997/03/27 01:57:59	1.20
 --- Src/Modules/Makefile.in	1997/03/27 14:28:34
 ***************
 *** 52,63 ****
   DLLD      = @DLLD@
   DLCFLAGS  = @DLCFLAGS@
   DLLDFLAGS = @DLLDFLAGS@
   
   INCLUDES = -I../.. -I. -I.. -I$(srcdir) -I$(srcdir)/..
   
   COMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(D@L@CFLAGS)
   DLCOMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) -DMODULE $(CFLAGS) $(DLCFLAGS)
 ! DLLINK    = $(DLLD) $(LDFLAGS) $(DLLDFLAGS) -o $@
   
   INSTALL         = @INSTALL@
   INSTALL_PROGRAM = @INSTALL_PROGRAM@
 --- 52,64 ----
   DLLD      = @DLLD@
   DLCFLAGS  = @DLCFLAGS@
   DLLDFLAGS = @DLLDFLAGS@
 + LIBLDFLAGS = @LIBLDFLAGS@
   
   INCLUDES = -I../.. -I. -I.. -I$(srcdir) -I$(srcdir)/..
   
   COMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(D@L@CFLAGS)
   DLCOMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) -DMODULE $(CFLAGS) $(DLCFLAGS)
 ! DLLINK    = $(DLLD) $(LDFLAGS) $(LIBLDFLAGS) $(DLLDFLAGS) -o $@
   
   INSTALL         = @INSTALL@
   INSTALL_PROGRAM = @INSTALL_PROGRAM@
 *** Src/Zle/Makefile.in	1997/03/22 07:01:03	1.25
 --- Src/Zle/Makefile.in	1997/03/27 14:29:08
 ***************
 *** 51,62 ****
   DLLD      = @DLLD@
   DLCFLAGS  = @DLCFLAGS@
   DLLDFLAGS = @DLLDFLAGS@
   
   INCLUDES = -I../.. -I. -I.. -I$(srcdir) -I$(srcdir)/..
   
   COMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(D@L@CFLAGS)
   DLCOMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) -DMODULE $(CFLAGS) $(DLCFLAGS)
 ! DLLINK    = $(DLLD) $(LDFLAGS) $(DLLDFLAGS) -o $@
   
   INSTALL         = @INSTALL@
   INSTALL_PROGRAM = @INSTALL_PROGRAM@
 --- 51,63 ----
   DLLD      = @DLLD@
   DLCFLAGS  = @DLCFLAGS@
   DLLDFLAGS = @DLLDFLAGS@
 + LIBLDFLAGS = @LIBLDFLAGS@
   
   INCLUDES = -I../.. -I. -I.. -I$(srcdir) -I$(srcdir)/..
   
   COMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) $(CFLAGS) $(D@L@CFLAGS)
   DLCOMPILE = $(CC) -c $(INCLUDES) $(CPPFLAGS) $(DEFS) -DMODULE $(CFLAGS) $(DLCFLAGS)
 ! DLLINK    = $(DLLD) $(LDFLAGS) $(LIBLDFLAGS) $(DLLDFLAGS) -o $@
   
   INSTALL         = @INSTALL@
   INSTALL_PROGRAM = @INSTALL_PROGRAM@

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: ascii

iQCVAwUBMzqTPnD/+HJTpU/hAQG7xQQAs5bJ2nlqmaeqHFtD8AFCbW8XGhmcdZzG
1rBWyvuDNJnzRDJ4g6pieILwSZ7SsgWORYHwRz16o1BNT18d3HijIBdSVyAV1w9X
etwVeAQU4RugUkFIEtWXN9RojfZRCJP3HClzNMsn16lEpS8TwxXJej00trAaZrFQ
zd+yqqImNcw=
=Ysaw
-----END PGP SIGNATURE-----



Messages sorted by: Reverse Date, Date, Thread, Author