From 9a9e8653757f54e6649aff4fa30af732a16d6b42 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 27 Oct 2014 14:39:07 -0600 Subject: [PATCH] Add support for installing a shared zlib --- INSTALL | 12 ++++---- configure | 29 +++++++++++++------ configure.ac | 28 +++++++++++++------ lib/zlib/Makefile.in | 66 +++++++++++++++++++++++++++++++++++++++++--- lib/zlib/zconf.h.in | 16 ++++++++++- 5 files changed, 123 insertions(+), 28 deletions(-) diff --git a/INSTALL b/INSTALL index b0a658d48..e19b08e1f 100644 --- a/INSTALL +++ b/INSTALL @@ -206,11 +206,13 @@ Compilation options: Enable the use of the zlib compress library when storing I/O log files. If specified, location is the base directory containing the zlib include and lib directories. The special - values "system" and "builtin" can be used to indicate that - the system version of zlib should be used or that the version - of zlib shipped with sudo should be used instead. - If this option is not specified, configure will use the - system zlib if it is present. + values "system", "builtin", "shared" and "static" can be + used to indicate that the system version of zlib should be + used or that the version of zlib shipped with sudo should + be used instead. If "static" is specified, sudo will + statically link the builtin zlib and not install it. If + this option is not specified, configure will use the system + zlib if it is present, falling back on the sudo version. --with-incpath=DIR Adds the specified directory (or directories) to CPPFLAGS diff --git a/configure b/configure index 32c44475c..132ba0424 100755 --- a/configure +++ b/configure @@ -784,6 +784,7 @@ LT_STATIC LT_LDEXPORTS LT_LDDEP LT_LDFLAGS +ZLIB_LDFLAGS LIBUTIL_LDFLAGS SUDOERS_LDFLAGS LDFLAGS @@ -2977,6 +2978,7 @@ $as_echo "$as_me: Configuring Sudo version $PACKAGE_VERSION" >&6;} + # @@ -19912,7 +19914,7 @@ fi ZLIB="-lz" ;; - builtin) + static|shared|builtin) # handled below ;; *) @@ -19946,17 +19948,26 @@ fi ZLIB="${ZLIB} -lz" ;; esac -if test X"$enable_zlib" = X"builtin"; then - $as_echo "#define HAVE_ZLIB_H 1" >>confdefs.h +case "$enable_zlib" in + builtin|static|dynamic) + $as_echo "#define HAVE_ZLIB_H 1" >>confdefs.h - CPPFLAGS='-I$(top_builddir)/lib/zlib -I$(top_srcdir)/lib/zlib '"${CPPFLAGS}" - ZLIB="${ZLIB}"' $(top_builddir)/lib/zlib/libz.la' - ZLIB_SRC=lib/zlib - ac_config_headers="$ac_config_headers lib/zlib/zconf.h" + CPPFLAGS='-I$(top_builddir)/lib/zlib -I$(top_srcdir)/lib/zlib '"${CPPFLAGS}" + ZLIB="${ZLIB}"' $(top_builddir)/lib/zlib/libsudo_z.la' + ZLIB_SRC=lib/zlib + ac_config_headers="$ac_config_headers lib/zlib/zconf.h" - ac_config_files="$ac_config_files lib/zlib/Makefile" + ac_config_files="$ac_config_files lib/zlib/Makefile" -fi + if test X"$enable_shared" = X"no" -o "$enable_zlib" = "static"; then + if test "$enable_zlib" = "shared"; then + as_fn_error $? "\"Unable to build shared libraries on this system\"" "$LINENO" 5 + fi + # Build as convenience library + ZLIB_LDFLAGS=-no-install + fi + ;; +esac ac_fn_c_check_decl "$LINENO" "errno" "ac_cv_have_decl_errno" " $ac_includes_default diff --git a/configure.ac b/configure.ac index 8a5892c76..420ef4bdd 100644 --- a/configure.ac +++ b/configure.ac @@ -22,6 +22,7 @@ AC_SUBST([CPPFLAGS]) AC_SUBST([LDFLAGS]) AC_SUBST([SUDOERS_LDFLAGS]) AC_SUBST([LIBUTIL_LDFLAGS]) +AC_SUBST([ZLIB_LDFLAGS]) AC_SUBST([LT_LDFLAGS]) AC_SUBST([LT_LDDEP]) AC_SUBST([LT_LDEXPORTS]) @@ -2903,7 +2904,7 @@ case "$enable_zlib" in AC_DEFINE(HAVE_ZLIB_H) ZLIB="-lz" ;; - builtin) + static|shared|builtin) # handled below ;; *) @@ -2913,14 +2914,23 @@ case "$enable_zlib" in ZLIB="${ZLIB} -lz" ;; esac -if test X"$enable_zlib" = X"builtin"; then - AC_DEFINE(HAVE_ZLIB_H) - CPPFLAGS='-I$(top_builddir)/lib/zlib -I$(top_srcdir)/lib/zlib '"${CPPFLAGS}" - ZLIB="${ZLIB}"' $(top_builddir)/lib/zlib/libz.la' - ZLIB_SRC=lib/zlib - AC_CONFIG_HEADER([lib/zlib/zconf.h]) - AC_CONFIG_FILES([lib/zlib/Makefile]) -fi +case "$enable_zlib" in + builtin|static|dynamic) + AC_DEFINE(HAVE_ZLIB_H) + CPPFLAGS='-I$(top_builddir)/lib/zlib -I$(top_srcdir)/lib/zlib '"${CPPFLAGS}" + ZLIB="${ZLIB}"' $(top_builddir)/lib/zlib/libsudo_z.la' + ZLIB_SRC=lib/zlib + AC_CONFIG_HEADER([lib/zlib/zconf.h]) + AC_CONFIG_FILES([lib/zlib/Makefile]) + if test X"$enable_shared" = X"no" -o "$enable_zlib" = "static"; then + if test "$enable_zlib" = "shared"; then + AC_MSG_ERROR(["Unable to build shared libraries on this system"]) + fi + # Build as convenience library + ZLIB_LDFLAGS=-no-install + fi + ;; +esac dnl dnl Check for errno declaration in errno.h diff --git a/lib/zlib/Makefile.in b/lib/zlib/Makefile.in index ed7379aae..bf493fa69 100644 --- a/lib/zlib/Makefile.in +++ b/lib/zlib/Makefile.in @@ -24,16 +24,56 @@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ cross_compiling = @CROSS_COMPILING@ +# Where to install things... +prefix = @prefix@ +exec_prefix = @exec_prefix@ +bindir = @bindir@ +sbindir = @sbindir@ +sysconfdir = @sysconfdir@ +libexecdir = @libexecdir@ +datarootdir = @datarootdir@ +localstatedir = @localstatedir@ + +# File extension, mode and map file to use for shared libraries/objects +shlib_enable = @SHLIB_ENABLE@ +shlib_mode = @SHLIB_MODE@ +shlib_exp = ./zlib.exp +shlib_map = zlib.map +shlib_opt = zlib.opt + # Compiler & tools to use CC = @CC@ LIBTOOL = @LIBTOOL@ +# Our install program supports extra flags... +INSTALL = $(SHELL) $(top_srcdir)/install-sh -c +INSTALL_OWNER = -o $(install_uid) -g $(install_gid) + # C preprocessor flags CPPFLAGS = -I. -I$(srcdir) # Usually -O and/or -g CFLAGS = @CFLAGS@ +# Flags to pass to the link stage +LT_LDFLAGS = @ZLIB_LDFLAGS@ +LDFLAGS = + +# PIE flags +PIE_CFLAGS = @PIE_CFLAGS@ +PIE_LDFLAGS = @PIE_LDFLAGS@ + +# Stack smashing protection flags +SSP_CFLAGS = @SSP_CFLAGS@ +SSP_LDFLAGS = @SSP_LDFLAGS@ + +# Libtool style shared library version +SHLIB_VERSION = 0:0:0 + +# User and group ids the installed files should be "owned" by +install_uid = 0 +install_gid = 0 + # OS dependent defines DEFS = @OSDEFS@ @@ -45,7 +85,7 @@ LTOBJS = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo \ gzread.lo gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo \ trees.lo uncompr.lo zutil.lo -all: libz.la +all: libsudo_z.la Makefile: $(srcdir)/Makefile.in (cd $(top_builddir) && ./config.status --file lib/zlib/Makefile) @@ -53,14 +93,31 @@ Makefile: $(srcdir)/Makefile.in .SUFFIXES: .c .h .lo .c.lo: - $(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(DEFS) $< + $(LIBTOOL) --mode=compile $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $(PIE_CFLAGS) $(SSP_CFLAGS) $(DEFS) $< + +$(shlib_map): $(shlib_exp) + @awk 'BEGIN { print "{\n\tglobal:" } { print "\t\t"$$0";" } END { print "\tlocal:\n\t\t*;\n};" }' $(shlib_exp) > $@ + +$(shlib_opt): $(shlib_exp) + @$(SED) 's/^/+e /' $(shlib_exp) > $@ -libz.la: $(LTOBJS) - $(LIBTOOL) --mode=link $(CC) -o $@ $(LTOBJS) -no-install +libsudo_z.la: $(LTOBJS) + case "$(LT_LDFLAGS)" in \ + *-no-install*) \ + $(LIBTOOL) --mode=link $(CC) -o $@ $(LDFLAGS) $(LT_LDFLAGS) $(LTOBJS);; \ + *) \ + $(LIBTOOL) --mode=link $(CC) -o $@ $(LDFLAGS) $(LT_LDFLAGS) $(LTOBJS) -version-info $(SHLIB_VERSION) -rpath $(libexecdir)/sudo;; \ + esac pre-install: install: + case "$(LT_LDFLAGS)" in \ + *-no-install*) ;; \ + *) if [ X"$(shlib_enable)" = X"yes" ]; then \ + INSTALL_BACKUP='~' $(LIBTOOL) --quiet --mode=install $(INSTALL) $(INSTALL_OWNER) libsudo_z.la $(DESTDIR)$(libexecdir)/sudo; \ + fi;; \ + esac install-dirs: @@ -73,6 +130,7 @@ install-doc: install-plugin: uninstall: + $(LIBTOOL) --mode=uninstall rm -f $(DESTDIR)$(libexecdir)/sudo/libsudo_z.la cppcheck: diff --git a/lib/zlib/zconf.h.in b/lib/zlib/zconf.h.in index e14d01906..aab2a65a0 100644 --- a/lib/zlib/zconf.h.in +++ b/lib/zlib/zconf.h.in @@ -9,13 +9,27 @@ #define ZCONF_H /* The following four defines are enabled by sudo's configure script. */ +#undef HAVE_DSO_VISIBILITY +#undef HAVE_MEMCPY #undef HAVE_UNISTD_H #undef HAVE_VSNPRINTF -#undef HAVE_MEMCPY #undef _FILE_OFFSET_BITS #undef _LARGE_FILES #undef const +/* We build sudo and its libs with -fvisibility=hidden where supported. */ +#ifdef HAVE_DSO_VISIBILITY +# if defined(__GNUC__) +# define ZEXTERN extern __attribute__((__visibility__("default"))) +# elif defined(__SUNPRO_C) +# define ZEXTERN extern __global +# elif defined(ZLIB_INTERNAL) +# define ZEXTERN extern __declspec(dllexport) +# else +# define ZEXTERN extern __declspec(dllimport) +# endif +#endif + /* * If you *really* need a unique prefix for all types and library functions, * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it. -- 2.40.0