From patchwork Sat Feb 11 18:01:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jack Howarth X-Patchwork-Id: 140793 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 5EBA4B6F9F for ; Sun, 12 Feb 2012 05:01:55 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1329588116; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=ORvA50MDpnPI9dgYWJ9Q ke7/7YQ=; b=K2gfTDpUPZagG7cXCy6Amp6kqry7/wzOoFNbJlw/Y2oSmgVX0UqA wmm/OGNNPg9prNAU8sO5CIMQoB94AqEoiGRA2UZWXyDtHwbo8Uza/VefVIQwop/4 Uugcq2K0RohJSMAcoYFCO145+4iDn8Sa4EFUCep6NJut7y7e1s9Bm4k= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:Cc:Subject:Message-ID:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=YZvHLqC0eciT0tBDQ6tUsCKE40aoJR9rBAGoygGd4vPK6PRSyhYHzvMsTueTA2 gPyFN0R5NJiJbJQtaHSrQRxh49oo+x8CkzyCkxrzj5FAGHjGZIWVsDUC8/70jxPR x4yEL3jkk3MoE7+SuMSdcy/AgiN0zSM1D0YX47TCjDle8=; Received: (qmail 26167 invoked by alias); 11 Feb 2012 18:01:50 -0000 Received: (qmail 26154 invoked by uid 22791); 11 Feb 2012 18:01:47 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, TW_CX, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from bromo.med.uc.edu (HELO bromo.med.uc.edu) (129.137.3.146) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 11 Feb 2012 18:01:31 +0000 Received: from bromo.med.uc.edu (localhost.localdomain [127.0.0.1]) by bromo.med.uc.edu (Postfix) with ESMTP id A141D400007; Sat, 11 Feb 2012 13:01:29 -0500 (EST) Received: (from howarth@localhost) by bromo.med.uc.edu (8.14.3/8.14.3/Submit) id q1BI1Tds011689; Sat, 11 Feb 2012 13:01:29 -0500 Date: Sat, 11 Feb 2012 13:01:29 -0500 From: Jack Howarth To: Eric Botcazou Cc: gcc-patches@gcc.gnu.org Subject: Re: [libitm] Link with -litm and -pthread Message-ID: <20120211180129.GA11655@bromo.med.uc.edu> References: <201202111514.40618.ebotcazou@adacore.com> <20120211174548.GA11595@bromo.med.uc.edu> <201202111854.06083.ebotcazou@adacore.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <201202111854.06083.ebotcazou@adacore.com> User-Agent: Mutt/1.5.18 (2008-05-17) 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 On Sat, Feb 11, 2012 at 06:54:05PM +0100, Eric Botcazou wrote: > > This change causes massive failures at -m32/-m64 on x86_64-apple-darwin11 > > in the libitm testsuite... > > How did you test it? > > -- > Eric Botcazou Eric, Applied to gcc trunk (r184130) along with the proposed fix for Bug libitm/52042... built as... Using built-in specs. COLLECT_GCC=gcc-fsf-4.7 COLLECT_LTO_WRAPPER=/sw/lib/gcc4.7/libexec/gcc/x86_64-apple-darwin11.3.0/4.7.0/lto-wrapper Target: x86_64-apple-darwin11.3.0 Configured with: ../gcc-4.7-20120211/configure --prefix=/sw --prefix=/sw/lib/gcc4.7 --mandir=/sw/share/man --infodir=/sw/lib/gcc4.7/info --with-build-config=bootstrap-lto --enable-stage1-languages=c,lto --enable-languages=c,c++,fortran,lto,objc,obj-c++,java --with-gmp=/sw --with-libiconv-prefix=/sw --with-ppl=/sw --with-cloog=/sw --with-mpc=/sw --with-system-zlib --x-includes=/usr/X11R6/include --x-libraries=/usr/X11R6/lib --program-suffix=-fsf-4.7 --enable-checking=release --enable-cloog-backend=isl Thread model: posix gcc version 4.7.0 20120211 (experimental) (GCC) then... cd darwin_objdir/x86_64-apple-darwin11.3.0/libitm make -k check RUNTESTFLAGS="--target_board=unix'{-m32,-m64}'" which is exactly how I have been testing Patrick Marlier proposed patch. Jack Index: libitm/alloc_cpp.cc =================================================================== --- libitm/alloc_cpp.cc (revision 183968) +++ libitm/alloc_cpp.cc (working copy) @@ -60,7 +60,7 @@ extern void _ZdlPvRKSt9nothrow_t (void *, c_nothro extern void *_ZnaXRKSt9nothrow_t (size_t, c_nothrow_p) __attribute__((weak)); extern void _ZdaPvRKSt9nothrow_t (void *, c_nothrow_p) __attribute__((weak)); -#if !defined (HAVE_ELF_STYLE_WEAKREF) +#if !defined (HAVE_ELF_STYLE_WEAKREF) && !defined (__MACH__) void *_ZnwX (size_t) { return NULL; } void _ZdlPv (void *) { return; } void *_ZnaX (size_t) { return NULL; } Index: libitm/eh_cpp.cc =================================================================== --- libitm/eh_cpp.cc (revision 183968) +++ libitm/eh_cpp.cc (working copy) @@ -39,7 +39,7 @@ extern void *__cxa_begin_catch (void *) WEAK; extern void *__cxa_end_catch (void) WEAK; extern void __cxa_tm_cleanup (void *, void *, unsigned int) WEAK; -#if !defined (HAVE_ELF_STYLE_WEAKREF) +#if !defined (HAVE_ELF_STYLE_WEAKREF) && !defined (__MACH__) void *__cxa_allocate_exception (size_t) { return NULL; } void __cxa_throw (void *, void *, void *) { return; } void *__cxa_begin_catch (void *) { return NULL; } Index: libgcc/config/darwin-crt-tm.c =================================================================== --- libgcc/config/darwin-crt-tm.c (revision 183968) +++ libgcc/config/darwin-crt-tm.c (working copy) @@ -23,33 +23,68 @@ a copy of the GCC Runtime Library Exception along see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . */ +#include "tsystem.h" +#include +#include #include +#include -/* not listed in mach-o/dyld.h for some reason. */ -extern char * getsectdata (const char*,const char*,unsigned long*); +#ifdef __LP64__ +#define GET_DATA_TMCT(mh,size) \ + getsectdatafromheader_64 ((struct mach_header_64*) mh, \ + "__DATA", "__tm_clone_table", (uint64_t *)size) +#else +#define GET_DATA_TMCT(mh,size) \ + getsectdatafromheader (mh, "__DATA", "__tm_clone_table", (uint32_t *)size) +#endif #define WEAK __attribute__((weak)) +#define UNUSED __attribute__((unused)) extern void _ITM_registerTMCloneTable (void *, size_t) WEAK; extern void _ITM_deregisterTMCloneTable (void *) WEAK; +#if defined(START) || defined(END) +static inline void *getTMCloneTable (const void *f, size_t *tmct_siz) +{ + char *tmct_fixed, *tmct = NULL; + unsigned int i, img_count; + struct mach_header *mh; + Dl_info info; + + if (! dladdr (f, &info) || info.dli_fbase == NULL) + abort (); + + mh = (struct mach_header *) info.dli_fbase; + tmct_fixed = GET_DATA_TMCT (mh, tmct_siz); + *tmct_siz /= (sizeof (size_t) * 2); + /* No tm_clone_table or no clones. */ + if (tmct_fixed == NULL || *tmct_siz == 0) + return NULL; + + img_count = _dyld_image_count(); + for (i = 0; i < img_count && tmct == NULL; i++) + { + if (mh == _dyld_get_image_header(i)) + tmct = tmct_fixed + (unsigned long)_dyld_get_image_vmaddr_slide(i); + } + + return tmct; +} +#endif + #ifdef START void __doTMRegistrations (void) __attribute__ ((constructor)); void __doTMRegistrations (void) { - char * tm_clone_table_sect_data; - unsigned long tmct_siz; - - tm_clone_table_sect_data = getsectdata ("__DATA", - "__tm_clone_table", - &tmct_siz); - tmct_siz /= (sizeof (size_t) * 2); - if (_ITM_registerTMCloneTable != NULL - && tm_clone_table_sect_data != NULL - && tmct_siz > 0) - _ITM_registerTMCloneTable (tm_clone_table_sect_data, (size_t)tmct_siz); + size_t tmct_siz; + void *tmct; + + tmct = getTMCloneTable ((const void *)&__doTMRegistrations, &tmct_siz); + if (_ITM_registerTMCloneTable != NULL && tmct != NULL) + _ITM_registerTMCloneTable (tmct, (size_t)tmct_siz); } #endif @@ -60,18 +95,53 @@ void __doTMdeRegistrations (void) __attribute__ (( void __doTMdeRegistrations (void) { - char * tm_clone_table_sect_data; - unsigned long tmct_siz; - - tm_clone_table_sect_data = getsectdata ("__DATA", - "__tm_clone_table", - &tmct_siz); - - if (_ITM_deregisterTMCloneTable != NULL - && tm_clone_table_sect_data != NULL - && tmct_siz > 0) - _ITM_deregisterTMCloneTable (tm_clone_table_sect_data); + size_t tmct_siz; + void *tmct; + tmct = getTMCloneTable ((const void *)&__doTMdeRegistrations, &tmct_siz); + if (_ITM_deregisterTMCloneTable != NULL && tmct != NULL) + _ITM_deregisterTMCloneTable (tmct); } +/* Provide dummy functions to satisfy linkage for versions of the Darwin tool-chain that + that can't handle undefined weak refs at the link stage. */ + +extern void *__cxa_allocate_exception (size_t) WEAK; +extern void __cxa_throw (void *, void *, void *) WEAK; +extern void *__cxa_begin_catch (void *) WEAK; +extern void *__cxa_end_catch (void) WEAK; +extern void __cxa_tm_cleanup (void *, void *, unsigned int) WEAK; + +void *__cxa_allocate_exception (size_t s UNUSED) { return NULL; } +void __cxa_throw (void * a UNUSED, void * b UNUSED, void * c UNUSED) +{ return; } +void *__cxa_begin_catch (void * a UNUSED) { return NULL; } +void *__cxa_end_catch (void) { return NULL; } +void __cxa_tm_cleanup (void * a UNUSED, void * b UNUSED, unsigned int c UNUSED) +{ return; } + +extern void *_ZnwX (size_t) WEAK; +extern void _ZdlPv (void *) WEAK; +extern void *_ZnaX (size_t) WEAK; +extern void _ZdaPv (void *) WEAK; + +typedef const struct nothrow_t { } *c_nothrow_p; + +extern void *_ZnwXRKSt9nothrow_t (size_t, c_nothrow_p) WEAK; +extern void _ZdlPvRKSt9nothrow_t (void *, c_nothrow_p) WEAK; +extern void *_ZnaXRKSt9nothrow_t (size_t, c_nothrow_p) WEAK; +extern void _ZdaPvRKSt9nothrow_t (void *, c_nothrow_p) WEAK; + +void *_ZnwX (size_t s UNUSED) { return NULL; } +void _ZdlPv (void * a UNUSED) { return; } +void *_ZnaX (size_t s UNUSED) { return NULL; } +void _ZdaPv (void * a UNUSED) { return; } + +void *_ZnwXRKSt9nothrow_t (size_t s UNUSED, c_nothrow_p b UNUSED) + { return NULL; } +void _ZdlPvRKSt9nothrow_t (void * a UNUSED, c_nothrow_p b UNUSED) { return; } +void *_ZnaXRKSt9nothrow_t (size_t s UNUSED, c_nothrow_p b UNUSED) + { return NULL; } +void _ZdaPvRKSt9nothrow_t (void * a UNUSED, c_nothrow_p b UNUSED) { return; } + #endif