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 */
 
 }
 
