From patchwork Sun Jun 20 19:59:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerald Pfeifer X-Patchwork-Id: 56272 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 953891007D1 for ; Mon, 21 Jun 2010 05:59:27 +1000 (EST) Received: (qmail 19425 invoked by alias); 20 Jun 2010 19:59:26 -0000 Received: (qmail 19415 invoked by uid 22791); 20 Jun 2010 19:59:25 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from vexpert.dbai.tuwien.ac.at (HELO vexpert.dbai.tuwien.ac.at) (128.131.111.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 20 Jun 2010 19:59:20 +0000 Received: from acrux.dbai.tuwien.ac.at (acrux.dbai.tuwien.ac.at [128.131.111.60]) by vexpert.dbai.tuwien.ac.at (Postfix) with ESMTP id DCECD1E059; Sun, 20 Jun 2010 21:59:14 +0200 (CEST) Received: by acrux.dbai.tuwien.ac.at (Postfix, from userid 1203) id 1F25A1604A; Sun, 20 Jun 2010 21:59:19 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by acrux.dbai.tuwien.ac.at (Postfix) with ESMTP id 0905F16048; Sun, 20 Jun 2010 21:59:19 +0200 (CEST) Date: Sun, 20 Jun 2010 21:59:18 +0200 (CEST) From: Gerald Pfeifer To: gcc-patches@gcc.gnu.org cc: Loren James Rittle Subject: [4.4, libmudflap] backport FreeBSD fixes Message-ID: User-Agent: Alpine 1.99 (LSU 1142 2008-08-13) 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 Looking at testresults more often the last weeks, those 353 failures from libmudflap coming from my FreeBSD testers really annoyed/worried me, so I investigated a bit and found that Loren had fixed this for GCC 4.4 and later. Here are the straightforward backports Backport from mainline: 2009-09-01 Loren J. Rittle * mf-runtime.c (__mf_init): Support FreeBSD. Prime mutex which calls calloc upon first lock to avoid deadlock. * mf-hooks1.c (__mf_0fn_mmap): Support FreeBSD. Ignore red zone allocation request for initial thread's stack. Backport from mainline: 2009-09-01 Loren J. Rittle Andreas Schwab * testsuite/libmudflap.c/pass51-frag.c (MAP_FAILED): Define, if not in system header; use it. On FreeBSD, must pass fd==-1 with MAP_ANON flag. Correct mmap error check. * testsuite/libmudflap.c/fail40-frag.c: Ditto. which I tested on i386-unknown-freebsd9.0 to see libmudflap go from # of expected passes 1541 # of unexpected failures 353 to # of expected passes 1889 # of unexpected failures 5 FAIL: libmudflap.c++/pass41-frag.cxx execution test FAIL: libmudflap.c++/pass41-frag.cxx (-static) execution test FAIL: libmudflap.c++/pass41-frag.cxx ( -O) execution test FAIL: libmudflap.c++/pass41-frag.cxx (-O2) execution test FAIL: libmudflap.c++/pass41-frag.cxx (-O3) execution test Installed based on a general approval by Loren. Gerald Index: mf-hooks1.c =================================================================== --- mf-hooks1.c (revision 151277) +++ mf-hooks1.c (revision 151278) @@ -321,6 +321,11 @@ void * __mf_0fn_mmap (void *start, size_t l, int prot, int f, int fd, off_t off) { +#if defined(__FreeBSD__) + if (f == 0x1000 && fd == -1 && prot == 0 && off == 0) + return 0; +#endif /* Ignore red zone allocation request for initial thread's stack. */ + return (void *) -1; } #endif Index: mf-runtime.c =================================================================== --- mf-runtime.c (revision 151277) +++ mf-runtime.c (revision 151278) @@ -695,6 +695,12 @@ if (LIKELY (__mf_starting_p == 0)) return; +#if defined(__FreeBSD__) && defined(LIBMUDFLAPTH) + pthread_self(); + LOCKTH (); + UNLOCKTH (); +#endif /* Prime mutex which calls calloc upon first lock to avoid deadlock. */ + /* This initial bootstrap phase requires that __mf_starting_p = 1. */ #ifdef PIC __mf_resolve_dynamics (); Index: testsuite/libmudflap.c/pass51-frag.c =================================================================== --- testsuite/libmudflap.c/pass51-frag.c (revision 151276) +++ testsuite/libmudflap.c/pass51-frag.c (revision 151277) @@ -13,14 +13,17 @@ #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON #endif +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif #ifdef HAVE_MMAP void *p; unsigned pg = getpagesize (); int rc; p = mmap (NULL, 4 * pg, PROT_READ|PROT_WRITE, - MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); - if (p == NULL) + MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (p == MAP_FAILED) return 1; memset (p, 0, 4*pg); Index: testsuite/libmudflap.c/fail40-frag.c =================================================================== --- testsuite/libmudflap.c/fail40-frag.c (revision 151276) +++ testsuite/libmudflap.c/fail40-frag.c (revision 151277) @@ -14,6 +14,9 @@ #ifndef MAP_ANONYMOUS #define MAP_ANONYMOUS MAP_ANON #endif +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif #ifdef HAVE_MMAP volatile unsigned char *p; unsigned num = getpagesize (); @@ -23,8 +26,8 @@ /* Get a bit of usable address space. We really want an 2**N+1-sized object, so the low/high addresses wrap when hashed into the lookup cache. So we will manually unregister the entire mmap, then re-register a slice. */ - p = mmap (NULL, num, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); - if (p == NULL) + p = mmap (NULL, num, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (p == MAP_FAILED) return 1; /* Now unregister it, as if munmap was called. But don't actually munmap, so we can write into the memory. */