This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC 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, libmpx, i386, PR driver/65444] Pass '-z bndplt' when building dynamic objects with MPX


On 04 Jun 15:53, Joseph Myers wrote:
> On Thu, 4 Jun 2015, Ilya Enkovich wrote:
> 
> > 2015-06-03 18:59 GMT+03:00 Joseph Myers <joseph@codesourcery.com>:
> > > You could, for example, have
> > >
> > > #if SOMETHING
> > > #define MSG "%nsome msg"
> > > #else
> > > #define MSG ""
> > > #endif
> > >
> > > and have another spec using MSG - that should work.
> > 
> > In this case I should define SOMETHING in configure of gcc, not in
> > configure of libmpx, right? But it would mean I check host linker, not
> > target.
> 
> gcc/ configure tests on the linker generally test the build-x-target 
> linker, which is required to have the same version and be configured the 
> same as the host-x-target linker.  (The tests mustn't actually try to link 
> anything, but they can e.g. see if a particular option is mentioned in 
> --help output.  In general they also have version number checks for the 
> case of an in-tree linker build.)
> 
> -- 
> Joseph S. Myers
> joseph@codesourcery.com

Thanks for help!  Here is a new patch version with a check moved into gcc/configure.  Does it look OK?

Thanks,
Ilya
--
gcc/

2015-06-05  Ilya Enkovich  <enkovich.gnu@gmail.com>

	* config/i386/linux-common.h (LINK_MPX): New.
	(MPX_SPEC): Use LINK_MPX instead of %(link_mpx).
	* configure.ac: Add HAVE_LD_BNDPLT_SUPPORT macro
	indicating '-z bndplt' support by linker.
	* configure: Regenerate.
	* config.in: Regenerate.

libmpx/

2015-06-05  Ilya Enkovich  <enkovich.gnu@gmail.com>

	* configure.ac: Remove link_mpx.
	* libmpx.spec.in: Likewise.
	* configure: Regenerate.


diff --git a/gcc/config/i386/linux-common.h b/gcc/config/i386/linux-common.h
index dd79ec6..63dd8d8 100644
--- a/gcc/config/i386/linux-common.h
+++ b/gcc/config/i386/linux-common.h
@@ -59,9 +59,20 @@ along with GCC; see the file COPYING3.  If not see
  %:include(libmpx.spec)%(link_libmpx)"
 #endif
 
+#ifndef LINK_MPX
+#if defined (HAVE_LD_BNDPLT_SUPPORT)
+#define LINK_MPX "-z bndplt "
+#else
+#define LINK_MPX \
+  "%nGCC was configured with a linker with no '-z bndplt' support. " \
+  "It significantly reduces MPX coverage for dynamic codes. " \
+  "It is strongly recommended to use GCC properly configured for MPX."
+#endif
+#endif
+
 #ifndef MPX_SPEC
 #define MPX_SPEC "\
- %{mmpx:%{fcheck-pointer-bounds:%{!static:%:include(libmpx.spec)%(link_mpx)}}}"
+ %{mmpx:%{fcheck-pointer-bounds:%{!static:" LINK_MPX "}}}"
 #endif
 
 #ifndef LIBMPX_SPEC
diff --git a/gcc/configure.ac b/gcc/configure.ac
index b27433e..7306a70 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -5859,6 +5859,27 @@ if test "$gcc_cv_no_pie" = "yes"; then
 fi
 AC_SUBST([NO_PIE_FLAG])
 
+# Check linker supports '-z bndplt'
+ld_bndplt_support=no
+AC_MSG_CHECKING(linker -z bndplt option)
+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_bndplt_support=yes
+    fi
+  elif test x$gcc_cv_ld != x; then
+    # Check if linker supports -a bndplt option
+    if $gcc_cv_ld --help 2>/dev/null | grep -- '-z bndplt' > /dev/null; then
+      ld_bndplt_support=yes
+    fi
+  fi
+fi
+if test x"$ld_bndplt_support" = xyes; then
+  AC_DEFINE(HAVE_LD_BNDPLT_SUPPORT, 1,
+	[Define if your linker supports -z bndplt])
+fi
+AC_MSG_RESULT($ld_bndplt_support)
+
 # Configure the subdirectories
 # AC_CONFIG_SUBDIRS($subdirs)
 
diff --git a/libmpx/configure.ac b/libmpx/configure.ac
index 463e855..18ba687 100644
--- a/libmpx/configure.ac
+++ b/libmpx/configure.ac
@@ -39,18 +39,7 @@ AC_MSG_RESULT($LIBMPX_SUPPORTED)
 AM_CONDITIONAL(LIBMPX_SUPPORTED, [test "x$LIBMPX_SUPPORTED" = "xyes"])
 
 link_libmpx="-lpthread"
-link_mpx=""
-AC_MSG_CHECKING([whether ld accepts -z bndplt])
-echo "int main() {};" > conftest.c
-if AC_TRY_COMMAND([${CC} ${CFLAGS} -Wl,-z,bndplt -o conftest conftest.c 1>&AS_MESSAGE_LOG_FD])
-then
-    AC_MSG_RESULT([yes])
-    link_mpx="$link_mpx -z bndplt"
-else
-    AC_MSG_RESULT([no])
-fi
 AC_SUBST(link_libmpx)
-AC_SUBST(link_mpx)
 
 AM_INIT_AUTOMAKE(foreign no-dist no-dependencies)
 AM_ENABLE_MULTILIB(, ..)
diff --git a/libmpx/libmpx.spec.in b/libmpx/libmpx.spec.in
index 34d0bdf..a80bba7 100644
--- a/libmpx/libmpx.spec.in
+++ b/libmpx/libmpx.spec.in
@@ -1,5 +1,3 @@
 # This spec file is read by gcc when linking.  It is used to specify the
 # standard libraries we need in order to link with libmpx.
 *link_libmpx: @link_libmpx@
-
-*link_mpx: @link_mpx@


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