Fixed bug 4308 - Prebuilt SDL.dll files not compiled with ASLR support (DYNAMICBASE)
authorSam Lantinga <slouken@libsdl.org>
Fri, 02 Nov 2018 18:07:11 -0700
changeset 1239060f322c5984f
parent 12389 5817dbd75619
child 12391 ca6e41ade79a
Fixed bug 4308 - Prebuilt SDL.dll files not compiled with ASLR support (DYNAMICBASE)

Cameron Gutman

The current SDL 2.0.8 and the prerelease SDL 2.0.9 are compiled without the DYNAMICBASE flag to indicate that ASLR may relocate the DLL at load-time. https://docs.microsoft.com/en-us/cpp/build/reference/dynamicbase-use-address-space-layout-randomization?view=vs-2017

When I build SDL.dll myself using the VS2010 project, the DLL has the DYNAMICBASE flag set (as is the default). Similarly, MinGW-w64 also enables ASLR by default on all binaries for a couple years now (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=836365)
configure
configure.in
     1.1 --- a/configure	Fri Nov 02 17:25:00 2018 -0700
     1.2 +++ b/configure	Fri Nov 02 18:07:11 2018 -0700
     1.3 @@ -16063,6 +16063,108 @@
     1.4  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_no_undefined" >&5
     1.5  $as_echo "$have_no_undefined" >&6; }
     1.6  
     1.7 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker option --dynamicbase" >&5
     1.8 +$as_echo_n "checking for linker option --dynamicbase... " >&6; }
     1.9 +have_dynamicbase=no
    1.10 +case "$host" in
    1.11 +    *)
    1.12 +        save_LDFLAGS="$LDFLAGS"
    1.13 +        LDFLAGS="$LDFLAGS -Wl,--dynamicbase"
    1.14 +        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    1.15 +/* end confdefs.h.  */
    1.16 +
    1.17 +
    1.18 +int
    1.19 +main ()
    1.20 +{
    1.21 +
    1.22 +
    1.23 +  ;
    1.24 +  return 0;
    1.25 +}
    1.26 +_ACEOF
    1.27 +if ac_fn_c_try_link "$LINENO"; then :
    1.28 +
    1.29 +        have_dynamicbase=yes
    1.30 +        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,--dynamicbase"
    1.31 +
    1.32 +fi
    1.33 +rm -f core conftest.err conftest.$ac_objext \
    1.34 +    conftest$ac_exeext conftest.$ac_ext
    1.35 +        LDFLAGS="$save_LDFLAGS"
    1.36 +        ;;
    1.37 +esac
    1.38 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_dynamicbase" >&5
    1.39 +$as_echo "$have_dynamicbase" >&6; }
    1.40 +
    1.41 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker option --nxcompat" >&5
    1.42 +$as_echo_n "checking for linker option --nxcompat... " >&6; }
    1.43 +have_nxcompat=no
    1.44 +case "$host" in
    1.45 +    *)
    1.46 +        save_LDFLAGS="$LDFLAGS"
    1.47 +        LDFLAGS="$LDFLAGS -Wl,--nxcompat"
    1.48 +        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    1.49 +/* end confdefs.h.  */
    1.50 +
    1.51 +
    1.52 +int
    1.53 +main ()
    1.54 +{
    1.55 +
    1.56 +
    1.57 +  ;
    1.58 +  return 0;
    1.59 +}
    1.60 +_ACEOF
    1.61 +if ac_fn_c_try_link "$LINENO"; then :
    1.62 +
    1.63 +        have_nxcompat=yes
    1.64 +        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,--nxcompat"
    1.65 +
    1.66 +fi
    1.67 +rm -f core conftest.err conftest.$ac_objext \
    1.68 +    conftest$ac_exeext conftest.$ac_ext
    1.69 +        LDFLAGS="$save_LDFLAGS"
    1.70 +        ;;
    1.71 +esac
    1.72 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_nxcompat" >&5
    1.73 +$as_echo "$have_nxcompat" >&6; }
    1.74 +
    1.75 +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker option --high-entropy-va" >&5
    1.76 +$as_echo_n "checking for linker option --high-entropy-va... " >&6; }
    1.77 +have_high_entropy_va=no
    1.78 +case "$host" in
    1.79 +    *)
    1.80 +        save_LDFLAGS="$LDFLAGS"
    1.81 +        LDFLAGS="$LDFLAGS -Wl,--high-entropy-va"
    1.82 +        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    1.83 +/* end confdefs.h.  */
    1.84 +
    1.85 +
    1.86 +int
    1.87 +main ()
    1.88 +{
    1.89 +
    1.90 +
    1.91 +  ;
    1.92 +  return 0;
    1.93 +}
    1.94 +_ACEOF
    1.95 +if ac_fn_c_try_link "$LINENO"; then :
    1.96 +
    1.97 +        have_high_entropy_va=yes
    1.98 +        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,--high-entropy-va"
    1.99 +
   1.100 +fi
   1.101 +rm -f core conftest.err conftest.$ac_objext \
   1.102 +    conftest$ac_exeext conftest.$ac_ext
   1.103 +        LDFLAGS="$save_LDFLAGS"
   1.104 +        ;;
   1.105 +esac
   1.106 +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_high_entropy_va" >&5
   1.107 +$as_echo "$have_high_entropy_va" >&6; }
   1.108 +
   1.109  # Check whether --enable-libc was given.
   1.110  if test "${enable_libc+set}" = set; then :
   1.111    enableval=$enable_libc;
     2.1 --- a/configure.in	Fri Nov 02 17:25:00 2018 -0700
     2.2 +++ b/configure.in	Fri Nov 02 18:07:11 2018 -0700
     2.3 @@ -232,6 +232,57 @@
     2.4  esac
     2.5  AC_MSG_RESULT($have_no_undefined)
     2.6  
     2.7 +AC_MSG_CHECKING(for linker option --dynamicbase)
     2.8 +have_dynamicbase=no
     2.9 +case "$host" in
    2.10 +    *)
    2.11 +        save_LDFLAGS="$LDFLAGS"
    2.12 +        LDFLAGS="$LDFLAGS -Wl,--dynamicbase"
    2.13 +        AC_TRY_LINK([
    2.14 +        ],[
    2.15 +        ],[
    2.16 +        have_dynamicbase=yes
    2.17 +        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,--dynamicbase"
    2.18 +        ])
    2.19 +        LDFLAGS="$save_LDFLAGS"
    2.20 +        ;;
    2.21 +esac
    2.22 +AC_MSG_RESULT($have_dynamicbase)
    2.23 +
    2.24 +AC_MSG_CHECKING(for linker option --nxcompat)
    2.25 +have_nxcompat=no
    2.26 +case "$host" in
    2.27 +    *)
    2.28 +        save_LDFLAGS="$LDFLAGS"
    2.29 +        LDFLAGS="$LDFLAGS -Wl,--nxcompat"
    2.30 +        AC_TRY_LINK([
    2.31 +        ],[
    2.32 +        ],[
    2.33 +        have_nxcompat=yes
    2.34 +        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,--nxcompat"
    2.35 +        ])
    2.36 +        LDFLAGS="$save_LDFLAGS"
    2.37 +        ;;
    2.38 +esac
    2.39 +AC_MSG_RESULT($have_nxcompat)
    2.40 +
    2.41 +AC_MSG_CHECKING(for linker option --high-entropy-va)
    2.42 +have_high_entropy_va=no
    2.43 +case "$host" in
    2.44 +    *)
    2.45 +        save_LDFLAGS="$LDFLAGS"
    2.46 +        LDFLAGS="$LDFLAGS -Wl,--high-entropy-va"
    2.47 +        AC_TRY_LINK([
    2.48 +        ],[
    2.49 +        ],[
    2.50 +        have_high_entropy_va=yes
    2.51 +        EXTRA_LDFLAGS="$EXTRA_LDFLAGS -Wl,--high-entropy-va"
    2.52 +        ])
    2.53 +        LDFLAGS="$save_LDFLAGS"
    2.54 +        ;;
    2.55 +esac
    2.56 +AC_MSG_RESULT($have_high_entropy_va)
    2.57 +
    2.58  dnl See whether we are allowed to use the system C library
    2.59  AC_ARG_ENABLE(libc,
    2.60  AC_HELP_STRING([--enable-libc], [Use the system C library [[default=yes]]]),