libgcc/config/darwin-crt-tm.c | 96 ++++++++++++++++++++++++++++++-----------
libgcc/config/t-darwin | 3 +
libitm/eh_cpp.cc | 2 +-
3 files changed, 75 insertions(+), 26 deletions(-)
diff --git a/libgcc/config/darwin-crt-tm.c b/libgcc/config/darwin-crt-tm.c
index 2311337..380767b 100644
--- a/libgcc/config/darwin-crt-tm.c
+++ b/libgcc/config/darwin-crt-tm.c
@@ -23,33 +23,68 @@ a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
. */
+#include "tsystem.h"
+#include
+#include
#include
-
-/* not listed in mach-o/dyld.h for some reason. */
-extern char * getsectdata (const char*,const char*,unsigned long*);
+#include
+
+#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,29 @@ 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);
+ 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; }
+
#endif
diff --git a/libitm/eh_cpp.cc b/libitm/eh_cpp.cc
index 352a313..4dd97bf 100644
--- a/libitm/eh_cpp.cc
+++ b/libitm/eh_cpp.cc
@@ -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; }