shithub: sox

Download patch

ref: d00500075aa840e1149b6fae3700856e3f74f345
parent: 2862cc5e69efbaeec829b0f69545e68083edc15f
author: Chris Bagwell <chris@cnpbagwell.com>
date: Tue Dec 16 16:41:24 EST 2014

Update stack-protect logic to work for cygwin

Get ready for 14.4.2rc1 release.

--- a/ChangeLog
+++ b/ChangeLog
@@ -4,7 +4,7 @@
 This file contains a list of all changes starting after the release of
 sox-11gamma, followed by a list of prior authors and features.
 
-sox-14.4.2	20xx-xx-xx
+sox-14.4.2	2014-12-31
 ----------
 
 Previously deprecated features that have been removed in this release:
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
 
 AC_PREREQ(2.62)
 
-AC_INIT(SoX, 14.4.2git, sox-devel@lists.sourceforge.net)
+AC_INIT(SoX, 14.4.2rc1, sox-devel@lists.sourceforge.net)
 
 AC_CONFIG_MACRO_DIR([m4])
 
@@ -91,6 +91,76 @@
     enable_debug=no
 fi
 
+# -fstack-protector
+AC_ARG_ENABLE([stack-protector],
+    [AS_HELP_STRING([--disable-stack-protector],
+        [Disable GCC's/libc's stack-smashing protection])],
+    [case "${enableval}" in
+         yes) enable_ssp=yes ;;
+          no) enable_ssp=no ;;
+           *) AC_MSG_ERROR([invalid value ${enableval} for --disable-stack-protector]) ;;
+     esac],
+    [enable_ssp=yes])
+
+if test x"$enable_ssp" = x"yes" && test x"$GCC" != x"yes"; then
+    AC_MSG_NOTICE([Disabling stack-smashing protection because compiler is not GCC])
+    enable_ssp=no
+fi
+
+if test x"$enable_ssp" = x"yes"; then
+    # Check for broken ssp in libc: http://www.avahi.org/ticket/105
+    # libc's brokenness will get in the way regardless of whether -lssp is
+    # provided, but provide it anyway (otherwise non-libc ssp would wrongly
+    # break here)
+
+    # Get -lssp if it exists
+    GCC_STACK_PROTECT_LIB
+
+    AC_MSG_CHECKING([whether stack-smashing protection is available])
+    ssp_old_cflags="$CFLAGS"
+    ssp_old_ldflags="$LDFLAGS"
+    CFLAGS="$CFLAGS -Werror -fstack-protector-all -fPIC"
+    LDFLAGS="$LDFLAGS -Wl,-z,defs"
+    cat confdefs.h > conftest.c
+    cat >>conftest.c <<_ACEOF
+void test_broken_ssp(c)
+    const char *c;
+{
+    char arr[[123]], *p; /* beware of possible double-braces if copying this */
+    for (p = arr; *c; ++p) {
+        *p = *c;
+        ++c;
+    }
+}
+_ACEOF
+    rm -f conftest.o
+
+    if $CC -c $CFLAGS $CPPFLAGS -o conftest.o conftest.c >/dev/null 2>&1; then
+        AC_MSG_RESULT([yes])
+        AC_MSG_CHECKING([whether stack-smashing protection is buggy])
+        if $CC -o conftest.so $LDFLAGS -shared conftest.o $LIBS >/dev/null 2>&1; then
+            AC_MSG_RESULT([no])
+        else
+            AC_MSG_RESULT([yes])
+            enable_ssp=no
+        fi
+    else
+        AC_MSG_RESULT([no])
+    fi
+
+    rm -f conftest.c conftest.o conftest.so
+
+    CFLAGS="$ssp_old_cflags"
+    LDFLAGS="$ssp_old_ldflags"
+fi
+
+if test x"$enable_ssp" = x"yes"; then
+    # Do this the long way so we don't call GCC_STACK_PROTECT_LIB twice
+    GCC_STACK_PROTECT_CC
+
+    # XXX: Update the enable_ssp value now for output later?
+fi
+
 dnl Extra CFLAGS if we have gcc
 if test "$GCC" = "yes"; then
 
@@ -99,11 +169,6 @@
     AC_MSG_RESULT($gccver)
 
     CFLAGS="$CFLAGS -Wall -W -Wmissing-prototypes -Wstrict-prototypes -pedantic"
-    AS_VERSION_COMPARE([$gccver], [4.1],,
-		       [CFLAGS="$CFLAGS -fstack-protector"],
-		       [AS_VERSION_COMPARE([$gccver], [4.9],,
-					  [CFLAGS="$CFLAGS -fstack-protector-strong"],
-					  [CFLAGS="$CFLAGS -fstack-protector-strong"])])
 
     AS_VERSION_COMPARE([$gccver], [4.3],
        [WARN_CFLAGS="-Wconversion"],
--- /dev/null
+++ b/m4/gcc_stack_protect.m4
@@ -1,0 +1,99 @@
+dnl
+dnl Useful macros for autoconf to check for ssp-patched gcc
+dnl 1.0 - September 2003 - Tiago Sousa <mirage@kaotik.org>
+dnl 1.1 - August 2006 - Ted Percival <ted@midg3t.net>
+dnl     * Stricter language checking (C or C++)
+dnl     * Adds GCC_STACK_PROTECT_LIB to add -lssp to LDFLAGS as necessary
+dnl     * Caches all results
+dnl     * Uses macros to ensure correct ouput in quiet/silent mode
+dnl 1.2 - April 2007 - Ted Percival <ted@midg3t.net>
+dnl     * Added GCC_STACK_PROTECTOR macro for simpler (one-line) invocation
+dnl     * GCC_STACK_PROTECT_LIB now adds -lssp to LIBS rather than LDFLAGS
+dnl
+dnl About ssp:
+dnl GCC extension for protecting applications from stack-smashing attacks
+dnl http://www.research.ibm.com/trl/projects/security/ssp/
+dnl
+dnl Usage:
+dnl Most people will simply call GCC_STACK_PROTECTOR.
+dnl If you only use one of C or C++, you can save time by only calling the
+dnl macro appropriate for that language. In that case you should also call
+dnl GCC_STACK_PROTECT_LIB first.
+dnl
+dnl GCC_STACK_PROTECTOR
+dnl Tries to turn on stack protection for C and C++ by calling the following
+dnl three macros with the right languages.
+dnl
+dnl GCC_STACK_PROTECT_CC
+dnl checks -fstack-protector with the C compiler, if it exists then updates
+dnl CFLAGS and defines ENABLE_SSP_CC
+dnl
+dnl GCC_STACK_PROTECT_CXX
+dnl checks -fstack-protector with the C++ compiler, if it exists then updates
+dnl CXXFLAGS and defines ENABLE_SSP_CXX
+dnl
+dnl GCC_STACK_PROTECT_LIB
+dnl adds -lssp to LIBS if it is available
+dnl ssp is usually provided as part of libc, but was previously a separate lib
+dnl It does not hurt to add -lssp even if libc provides SSP - in that case
+dnl libssp will simply be ignored.
+dnl
+
+AC_DEFUN([GCC_STACK_PROTECT_LIB],[
+  AC_CACHE_CHECK([whether libssp exists], ssp_cv_lib,
+    [ssp_old_libs="$LIBS"
+     LIBS="$LIBS -lssp"
+     AC_TRY_LINK(,, ssp_cv_lib=yes, ssp_cv_lib=no)
+     LIBS="$ssp_old_libs"
+    ])
+  if test $ssp_cv_lib = yes; then
+    LIBS="$LIBS -lssp"
+  fi
+])
+
+AC_DEFUN([GCC_STACK_PROTECT_CC],[
+  AC_LANG_ASSERT(C)
+  if test "X$CC" != "X"; then
+    AC_CACHE_CHECK([whether ${CC} accepts -fstack-protector],
+      ssp_cv_cc,
+      [ssp_old_cflags="$CFLAGS"
+       CFLAGS="$CFLAGS -fstack-protector -Werror"
+       AC_TRY_COMPILE(,, ssp_cv_cc=yes, ssp_cv_cc=no)
+       CFLAGS="$ssp_old_cflags"
+      ])
+    if test $ssp_cv_cc = yes; then
+      CFLAGS="$CFLAGS -fstack-protector"
+      AC_DEFINE([ENABLE_SSP_CC], 1, [Define if SSP C support is enabled.])
+    fi
+  fi
+])
+
+AC_DEFUN([GCC_STACK_PROTECT_CXX],[
+  AC_LANG_ASSERT(C++)
+  if test "X$CXX" != "X"; then
+    AC_CACHE_CHECK([whether ${CXX} accepts -fstack-protector],
+      ssp_cv_cxx,
+      [ssp_old_cxxflags="$CXXFLAGS"
+       CXXFLAGS="$CXXFLAGS -fstack-protector -Werror"
+       AC_TRY_COMPILE(,, ssp_cv_cxx=yes, ssp_cv_cxx=no)
+       CXXFLAGS="$ssp_old_cxxflags"
+      ])
+    if test $ssp_cv_cxx = yes; then
+      CXXFLAGS="$CXXFLAGS -fstack-protector"
+      AC_DEFINE([ENABLE_SSP_CXX], 1, [Define if SSP C++ support is enabled.])
+    fi
+  fi
+])
+
+AC_DEFUN([GCC_STACK_PROTECTOR],[
+  GCC_STACK_PROTECT_LIB
+
+  AC_LANG_PUSH([C])
+  GCC_STACK_PROTECT_CC
+  AC_LANG_POP([C])
+
+  AC_LANG_PUSH([C++])
+  GCC_STACK_PROTECT_CXX
+  AC_LANG_POP([C++])
+])
+
--- a/mingwbuild
+++ b/mingwbuild
@@ -1,10 +1,10 @@
 #!/bin/sh
 #
-# This script will automates the steps used to producing a static win32
-# package of SoX.
+# This script will automates the steps used to producing a win32 package
+# of SoX.
 #
-# It is used on a Fedora box with mingw cross compiler and wine to
-# test.  It can also be used under MSYS but will not generate PDF docs.
+# It is used on a Fedora box with mingw32 cross compiler and wine to
+# test.
 #
 # It will optionally package up VC++ version of wget if found in
 # ../wget-1.11.4.
@@ -11,48 +11,43 @@
 #
 # Various notes:
 #
-# Script makes use of "-static" option to tell compiler to prefer static
-# external libraries so that we do not need to distribute DLL's.
+# The following command lines were used to generate the external libraries
+# SoX ships with.
 #
-# Libtool will get confused with this flag for external libraries
-# that have a libtool lib*.la file and support shared libraries as
-# well as static libraries (but usually only if that library
-# further depends on other external libraries with lib*.la files).
-# Libtool may ignore -static option or it may link first external
-# library as static but other dependent libraries as shared (usually
-# because it follows $dependency_libs and that ignores -static option).
-#
-# Work arounds include to only install static libraries, delete the lib*.la
-# file, or edit the lib*.la file and set dlnames and library_names variables
-# to empty string ("").
-#
-# The following command lines were used to generate the static external
-# libraries SoX ships with.
-#
+# Needed for libltdl support.
+# FIXME: Install
 # cd libtool-2.4.2
 # mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
 #
-# libpng.la will have libtool issue because depends on libz
-# which has a libz.la file.  Must edit libpng.la to
-# prevent needing to distribute zlib1.dll.
-# cd libpng-1.5.7
+# yum install ming32-libpng mingw32-libpng-static
+#  or
+# cd libpng-1.6.15
 # mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
 #
-# cd ../wavpack-4.60.1
+# yum install mingw32-wavpack
+#  or
+# cd ../wavpack-4.70.0
 # mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
 #
+# yum install mingw32-flac
+#  or
 # Need to disable optional ogg support to prevent duplicate symbols during
 # link.
 # Edited Makefile and removed "examples" from SUBDIRS.
-# cd ../flac-1.2.1
+# cd ../flac-1.3.1
 # mingw32-configure --disable-ogg --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
 #
-# cd ../libogg-1.3.0
+# yum install mingw32-libogg
+#  or
+# cd ../libogg-1.3.2
 # mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
 #
-# cd ../libvorbis-1.3.2
+# yum install mingw32-libvorbis
+#  or
+# cd ../libvorbis-1.3.4
 # mingw32-configure --disable-shared --enable-static;mingw-32-make;sudo mingw32-make install
 #
+# FIXME: Install libsndfile
 # Compile libsndfile after FLAC and ogg vorbis so that it will include
 # support for that.
 # MINGW work around: Can either add -lwsock32 to end of *_LDADD for any
@@ -61,6 +56,8 @@
 # cd ../libsndfile-1.0.25
 # mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
 #
+# yum install mingw32-libid3tag
+#  or
 # libid3tag does not like to be compiled shared on mingw32 cross compiler.
 # cd ../libid3tag-0.15.1b
 # mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
@@ -67,6 +64,8 @@
 #
 # To get MP3 header files used to enable MP3 support (no libraries used):
 #
+# yum install mingw32-libmad
+#  or
 # MINGW work around: Edit Makefile and remove -fforce-mem from CFLAGS
 # cd ../libmad-0.15.1b
 # mingw32-configure --enable-shared --disable-static;mingw32-make;sudo mingw32-make install
@@ -73,29 +72,12 @@
 
 [ ! -x configure ] && autoreconf -i
 
-case `uname` in
-  MINGW32*)
-  CONFIGURE=configure
-  SYS_ROOT=""
-  # Can't build PDF's on MSYS unless ghostscript is installed.
-  DOC_TARGETS=""
-  DOCS=""
-  TMP_SNDFILE_LIBS=""
-  TMP_FLAC_LIBS=""
-  STRIP=strip
-  ;;
-  *)
-  SYS_ROOT="/usr/i686-w64-mingw32/sys-root"
-  CONFIGURE=mingw32-configure
-  DOC_TARGETS="pdf"
-  DOCS="sox.pdf soxformat.pdf soxi.pdf"
-  TMP_SNDFILE_LIBS="-lsndfile -lFLAC -lvorbisenc -lvorbisfile -lvorbis -logg"
-  # TODO: libFLAC is referencing ntohl() but not defining it in their
-  # flac.pc. Its not obvious how upstream is going to fix this issue
-  # so work around in script for now.
-  #TMP_FLAC_LIBS="-lwsock32"
-  STRIP=i686-pc-mingw32-strip
-esac
+SYS_ROOT="/usr/i686-w64-mingw32/sys-root"
+CONFIGURE=mingw32-configure
+DOC_TARGETS="pdf"
+DOCS="sox.pdf soxformat.pdf soxi.pdf"
+TMP_SNDFILE_LIBS="-lsndfile -lFLAC -lvorbisenc -lvorbisfile -lvorbis -logg"
+STRIP=i686-pc-mingw32-strip
 
 # Some versions of autoconf (2.63?) seem to get easily confused about
 # CPP variable. If you see warning messages about header files
@@ -105,11 +87,10 @@
 # FLAC or ogg vorbis support.  Need to force the link ourselves.
 if [ $# -ne 0 -o ! -r Makefile ]; then
   $CONFIGURE \
-    --disable-shared \
     --with-libltdl \
     --enable-dl-lame --enable-dl-mad --enable-dl-amrnb --enable-dl-amrwb \
-    LDFLAGS="-static -L/usr/local/lib" CPPFLAGS=-I/usr/local/include \
-    SNDFILE_LIBS="${TMP_SNDFILE_LIBS}" FLAC_LIBS="${TMP_FLAC_LIBS}"\
+    LDFLAGS="-L/usr/local/lib" CPPFLAGS=-I/usr/local/include \
+    SNDFILE_LIBS="${TMP_SNDFILE_LIBS}" \
     $*
 fi
 
@@ -129,11 +110,9 @@
 
 binaries=src/sox.exe
 
-# If you do not edit libpng.la to comment out shared libraries
-# then you'll need to distribute zlib1.dll.
-dlls=""
-dlls="$dlls ${SYS_ROOT}/mingw/bin/zlib1.dll"
-dlls="$dlls ${SYS_ROOT}/mingw/bin/libgomp-1.dll"
+dlls=`/usr/i686-w64-mingw32/bin/objdump -p src/.libs/libsox-3.dll | grep "DLL Name:" | sed "s|DLL Name: |${SYS_ROOT}/mingw/bin/|" | grep -v KERNEL32.dll | grep -v msvcrt.dll | grep -v USER32.dll | grep -v WINMM.DLL`
+dlls="$dlls src/.libs/libsox-3.dll"
+dlls="$dlls ${SYS_ROOT}/mingw/bin/libwinpthread-1.dll"
 
 cp -p \
   $binaries \
@@ -142,9 +121,8 @@
   scripts/batch-example.bat \
   $dir
 
-# Special case copy to work around some case sensitivity bugs with
-# nsiswrapper under linux.
-cp -p ${SYS_ROOT}/mingw/bin/pthreadGC2.dll ${dir}/pthreadgc2.dll
+# Special case fixup for nsiswrapper. Rename libFLAC-8.dll to libflac-8.dll.
+mv $dir/libFLAC-8.dll $dir/libflac-8.dll
 
 unix2dos $dir/batch-example.bat
 
@@ -159,7 +137,7 @@
 if test -r "/usr/bin/nsiswrapper"; then
   cd ${dir}
   export PATH=$PATH:.
-  nsiswrapper --run --name $dir --outfile ../${dir}-win32.exe *.exe *.ini *.txt *.pdf *.bat
+  nsiswrapper --run --name $dir --outfile ../${dir}-win32.exe *.exe *.dll *.ini *.txt *.pdf *.bat
   cd ..
 fi
 
--- a/sox.1
+++ b/sox.1
@@ -29,7 +29,7 @@
 .SP
 .fi
 ..
-.TH SoX 1 "February 1, 2013" "sox" "Sound eXchange"
+.TH SoX 1 "December 31, 2014" "sox" "Sound eXchange"
 .SH NAME
 SoX \- Sound eXchange, the Swiss Army knife of audio manipulation
 .SH SYNOPSIS
--- a/soxformat.7
+++ b/soxformat.7
@@ -29,7 +29,7 @@
 .SP
 .fi
 ..
-.TH SoX 7 "February 1, 2013" "soxformat" "Sound eXchange"
+.TH SoX 7 "December 31, 2014" "soxformat" "Sound eXchange"
 .SH NAME
 SoX \- Sound eXchange, the Swiss Army knife of audio manipulation
 .SH DESCRIPTION
--- a/src/soxconfig.h.cmake
+++ b/src/soxconfig.h.cmake
@@ -1,4 +1,4 @@
-#define PACKAGE_VERSION "14.4.2git"
+#define PACKAGE_VERSION "14.4.2rc1"
 
 #cmakedefine EXTERNAL_GSM             1
 #cmakedefine EXTERNAL_LPC10           1