This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: BZ #14865: linker -z XXXX support isn't properly checked


On Wed, Nov 21, 2012 at 1:33 PM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Hi,
>
> This patch uses "ld -v --help" to check if a linker -z XXXX is mentioned
> before trying gcc -Wl,-z,XXXX since GNU linker ignores unknown -z XXX
> option with a warning.  Tested on x86-64.  OK to install?
>
> Thanks.
>
>
> H.J.
> ---
> 2012-11-21  H.J. Lu  <hongjiu.lu@intel.com>
>
>         [BZ #14865]
>         * aclocal.m4 (LIBC_LINKER_FEATURE): New macro.
>         * configure.in: Use LIBC_LINKER_FEATURE to check -z nodelete,
>         -z nodlopen, -z initfirst and -z execstack support.
>         * configure: Regenerated.

Several of the original checks used `-nostartfiles', but your new
LBIC_LINKER_FEATURE doesn't.

Will that make any difference when bootstrapping?

I think the idea of the patch is OK, but I'm worried about the
-nostartfiles difference.

> diff --git a/aclocal.m4 b/aclocal.m4
> index b173e9e..346855e 100644
> --- a/aclocal.m4
> +++ b/aclocal.m4
> @@ -213,3 +213,30 @@ AC_DEFUN([ACX_BUGURL],[
>    AC_SUBST(REPORT_BUGS_TO)
>    AC_SUBST(REPORT_BUGS_TEXI)
>  ])
> +
> +dnl Check linker option support.
> +dnl LIBC_LINKER_FEATURE([ld_option], [cc_option], [action-if-true], [action-if-false])
> +AC_DEFUN([LIBC_LINKER_FEATURE],
> +[AC_MSG_CHECKING([for linker that supports $1])
> +libc_linker_feature=no
> +if test x"$gnu_ld" = x"yes"; then
> +  libc_linker_check=`$LD -v --help 2>/dev/null | grep "\$1"`
> +  if test -n "$libc_linker_check"; then
> +    cat > conftest.c <<EOF
> +int _start (void) { return 42; }
> +EOF
> +    if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS $2 -nostdlib
> +                               -fPIC -shared -o conftest.so conftest.c
> +                               1>&AS_MESSAGE_LOG_FD])
> +    then
> +      libc_linker_feature=yes
> +    fi
> +    rm -f conftest*
> +  fi
> +fi
> +if test $libc_linker_feature = yes; then
> +  $3
> +else
> +  $4
> +fi
> +AC_MSG_RESULT($libc_linker_feature)])
> diff --git a/configure b/configure
> index 1927ce8..1638565 100755
> --- a/configure
> +++ b/configure
> @@ -6235,86 +6235,98 @@ if test $libc_cv_cc_with_libunwind = yes; then
>
>  fi
>
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -z nodelete option" >&5
> -$as_echo_n "checking for -z nodelete option... " >&6; }
> -if ${libc_cv_z_nodelete+:} false; then :
> -  $as_echo_n "(cached) " >&6
> -else
> -  cat > conftest.c <<EOF
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker that supports -z nodelete" >&5
> +$as_echo_n "checking for linker that supports -z nodelete... " >&6; }
> +libc_linker_feature=no
> +if test x"$gnu_ld" = x"yes"; then
> +  libc_linker_check=`$LD -v --help 2>/dev/null | grep "\-z nodelete"`
> +  if test -n "$libc_linker_check"; then
> +    cat > conftest.c <<EOF
>  int _start (void) { return 42; }
>  EOF
> -if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
> -                  -fPIC -shared -o conftest.so conftest.c
> -                  -nostartfiles -nostdlib
> -                  -Wl,--enable-new-dtags,-z,nodelete 1>&5'
> +    if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -Wl,--enable-new-dtags,-z,nodelete -nostdlib
> +                               -fPIC -shared -o conftest.so conftest.c
> +                               1>&5'
>    { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
>    (eval $ac_try) 2>&5
>    ac_status=$?
>    $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>    test $ac_status = 0; }; }
> -then
> +    then
> +      libc_linker_feature=yes
> +    fi
> +    rm -f conftest*
> +  fi
> +fi
> +if test $libc_linker_feature = yes; then
>    libc_cv_z_nodelete=yes
>  else
>    as_fn_error $? "linker with -z nodelete support required" "$LINENO" 5
>  fi
> -rm -f conftest*
> -fi
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_z_nodelete" >&5
> -$as_echo "$libc_cv_z_nodelete" >&6; }
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
> +$as_echo "$libc_linker_feature" >&6; }
>
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -z nodlopen option" >&5
> -$as_echo_n "checking for -z nodlopen option... " >&6; }
> -if ${libc_cv_z_nodlopen+:} false; then :
> -  $as_echo_n "(cached) " >&6
> -else
> -  cat > conftest.c <<EOF
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker that supports -z nodlopen" >&5
> +$as_echo_n "checking for linker that supports -z nodlopen... " >&6; }
> +libc_linker_feature=no
> +if test x"$gnu_ld" = x"yes"; then
> +  libc_linker_check=`$LD -v --help 2>/dev/null | grep "\-z nodlopen"`
> +  if test -n "$libc_linker_check"; then
> +    cat > conftest.c <<EOF
>  int _start (void) { return 42; }
>  EOF
> -if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
> -                       -fPIC -shared -o conftest.so conftest.c
> -                       -nostartfiles -nostdlib
> -                       -Wl,--enable-new-dtags,-z,nodlopen 1>&5'
> +    if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -Wl,--enable-new-dtags,-z,nodlopen -nostdlib
> +                               -fPIC -shared -o conftest.so conftest.c
> +                               1>&5'
>    { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
>    (eval $ac_try) 2>&5
>    ac_status=$?
>    $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>    test $ac_status = 0; }; }
> -then
> +    then
> +      libc_linker_feature=yes
> +    fi
> +    rm -f conftest*
> +  fi
> +fi
> +if test $libc_linker_feature = yes; then
>    libc_cv_z_nodlopen=yes
>  else
>    as_fn_error $? "linker with -z nodlopen support required" "$LINENO" 5
>  fi
> -rm -f conftest*
> -fi
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_z_nodlopen" >&5
> -$as_echo "$libc_cv_z_nodlopen" >&6; }
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
> +$as_echo "$libc_linker_feature" >&6; }
>
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -z initfirst option" >&5
> -$as_echo_n "checking for -z initfirst option... " >&6; }
> -if ${libc_cv_z_initfirst+:} false; then :
> -  $as_echo_n "(cached) " >&6
> -else
> -  cat > conftest.c <<EOF
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker that supports -z initfirst" >&5
> +$as_echo_n "checking for linker that supports -z initfirst... " >&6; }
> +libc_linker_feature=no
> +if test x"$gnu_ld" = x"yes"; then
> +  libc_linker_check=`$LD -v --help 2>/dev/null | grep "\-z initfirst"`
> +  if test -n "$libc_linker_check"; then
> +    cat > conftest.c <<EOF
>  int _start (void) { return 42; }
>  EOF
> -if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
> -                       -fPIC -shared -o conftest.so conftest.c
> -                       -nostartfiles -nostdlib
> -                       -Wl,--enable-new-dtags,-z,initfirst 1>&5'
> +    if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -Wl,--enable-new-dtags,-z,initfirst -nostdlib
> +                               -fPIC -shared -o conftest.so conftest.c
> +                               1>&5'
>    { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
>    (eval $ac_try) 2>&5
>    ac_status=$?
>    $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>    test $ac_status = 0; }; }
> -then
> +    then
> +      libc_linker_feature=yes
> +    fi
> +    rm -f conftest*
> +  fi
> +fi
> +if test $libc_linker_feature = yes; then
>    libc_cv_z_initfirst=yes
>  else
>    as_fn_error $? "linker with -z initfirst support required" "$LINENO" 5
>  fi
> -rm -f conftest*
> -fi
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_z_initfirst" >&5
> -$as_echo "$libc_cv_z_initfirst" >&6; }
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
> +$as_echo "$libc_linker_feature" >&6; }
>
>  # Add-on fragments can set these for other machines.
>  libc_commonpagesize=${libc_commonpagesize:-no}
> @@ -6511,32 +6523,36 @@ if test "$libc_cv_z_combreloc" = yes; then
>  fi
>
>
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -z execstack" >&5
> -$as_echo_n "checking for -z execstack... " >&6; }
> -if ${libc_cv_z_execstack+:} false; then :
> -  $as_echo_n "(cached) " >&6
> -else
> -  cat > conftest.c <<EOF
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linker that supports -z execstack" >&5
> +$as_echo_n "checking for linker that supports -z execstack... " >&6; }
> +libc_linker_feature=no
> +if test x"$gnu_ld" = x"yes"; then
> +  libc_linker_check=`$LD -v --help 2>/dev/null | grep "\-z execstack"`
> +  if test -n "$libc_linker_check"; then
> +    cat > conftest.c <<EOF
>  int _start (void) { return 42; }
>  EOF
> -if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
> -                           -fPIC -shared -o conftest.so conftest.c
> -                           -Wl,-z,execstack -nostdlib
> -                           1>&5'
> +    if { ac_try='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -Wl,-z,execstack -nostdlib
> +                               -fPIC -shared -o conftest.so conftest.c
> +                               1>&5'
>    { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
>    (eval $ac_try) 2>&5
>    ac_status=$?
>    $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
>    test $ac_status = 0; }; }
> -then
> +    then
> +      libc_linker_feature=yes
> +    fi
> +    rm -f conftest*
> +  fi
> +fi
> +if test $libc_linker_feature = yes; then
>    libc_cv_z_execstack=yes
>  else
>    libc_cv_z_execstack=no
>  fi
> -rm -f conftest*
> -fi
> -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_cv_z_execstack" >&5
> -$as_echo "$libc_cv_z_execstack" >&6; }
> +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libc_linker_feature" >&5
> +$as_echo "$libc_linker_feature" >&6; }
>
>
>  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for -fpie" >&5
> diff --git a/configure.in b/configure.in
> index 9decd7d..a7f7198 100644
> --- a/configure.in
> +++ b/configure.in
> @@ -1409,53 +1409,17 @@ if test $libc_cv_cc_with_libunwind = yes; then
>    AC_DEFINE(HAVE_CC_WITH_LIBUNWIND)
>  fi
>
> -AC_CACHE_CHECK(for -z nodelete option,
> -              libc_cv_z_nodelete, [dnl
> -cat > conftest.c <<EOF
> -int _start (void) { return 42; }
> -EOF
> -if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
> -                  -fPIC -shared -o conftest.so conftest.c
> -                  -nostartfiles -nostdlib
> -                  -Wl,--enable-new-dtags,-z,nodelete 1>&AS_MESSAGE_LOG_FD])
> -then
> -  libc_cv_z_nodelete=yes
> -else
> -  AC_MSG_ERROR(linker with -z nodelete support required)
> -fi
> -rm -f conftest*])
> +LIBC_LINKER_FEATURE([-z nodelete], [-Wl,--enable-new-dtags,-z,nodelete],
> +                   [libc_cv_z_nodelete=yes],
> +                   [AC_MSG_ERROR(linker with -z nodelete support required)])
>
> -AC_CACHE_CHECK(for -z nodlopen option,
> -              libc_cv_z_nodlopen, [dnl
> -cat > conftest.c <<EOF
> -int _start (void) { return 42; }
> -EOF
> -if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
> -                       -fPIC -shared -o conftest.so conftest.c
> -                       -nostartfiles -nostdlib
> -                       -Wl,--enable-new-dtags,-z,nodlopen 1>&AS_MESSAGE_LOG_FD])
> -then
> -  libc_cv_z_nodlopen=yes
> -else
> -  AC_MSG_ERROR(linker with -z nodlopen support required)
> -fi
> -rm -f conftest*])
> +LIBC_LINKER_FEATURE([-z nodlopen], [-Wl,--enable-new-dtags,-z,nodlopen],
> +                   [libc_cv_z_nodlopen=yes],
> +                   [AC_MSG_ERROR(linker with -z nodlopen support required)])
>
> -AC_CACHE_CHECK(for -z initfirst option,
> -              libc_cv_z_initfirst, [dnl
> -cat > conftest.c <<EOF
> -int _start (void) { return 42; }
> -EOF
> -if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
> -                       -fPIC -shared -o conftest.so conftest.c
> -                       -nostartfiles -nostdlib
> -                       -Wl,--enable-new-dtags,-z,initfirst 1>&AS_MESSAGE_LOG_FD])
> -then
> -  libc_cv_z_initfirst=yes
> -else
> -  AC_MSG_ERROR(linker with -z initfirst support required)
> -fi
> -rm -f conftest*])
> +LIBC_LINKER_FEATURE([-z initfirst], [-Wl,--enable-new-dtags,-z,initfirst],
> +                   [libc_cv_z_initfirst=yes],
> +                   [AC_MSG_ERROR(linker with -z initfirst support required)])
>
>  # Add-on fragments can set these for other machines.
>  libc_commonpagesize=${libc_commonpagesize:-no}
> @@ -1593,21 +1557,8 @@ if test "$libc_cv_z_combreloc" = yes; then
>  fi
>  AC_SUBST(libc_cv_z_combreloc)
>
> -AC_CACHE_CHECK(for -z execstack,
> -              libc_cv_z_execstack, [dnl
> -cat > conftest.c <<EOF
> -int _start (void) { return 42; }
> -EOF
> -if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS
> -                           -fPIC -shared -o conftest.so conftest.c
> -                           -Wl,-z,execstack -nostdlib
> -                           1>&AS_MESSAGE_LOG_FD])
> -then
> -  libc_cv_z_execstack=yes
> -else
> -  libc_cv_z_execstack=no
> -fi
> -rm -f conftest*])
> +LIBC_LINKER_FEATURE([-z execstack], [-Wl,-z,execstack],
> +                   [libc_cv_z_execstack=yes], [libc_cv_z_execstack=no])
>  AC_SUBST(libc_cv_z_execstack)
>
>  AC_CACHE_CHECK(for -fpie, libc_cv_fpie, [dnl


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