From patchwork Mon Nov 21 15:17:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 126818 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 0C6B4B7211 for ; Tue, 22 Nov 2011 02:19:01 +1100 (EST) Received: (qmail 5386 invoked by alias); 21 Nov 2011 15:18:57 -0000 Received: (qmail 5373 invoked by uid 22791); 21 Nov 2011 15:18:56 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, TW_CX X-Spam-Check-By: sourceware.org Received: from c2beaomr10.btconnect.com (HELO mail.btconnect.com) (213.123.26.188) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 21 Nov 2011 15:17:57 +0000 Received: from host81-138-1-83.in-addr.btopenworld.com (EHLO thor.office) ([81.138.1.83]) by c2beaomr10.btconnect.com with ESMTP id FEM95239; Mon, 21 Nov 2011 15:17:55 +0000 (GMT) Message-Id: From: Iain Sandoe To: GCC Patches Mime-Version: 1.0 (Apple Message framework v936) Subject: [Patch libitm] [V2] config-based assessment of weakref capability Date: Mon, 21 Nov 2011 15:17:54 +0000 Cc: Richard Henderson , Mike Stump , Rainer Orth X-Mirapoint-IP-Reputation: reputation=Fair-1, source=Queried, refid=tid=0001.0A0B0302.4ECA6BA2.009C, actions=tag X-Junkmail-Premium-Raw: score=8/50, refid=2.7.2:2011.11.21.140915:17:8.510, 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, __SUBJ_ALPHA_END, __MULTIPLE_RCPTS_CC_X2, __HAS_X_MAILER, __X_MAILER_APPLEMAIL, TXT_ATTACHED, __ANY_URI, __URI_NO_MAILTO, __URI_NO_WWW, __CP_URI_IN_BODY, BODY_PARA_IS_SENTENCE_URL, BODYTEXTP_SIZE_3000_LESS, BODY_SIZE_6000_6999, __MIME_TEXT_ONLY, RDNS_GENERIC_POOLED, RDNS_SUSP_GENERIC, __USER_AGENT_APPLEMAIL, RDNS_SUSP, BODY_SIZE_7000_LESS, MIME_TEXT_ONLY_MP_MIXED, MULTIPLE_RCPTS X-Junkmail-Signature-Raw: score=unknown, refid=str=0001.0A0B020C.4ECA6BA4.0064, 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 Hello All, This is the last piece needed to get libitm working on Darwin. --- It is take 2 on auto-configury for weakrefs in libitm. It takes into account the comments made by Rainer (and follow-up) on: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg01898.html * moves the checking functions to config/weakref.m4 * tries to make it clear that we are checking for a specific weakref behavior. -=- If it is preferred that libitm should stand alone - then it would be easy to cut the relevant part of weakref.m4 back into libitm/ acinclude.m4. This checked to DTRT on i686-darwin9 (weak ref doesn't behave like ELF's) and x86-64-darwin10/XCode 3.2.5 (weak ref behaves as per ELF). It is my understanding from some off-list discussion reported with the ld64 engineer - - that Darwin >= 10 should, in principle, support ELF-style weak refs (as well as the two-level and flat_namespace versions). comments/OK for trunk? Iain config: * weakref.m4: New file. libitm: * configure.ac: Use GCC_CHECK_ELF_STYLE_WEAKREF. * alloc_cpp.cc: Generate dummy functions if we don't HAVE_ELF_STYLE_WEAKREF. * eh_cpp.cc: Likewise. * configure: Regenerate. * aclocal.m4: Likewise. * config.h.in: Likewise. Index: config/weakref.m4 =================================================================== --- config/weakref.m4 (revision 0) +++ config/weakref.m4 (revision 0) @@ -0,0 +1,48 @@ + +dnl Check if the target supports weak. +AC_DEFUN([GCC_CHECK_ATTRIBUTE_WEAK], [ + AC_CACHE_CHECK([whether the target supports weak], + ac_cv_have_attribute_weak, [ + weakref_m4_saved_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Werror" + AC_TRY_COMPILE([void __attribute__((weak)) foo(void) { }], + [], ac_cv_have_attribute_weak=yes, + ac_cv_have_attribute_weak=no) + CFLAGS="$weakref_m4_saved_CFLAGS"]) + if test $ac_cv_have_attribute_weak = yes; then + AC_DEFINE(HAVE_ATTRIBUTE_WEAK, 1, + [Define to 1 if the target supports __attribute__((weak)).]) + fi]) + +dnl Check whether weak refs work like the ELF ones. +dnl This means that the weak reference works without having to satify +dnl linkage for the item. +dnl There are targets (at least Darwin) where we have fully functional +dnl weakrefs at runtime, but must supply the referenced item at link time. +AC_DEFUN([GCC_CHECK_ELF_STYLE_WEAKREF], [ + AC_CACHE_CHECK([whether weak refs work like ELF], + ac_cv_have_elf_style_weakref, [ + weakref_m4_saved_CFLAGS="$CFLAGS" + case "${host}" in + *-apple-darwin*) CFLAGS="$CFLAGS -Wl,-undefined,dynamic_lookup" ;; + *) ;; + esac + AC_RUN_IFELSE([AC_LANG_SOURCE([[ +extern void fNotToBeFound(void) __attribute__((weak)); +int main () +{ + if (fNotToBeFound) + return 1; + else + return 0; +} +]])], ac_cv_have_elf_style_weakref=yes, ac_cv_have_elf_style_weakref=no, [ +case "${host}" in + alpha*-dec-osf*) ac_cv_have_elf_style_weakref=no ;; + *-apple-darwin[[89]]*) ac_cv_have_elf_style_weakref=no ;; + *) ac_cv_have_elf_style_weakref=yes;; +esac])CFLAGS="$weakref_m4_saved_CFLAGS"]) +if test x"$ac_cv_have_elf_style_weakref" = xyes; then + AC_DEFINE(HAVE_ELF_STYLE_WEAKREF, 1, [Define to 1 if target has a weakref that works like the ELF one.]) +fi]) + Index: libitm/configure.ac =================================================================== --- libitm/configure.ac (revision 181573) +++ libitm/configure.ac (working copy) @@ -239,6 +239,8 @@ LIBITM_CHECK_SYNC_BUILTINS LIBITM_CHECK_64BIT_SYNC_BUILTINS LIBITM_CHECK_AS_AVX +GCC_CHECK_ELF_STYLE_WEAKREF + # Cleanup and exit. CFLAGS="$save_CFLAGS" AC_CACHE_SAVE Index: libitm/alloc_cpp.cc =================================================================== --- libitm/alloc_cpp.cc (revision 181573) +++ 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)); -#ifdef __osf__ /* Really: !HAVE_WEAKDEF */ +#if !defined (HAVE_ELF_STYLE_WEAKREF) void *_ZnwX (size_t) { return NULL; } void _ZdlPv (void *) { return; } void *_ZnaX (size_t) { return NULL; } @@ -70,7 +70,7 @@ void *_ZnwXRKSt9nothrow_t (size_t, c_nothrow_p) { 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 /* __osf__ */ +#endif /* HAVE_ELF_STYLE_WEAKREF */ /* Wrap the delete nothrow symbols for usage with a single argument. Perhaps should have a configure type check for this, because the Index: libitm/eh_cpp.cc =================================================================== --- libitm/eh_cpp.cc (revision 181573) +++ libitm/eh_cpp.cc (working copy) @@ -39,13 +39,13 @@ extern void *__cxa_begin_catch (void *) WEAK; extern void *__cxa_end_catch (void) WEAK; extern void __cxa_tm_cleanup (void *, void *, unsigned int) WEAK; -#ifdef __osf__ /* Really: !HAVE_WEAKDEF */ +#if !defined (HAVE_ELF_STYLE_WEAKREF) void *__cxa_allocate_exception (size_t) { return NULL; } void __cxa_throw (void *, void *, void *) { return; } void *__cxa_begin_catch (void *) { return NULL; } void *__cxa_end_catch (void) { return NULL; } void __cxa_tm_cleanup (void *, void *, unsigned int) { return; } -#endif +#endif /* HAVE_ELF_STYLE_WEAKREF */ }