From patchwork Mon Jun 20 11:45:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rainer Orth X-Patchwork-Id: 101097 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id D0E42B6FDE for ; Mon, 20 Jun 2011 21:46:23 +1000 (EST) Received: (qmail 671 invoked by alias); 20 Jun 2011 11:46:21 -0000 Received: (qmail 658 invoked by uid 22791); 20 Jun 2011 11:46:20 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_CP, TW_IB, TW_TM, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from snape.CeBiTec.Uni-Bielefeld.DE (HELO smtp-relay.CeBiTec.Uni-Bielefeld.DE) (129.70.160.84) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 20 Jun 2011 11:46:03 +0000 Received: from localhost (localhost.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTP id D9C6C95B; Mon, 20 Jun 2011 13:46:01 +0200 (CEST) Received: from smtp-relay.CeBiTec.Uni-Bielefeld.DE ([127.0.0.1]) by localhost (malfoy.CeBiTec.Uni-Bielefeld.DE [127.0.0.1]) (amavisd-new, port 10024) with LMTP id T5yK6sqeyhRM; Mon, 20 Jun 2011 13:45:57 +0200 (CEST) Received: from manam.CeBiTec.Uni-Bielefeld.DE (manam.CeBiTec.Uni-Bielefeld.DE [129.70.161.120]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-relay.CeBiTec.Uni-Bielefeld.DE (Postfix) with ESMTPS id C91A795A; Mon, 20 Jun 2011 13:45:57 +0200 (CEST) Received: (from ro@localhost) by manam.CeBiTec.Uni-Bielefeld.DE (8.14.4+Sun/8.14.4/Submit) id p5KBjuIl018422; Mon, 20 Jun 2011 13:45:56 +0200 (MEST) From: Rainer Orth To: gcc-patches@gcc.gnu.org Cc: "Frank Ch. Eigler" , "Joseph S. Myers" Subject: Support libmudflap on Solaris (PR libmudflap/38738) Date: Mon, 20 Jun 2011 13:45:56 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (usg-unix-v) MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 instead of 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 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 . * testsuite/libmudflap.c/pass-stratcliff.c (main) [__sun__ && __svr4__]: Disable rawmemchr, stpcpy, mempcpy tests. 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 and Graydon Hoare @@ -90,6 +90,9 @@ see the files COPYING3 and COPYING.RUNTI #ifdef HAVE_MNTENT_H #include #endif +#ifdef HAVE_SYS_MNTTAB_H +#include +#endif #ifdef HAVE_SYS_SOCKET_H #include #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)