From patchwork Tue Nov 22 13:57:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 127078 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 2B5351007D1 for ; Wed, 23 Nov 2011 00:57:28 +1100 (EST) Received: (qmail 7979 invoked by alias); 22 Nov 2011 13:57:25 -0000 Received: (qmail 7967 invoked by uid 22791); 22 Nov 2011 13:57:24 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from c2bthomr13.btconnect.com (HELO mail.btconnect.com) (213.123.20.131) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 22 Nov 2011 13:57:09 +0000 Received: from host81-138-1-83.in-addr.btopenworld.com (EHLO thor.office) ([81.138.1.83]) by c2bthomr13.btconnect.com with ESMTP id FGG79411; Tue, 22 Nov 2011 13:57:06 +0000 (GMT) Cc: GCC Patches Message-Id: From: Iain Sandoe To: Mike Stump In-Reply-To: <4ECA9E53.7020509@redhat.com> Mime-Version: 1.0 (Apple Message framework v936) Subject: Re: [Patch RFC Darwin] provide the crt stuff for tm. Date: Tue, 22 Nov 2011 13:57:05 +0000 References: <576CABB2-597C-4C7B-BE4C-DF03B57E6DF7@sandoe-acoustics.co.uk> <4EC9977F.8020309@redhat.com> <20A02D67-EC83-4CE6-82E0-6BF1BC0EE6CE@sandoe-acoustics.co.uk> <4ECA9E53.7020509@redhat.com> X-Mirapoint-IP-Reputation: reputation=Good-1, source=Queried, refid=tid=0001.0A0B0301.4ECBAA05.00A4, actions=tag X-Junkmail-Premium-Raw: score=7/50, refid=2.7.2:2011.11.22.114815:17:7.763, ip=81.138.1.83, rules=__HAS_MSGID, __SANE_MSGID, __MSGID_APPLEMAIL, __TO_MALFORMED_2, __CT, __CTYPE_HAS_BOUNDARY, __CTYPE_MULTIPART, CTYPE_MULTIPART_NO_QUOTE, __CTYPE_MULTIPART_MIXED, __MIME_VERSION, __MIME_VERSION_APPLEMAIL, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __HAS_X_MAILER, __X_MAILER_APPLEMAIL, TXT_ATTACHED, __ANY_URI, __CP_MEDIA_BODY, __CP_URI_IN_BODY, BODYTEXTP_SIZE_3000_LESS, __MIME_TEXT_ONLY, RDNS_GENERIC_POOLED, RDNS_SUSP_GENERIC, __USER_AGENT_APPLEMAIL, RDNS_SUSP, MIME_TEXT_ONLY_MP_MIXED X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A0B0201.4ECBAA33.00BC, ss=1, fgs=0, ip=0.0.0.0, so=2010-07-22 22:03:31, dmn=2009-09-10 00:05:08, mode=multiengine 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 On 21 Nov 2011, at 18:54, Richard Henderson wrote: > On 11/21/2011 01:17 AM, Iain Sandoe wrote: >> 1. should I be applying this constructor/destructor pair to shared >> libraries as well? >> (the specs need minor amendment) > > Yes. this is what I applied (r181616)after checking that dylibs, bundles and executables get the c/dtors added (only when -fgnu-tm is given, so we don't add them for everything). I don't have any test-cases to prove that anything other than a plain executable works - this is a TODO once the basic facility is working. Iain Index: libgcc/config.host =================================================================== --- libgcc/config.host (revision 181614) +++ libgcc/config.host (working copy) @@ -170,7 +170,7 @@ case ${host} in *-*-darwin*) asm_hidden_op=.private_extern tmake_file="$tmake_file t-darwin ${cpu_type}/t-darwin t-libgcc-pic t-slibgcc-darwin" - extra_parts=crt3.o + extra_parts="crt3.o crttms.o crttme.o" ;; *-*-freebsd*) # This is the generic ELF configuration of FreeBSD. Later Index: libgcc/config/t-darwin =================================================================== --- libgcc/config/t-darwin (revision 181614) +++ libgcc/config/t-darwin (working copy) @@ -3,6 +3,12 @@ crt3.o: $(srcdir)/config/darwin-crt3.c $(crt_compile) \ -fno-tree-dominator-opts $(DARWIN_EXTRA_CRT_BUILD_CFLAGS) -c $< +crttms.o: $(srcdir)/config/darwin-crt-tm.c + $(crt_compile) $(DARWIN_EXTRA_CRT_BUILD_CFLAGS) -DSTART -c $< + +crttme.o: $(srcdir)/config/darwin-crt-tm.c + $(crt_compile) $(DARWIN_EXTRA_CRT_BUILD_CFLAGS) -DEND -c $< + # -pipe because there's an assembler bug, 4077127, which causes # it to not properly process the first # directive, causing temporary # file names to appear in stabs, causing the bootstrap to fail. Using -pipe Index: libgcc/config/darwin-crt-tm.c =================================================================== --- libgcc/config/darwin-crt-tm.c (revision 0) +++ libgcc/config/darwin-crt-tm.c (revision 0) @@ -0,0 +1,83 @@ +/* Provide the runtime intrastructure the transactional memory lib. + Copyright (C) 2011 Free Software Foundation, Inc. + Contributed by Iain Sandoe + + This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3, or (at your option) +any later version. + +GCC is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING3. If not see +. */ + +#include + +/* not listed in mach-o/dyld.h for some reason. */ +extern char * getsectdata (const char*,const char*,unsigned long*); + +#define WEAK __attribute__((weak)) + +#ifndef ATTRIBUTE_UNUSED +#define ATTRIBUTE_UNUSED __attribute__((unused)) +#endif + +extern void _ITM_registerTMCloneTable (void *, size_t) WEAK; +extern void _ITM_deregisterTMCloneTable (void *) WEAK; + +#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); +} + +#endif + +#ifdef END + +void __doTMdeRegistrations (void) __attribute__ ((destructor)); + +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); + +} + +/* Provide dumy funcs for the weak ones - needed on most Darwin versions + for now. */ + +void _ITM_registerTMCloneTable (void *n ATTRIBUTE_UNUSED, size_t s ATTRIBUTE_UNUSED) +{} +void _ITM_deregisterTMCloneTable (void *n ATTRIBUTE_UNUSED) +{} +#endif Index: gcc/config/i386/darwin.h =================================================================== --- gcc/config/i386/darwin.h (revision 181614) +++ gcc/config/i386/darwin.h (working copy) @@ -132,7 +132,8 @@ extern int darwin_emit_branch_islands; "%{Ofast|ffast-math|funsafe-math-optimizations:crtfastmath.o%s} \ %{mpc32:crtprec32.o%s} \ %{mpc64:crtprec64.o%s} \ - %{mpc80:crtprec80.o%s}" + %{mpc80:crtprec80.o%s} \ + %{fgnu-tm: -lcrttme.o}" #undef SUBTARGET_EXTRA_SPECS #define SUBTARGET_EXTRA_SPECS \ Index: gcc/config/darwin.h =================================================================== --- gcc/config/darwin.h (revision 181614) +++ gcc/config/darwin.h (working copy) @@ -359,8 +359,8 @@ extern GTY(()) int darwin_ms_struct; #undef STARTFILE_SPEC #define STARTFILE_SPEC \ - "%{Zdynamiclib: %(darwin_dylib1) } \ - %{!Zdynamiclib:%{Zbundle:%{!static:-lbundle1.o}} \ + "%{Zdynamiclib: %(darwin_dylib1) %{fgnu-tm: -lcrttms.o}} \ + %{!Zdynamiclib:%{Zbundle:%{!static:-lbundle1.o %{fgnu-tm: -lcrttms.o}}} \ %{!Zbundle:%{pg:%{static:-lgcrt0.o} \ %{!static:%{object:-lgcrt0.o} \ %{!object:%{preload:-lgcrt0.o} \ @@ -372,10 +372,8 @@ extern GTY(()) int darwin_ms_struct; %(darwin_crt2)}}}}}} \ %{shared-libgcc:%:version-compare(< 10.5 mmacosx-version-min= crt3.o%s)}" -/* The native Darwin linker doesn't necessarily place files in the order - that they're specified on the link line. Thus, it is pointless - to put anything in ENDFILE_SPEC. */ -/* #define ENDFILE_SPEC "" */ +/* We want a destructor last in the list. */ +#define ENDFILE_SPEC "%{fgnu-tm: -lcrttme.o}" #define DARWIN_EXTRA_SPECS \ { "darwin_crt1", DARWIN_CRT1_SPEC }, \ @@ -388,7 +386,8 @@ extern GTY(()) int darwin_ms_struct; #define DARWIN_CRT1_SPEC \ "%:version-compare(!> 10.5 mmacosx-version-min= -lcrt1.o) \ - %:version-compare(>= 10.5 mmacosx-version-min= -lcrt1.10.5.o)" + %:version-compare(>= 10.5 mmacosx-version-min= -lcrt1.10.5.o) \ + %{fgnu-tm: -lcrttms.o}" /* Default Darwin ASM_SPEC, very simple. */ #define ASM_SPEC "-arch %(darwin_arch) \