From patchwork Thu Feb 9 13:54:14 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Marlier X-Patchwork-Id: 140381 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 9EAD0B6F62 for ; Fri, 10 Feb 2012 00:54:38 +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=1329400479; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC: Subject:References:In-Reply-To:Content-Type:Mailing-List: Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:Sender:Delivered-To; bh=NTLRBSqXKBySRyLYqu8HC2Dxzlg=; b=ezrEeRUUj+sl6ykunulzBPGP/gBv2TLwbUtX81XkrfARoKKCym83jPbpSoacJL gPu0BBkPfihuyRI72kiI2US7bZFLnSyZEInXtgjrHsC38Dx3QSsZ60braAtzCCxc 1BL6+lqJC9hZCbON/86d+wfTm5Cg+dCyUT5MQa8/dDJ4I= 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:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=w90eZWpKs+GODzVqo3RocaYC2ATGaOQRSXSkwiI3Y9defa1XLvgnKfSOATR5B5 f0i/kW8CbPgAf8pfeFe0zAf19m5tVMovaUX8P6hTdiPCF/Jl6rLtxNZ+k2DYZ4UZ 0jT70SAHXCz/dw3eG1cx4dRoQ6qV95iqjoJbYGVInLTVY=; Received: (qmail 5102 invoked by alias); 9 Feb 2012 13:54:35 -0000 Received: (qmail 5083 invoked by uid 22791); 9 Feb 2012 13:54:33 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, TW_CX X-Spam-Check-By: sourceware.org Received: from mail-qy0-f175.google.com (HELO mail-qy0-f175.google.com) (209.85.216.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 09 Feb 2012 13:54:18 +0000 Received: by qcso7 with SMTP id o7so976138qcs.20 for ; Thu, 09 Feb 2012 05:54:17 -0800 (PST) Received: by 10.229.105.159 with SMTP id t31mr1270269qco.57.1328795657852; Thu, 09 Feb 2012 05:54:17 -0800 (PST) Received: from [192.168.2.2] (cpe-69-207-95-157.rochester.res.rr.com. [69.207.95.157]) by mx.google.com with ESMTPS id hk9sm5855676qab.20.2012.02.09.05.54.15 (version=SSLv3 cipher=OTHER); Thu, 09 Feb 2012 05:54:16 -0800 (PST) Message-ID: <4F33D006.6020708@gmail.com> Date: Thu, 09 Feb 2012 08:54:14 -0500 From: Patrick Marlier User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111229 Thunderbird/9.0 MIME-Version: 1.0 To: Iain Sandoe CC: Jack Howarth , gcc-patches Patches , Mike Stump , Rainer Orth Subject: Re: [trans-mem,darwin] PR/52042 find tm_clone_table with PIE References: <4F31EDC9.2060600@gmail.com> <20120208051249.GA31393@bromo.med.uc.edu> <4F335558.40502@gmail.com> In-Reply-To: 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 Hi Iain, On 02/09/2012 07:26 AM, Iain Sandoe wrote: > apologies for > (a) the extra loop - I missed a deprecation warning when I built your > last version ... Thanks! Actually, I saw the depreciation but I didn't found that dladdr. > (b) rolling two things into one mail ... > ... (point 1 is related the pie issue, point 2 to linkage hassles). > > On 9 Feb 2012, at 08:36, Iain Sandoe wrote: >>> >>> I think refs (from libstdc++) should be satisfied at link time with >>> -lstdc++ but probably I am missing something? >> >> when you link c++ code, that is what is required .. but obv. we don't >> want lstdc++ on the link line for c (because the library *will* be >> found @ runtime - and thus the routines would be called). >> >> I have an idea ... perhaps we supply (yet another) crt that is linked >> last on the line and provides the dummies. That way the linkage will >> be satisfied from libstd++ for c++ and the dummies for c. >> >> will try and see if I can fit a trial of that idea in on D9 & D10. Thanks for the explanation. > Point 2 below... now I look at this again, I wonder why the current > scheme doesn't cause a problem for Rainer on c++ as well? Yep, this confuses me too. > 2/ I've moved the dummy routines to the [Darwin] tm crt endfile .. > > +/* 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; } > + Note you should also do the same for alloc_cpp.cc: #if !defined (HAVE_ELF_STYLE_WEAKREF) void *_ZnwX (size_t) { return NULL; } void _ZdlPv (void *) { return; } void *_ZnaX (size_t) { return NULL; } void _ZdaPv (void *) { return; } void *_ZnwXRKSt9nothrow_t (size_t, c_nothrow_p) { return NULL; } void _ZdlPvRKSt9nothrow_t (void *, c_nothrow_p) { return; } void *_ZnaXRKSt9nothrow_t (size_t, c_nothrow_p) { return NULL; } void _ZdaPvRKSt9nothrow_t (void *, c_nothrow_p) { return; } #endif /* HAVE_ELF_STYLE_WEAKREF */ Native configuration is x86_64-apple-darwin10.8.0 === libitm tests === Schedule of variations: unix Running target unix Using /usr/local/share/dejagnu/baseboards/unix.exp as board description file for target. Using /usr/local/share/dejagnu/config/unix.exp as generic interface file for target. Using /Users/patrick/gcc/trunk/libitm/testsuite/config/default.exp as tool-and-target-specific interface file. Running /Users/patrick/gcc/trunk/libitm/testsuite/libitm.c/c.exp ... Running /Users/patrick/gcc/trunk/libitm/testsuite/libitm.c++/c++.exp ... === libitm Summary === # of expected passes 26 # of expected failures 3 # of unsupported tests 1 Tested with XCode 4.0. I do not have any darwin 11. Thanks. --- Patrick. 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