Patchwork Support libmudflap on Solaris (PR libmudflap/38738)

login
register
mail settings
Submitter Rainer Orth
Date June 20, 2011, 11:45 a.m.
Message ID <yddoc1spvyj.fsf@manam.CeBiTec.Uni-Bielefeld.DE>
Download mbox | patch
Permalink /patch/101097/
State New
Headers show

Comments

Rainer Orth - June 20, 2011, 11:45 a.m.
I had long meant to revisit libmudflap support on Solaris and finally
got to it this weekend.

libmudflap could always be used with GNU ld since it relies on --wrap,
but recent builds of Solaris 11 (snv_125 and up) include -z wrap/--wrap
support in the Sun linker, too.

One generic issue came up with the port: enabling or disabling
libmudflap depends on a factor (linker support for --wrap/-z wrap) that
is best checked dynamically, thus doesn't really seem to belong at the
toplevel.  Is there any precedent for performing such a test in the
target library and enabling or disabling depending on the outcome?  For
now, I rely on users to pass --enable-libmudflap to work around this,
but this could (and should, IMO) be automatic.

The following patch is an initial attempt to get libmudflap working.  A
couple of comments:

* The gcc/config/sol2.h part defines MFLIB_SPEC for use with Sun ld; the
  default is GNU ld-specific.  It relies on a massive overhaul of the
  gcc Solaris configuration that I'm going to install once testing is
  completed.

* Solaris has <sys/mnttab.h> instead of <mntent.h> and getmntent has a
  different signature.  The patch below hacks around this; I'll complete
  support once the basic stuff is working.

* Similarly, pass-stratcliff.c is highly unportable.  It should either
  be made Linux-only or the current __FreeBSD__/__sun__&&__svr4__ tests
  replaced by autoconf tests for the Linuxisms.

* libmudflap.so depends on connect etc., which live in libsocket on
  Solaris.  There's no need for its usual companion, libnsl, which
  simplifies the configure test compared to what libjava does.

With this patch, libmudflap builds with both Sun ld and GNU ld on
i386-pc-solaris2.11.  Testsuite results aren't too bad:

		=== libmudflap Summary ===

# of expected passes		2056
# of unexpected failures	288

It seems the failures fall into only a few categories.  It's probably
best to analyse and fix those before checking in the patch.  Where
should we continue discussing the failures?  Here or rather in the PR?

Thanks.
	Rainer


2011-06-19  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	gcc:
	PR libmudflap/38738
	* config/sol2.h [!USE_GLD] (MFLIB_SPEC): Define.

	libmudflap:
	PR libmudflap/38738
	* configure.ac: Check for sys/mnttab.h.
	Check for library containing connect.
	* configure: Regenerate.
	* config.h.in: Regenerate.
	* mf-hooks2.c [HAVE_SYS_MNTTAB_H]: Include <sys/mnttab.h>.
	* testsuite/libmudflap.c/pass-stratcliff.c (main) [__sun__ &&
	__svr4__]: Disable rawmemchr, stpcpy, mempcpy tests.

Patch

diff --git a/gcc/config/sol2.h b/gcc/config/sol2.h
--- a/gcc/config/sol2.h
+++ b/gcc/config/sol2.h
@@ -187,6 +187,11 @@  along with GCC; see the file COPYING3.  
 #endif /* HAVE_LD_EH_FRAME && TARGET_DL_ITERATE_PHDR */
 #endif
 
+#ifndef USE_GLD
+/* The default MFLIB_SPEC is GNU ld specific.  */
+#define MFLIB_SPEC ""
+#endif
+
 /* collect2.c can only parse GNU nm -n output.  Solaris nm needs -png to
    produce the same format.  */
 #define NM_FLAGS "-png"
diff --git a/libmudflap/configure.ac b/libmudflap/configure.ac
--- a/libmudflap/configure.ac
+++ b/libmudflap/configure.ac
@@ -62,7 +62,7 @@  enable_shared=no])
 
 AC_CHECK_HEADERS(stdint.h execinfo.h signal.h dlfcn.h dirent.h pwd.h grp.h \
   netdb.h sys/ipc.h sys/sem.h sys/shm.h sys/wait.h ctype.h mntent.h \
-  sys/socket.h netinet/in.h arpa/inet.h dlfcn.h sys/mman.h)
+  sys/mnttab.h sys/socket.h netinet/in.h arpa/inet.h dlfcn.h sys/mman.h)
 
 AC_CHECK_FUNCS(backtrace backtrace_symbols gettimeofday signal)
 AC_CHECK_FUNCS(fopen64 fseeko64 ftello64 stat64 freopen64)
@@ -147,6 +147,8 @@  AC_SUBST(build_libmudflapth)
 
 AC_CHECK_LIB(dl, dlsym)
 
+AC_CHECK_FUNC(connect,, AC_CHECK_LIB(socket, connect))
+
 # Calculate toolexeclibdir
 # Also toolexecdir, though it's only used in toolexeclibdir
 case ${version_specific_libs} in
diff --git a/libmudflap/mf-hooks2.c b/libmudflap/mf-hooks2.c
--- a/libmudflap/mf-hooks2.c
+++ b/libmudflap/mf-hooks2.c
@@ -1,5 +1,5 @@ 
 /* Mudflap: narrow-pointer bounds-checking by tree rewriting.
-   Copyright (C) 2002, 2003, 2004, 2009 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2009, 2011 Free Software Foundation, Inc.
    Contributed by Frank Ch. Eigler <fche@redhat.com>
    and Graydon Hoare <graydon@redhat.com>
 
@@ -90,6 +90,9 @@  see the files COPYING3 and COPYING.RUNTI
 #ifdef HAVE_MNTENT_H
 #include <mntent.h>
 #endif
+#ifdef HAVE_SYS_MNTTAB_H
+#include <sys/mnttab.h>
+#endif
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
 #endif
@@ -2063,6 +2066,7 @@  WRAPPER2(const char *, gai_strerror, int
 
 
 #ifdef HAVE_GETMNTENT
+#ifdef HAVE_MNTENT_H
 WRAPPER2(struct mntent *, getmntent, FILE *filep)
 {
   struct mntent *m;
@@ -2097,6 +2101,9 @@  WRAPPER2(struct mntent *, getmntent, FIL
 
   return m;
 }
+#elif defined HAVE_SYS_MNTTAB_H
+/* FIXME: Implement.  */
+#endif
 #endif
 
 
diff --git a/libmudflap/testsuite/libmudflap.c/pass-stratcliff.c b/libmudflap/testsuite/libmudflap.c/pass-stratcliff.c
--- a/libmudflap/testsuite/libmudflap.c/pass-stratcliff.c
+++ b/libmudflap/testsuite/libmudflap.c/pass-stratcliff.c
@@ -153,7 +153,7 @@  main (int argc, char *argv[])
 	    }
         }
 
-#ifndef __FreeBSD__
+#if !defined  __FreeBSD__ && !(defined __sun__ && defined __svr4__)
       /* rawmemchr test */
       for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
         {
@@ -250,7 +250,7 @@  main (int argc, char *argv[])
 	    }
         }
 
-#ifndef __FreeBSD__
+#ifndef __FreeBSD__ && !(defined __sun__ && defined __svr4__)
       /* stpcpy test */
       for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
         {
@@ -302,7 +302,7 @@  main (int argc, char *argv[])
 	      result = 1;
 	    }
 
-#ifndef __FreeBSD__
+#if !defined __FreeBSD__ && !(defined __sun__ && defined __svr4__)
       /* mempcpy test */
       for (outer = size - 1; outer >= MAX (0, size - 128); --outer)
 	for (inner = 0; inner < size - outer; ++inner)