From 7e4955774fe4e365ec762a51d90ef6365b8be315 Mon Sep 17 00:00:00 2001 From: Alexander Ivchenko Date: Fri, 9 Sep 2016 21:38:06 +0000 Subject: [PATCH] re PR target/77267 (MPX does not work in a presence of "-Wl,-as-needed" option (Ubuntu default)) Fix PR target/77267 2016-09-10 Alexander Ivchenko PR target/77267 * config.in: Regenerate. * config/i386/linux-common.h (MPX_LD_AS_NEEDED_GUARD_PUSH): New macro. (MPX_LD_AS_NEEDED_GUARD_PUSH): Ditto. (LIBMPXWRAPPERS_SPEC): Remove "--no-whole-archive" from static-libmpxwrappers case. (LIBMPX_SPEC): Add guards with MPX_LD_AS_NEEDED_GUARD_PUSH and MPX_LD_AS_NEEDED_GUARD_POP. * configure: Regenerate. * configure.ac (HAVE_LD_PUSHPOPSTATE_SUPPORT): New variable. defined if linker support "--push-state"/"--pop-state". From-SVN: r240057 --- gcc/ChangeLog | 15 +++++++++++++++ gcc/config.in | 6 ++++++ gcc/config/i386/linux-common.h | 16 +++++++++++++--- gcc/configure | 24 ++++++++++++++++++++++++ gcc/configure.ac | 21 +++++++++++++++++++++ 5 files changed, 79 insertions(+), 3 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bd49c7478c2..29d329ef080 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,18 @@ +2016-09-10 Alexander Ivchenko + + PR target/77267 + * config.in: Regenerate. + * config/i386/linux-common.h (MPX_LD_AS_NEEDED_GUARD_PUSH): + New macro. + (MPX_LD_AS_NEEDED_GUARD_PUSH): Ditto. + (LIBMPXWRAPPERS_SPEC): Remove "--no-whole-archive" from + static-libmpxwrappers case. + (LIBMPX_SPEC): Add guards with MPX_LD_AS_NEEDED_GUARD_PUSH and + MPX_LD_AS_NEEDED_GUARD_POP. + * configure: Regenerate. + * configure.ac (HAVE_LD_PUSHPOPSTATE_SUPPORT): New variable. + defined if linker support "--push-state"/"--pop-state". + 2016-09-09 Bernd Edlinger * doc/cpp.texi (__*_WIDTH__): Small wording fixes. diff --git a/gcc/config.in b/gcc/config.in index fc3321cb146..a736de3a82b 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -1538,6 +1538,12 @@ #endif +/* Define if your linker supports --push-state/--pop-state */ +#ifndef USED_FOR_TARGET +#undef HAVE_LD_PUSHPOPSTATE_SUPPORT +#endif + + /* Define if your linker links a mix of read-only and read-write sections into a read-write section. */ #ifndef USED_FOR_TARGET diff --git a/gcc/config/i386/linux-common.h b/gcc/config/i386/linux-common.h index 4b9910fa902..22731706a25 100644 --- a/gcc/config/i386/linux-common.h +++ b/gcc/config/i386/linux-common.h @@ -79,13 +79,23 @@ along with GCC; see the file COPYING3. If not see #endif #endif +#ifdef HAVE_LD_PUSHPOPSTATE_SUPPORT +#define MPX_LD_AS_NEEDED_GUARD_PUSH "--push-state --no-as-needed" +#define MPX_LD_AS_NEEDED_GUARD_POP "--pop-state" +#else +#define MPX_LD_AS_NEEDED_GUARD_PUSH "" +#define MPX_LD_AS_NEEDED_GUARD_POP "" +#endif + #ifndef LIBMPX_SPEC #if defined(HAVE_LD_STATIC_DYNAMIC) #define LIBMPX_SPEC "\ %{mmpx:%{fcheck-pointer-bounds:\ %{static:--whole-archive -lmpx --no-whole-archive" LIBMPX_LIBS "}\ %{!static:%{static-libmpx:" LD_STATIC_OPTION " --whole-archive}\ - -lmpx %{static-libmpx:--no-whole-archive " LD_DYNAMIC_OPTION \ + %{!static-libmpx:" MPX_LD_AS_NEEDED_GUARD_PUSH "} -lmpx \ + %{!static-libmpx:" MPX_LD_AS_NEEDED_GUARD_POP "} \ + %{static-libmpx:--no-whole-archive " LD_DYNAMIC_OPTION \ LIBMPX_LIBS "}}}}" #else #define LIBMPX_SPEC "\ @@ -98,8 +108,8 @@ along with GCC; see the file COPYING3. If not see #define LIBMPXWRAPPERS_SPEC "\ %{mmpx:%{fcheck-pointer-bounds:%{!fno-chkp-use-wrappers:\ %{static:-lmpxwrappers}\ - %{!static:%{static-libmpxwrappers:" LD_STATIC_OPTION " --whole-archive}\ - -lmpxwrappers %{static-libmpxwrappers:--no-whole-archive "\ + %{!static:%{static-libmpxwrappers:" LD_STATIC_OPTION "}\ + -lmpxwrappers %{static-libmpxwrappers: "\ LD_DYNAMIC_OPTION "}}}}}" #else #define LIBMPXWRAPPERS_SPEC "\ diff --git a/gcc/configure b/gcc/configure index 871ed0c3d15..0eeee94307e 100755 --- a/gcc/configure +++ b/gcc/configure @@ -29609,6 +29609,30 @@ fi { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_bndplt_support" >&5 $as_echo "$ld_bndplt_support" >&6; } +# Check linker supports '--push-state'/'--pop-state' +ld_pushpopstate_support=no +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking linker --push-state/--pop-state options" >&5 +$as_echo_n "checking linker --push-state/--pop-state options... " >&6; } +if test x"$ld_is_gold" = xno; then + if test $in_tree_ld = yes ; then + if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 25 -o "$gcc_cv_gld_major_version" -gt 2; then + ld_pushpopstate_support=yes + fi + elif test x$gcc_cv_ld != x; then + # Check if linker supports --push-state/--pop-state options + if $gcc_cv_ld --help 2>/dev/null | grep -- '--push-state' > /dev/null; then + ld_pushpopstate_support=yes + fi + fi +fi +if test x"$ld_pushpopstate_support" = xyes; then + +$as_echo "#define HAVE_LD_PUSHPOPSTATE_SUPPORT 1" >>confdefs.h + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ld_pushpopstate_support" >&5 +$as_echo "$ld_pushpopstate_support" >&6; } + # Configure the subdirectories # AC_CONFIG_SUBDIRS($subdirs) diff --git a/gcc/configure.ac b/gcc/configure.ac index 241e82dfc72..93af766a57c 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -6237,6 +6237,27 @@ if test x"$ld_bndplt_support" = xyes; then fi AC_MSG_RESULT($ld_bndplt_support) +# Check linker supports '--push-state'/'--pop-state' +ld_pushpopstate_support=no +AC_MSG_CHECKING(linker --push-state/--pop-state options) +if test x"$ld_is_gold" = xno; then + if test $in_tree_ld = yes ; then + if test "$gcc_cv_gld_major_version" -eq 2 -a "$gcc_cv_gld_minor_version" -ge 25 -o "$gcc_cv_gld_major_version" -gt 2; then + ld_pushpopstate_support=yes + fi + elif test x$gcc_cv_ld != x; then + # Check if linker supports --push-state/--pop-state options + if $gcc_cv_ld --help 2>/dev/null | grep -- '--push-state' > /dev/null; then + ld_pushpopstate_support=yes + fi + fi +fi +if test x"$ld_pushpopstate_support" = xyes; then + AC_DEFINE(HAVE_LD_PUSHPOPSTATE_SUPPORT, 1, + [Define if your linker supports --push-state/--pop-state]) +fi +AC_MSG_RESULT($ld_pushpopstate_support) + # Configure the subdirectories # AC_CONFIG_SUBDIRS($subdirs) -- 2.30.2