]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/darwin-crt-tm.c
libitm/
[thirdparty/gcc.git] / libgcc / config / darwin-crt-tm.c
CommitLineData
00b708da 1/* Provide the runtime infrastructure for the transactional memory lib.
8f8ba4fc 2 Copyright (C) 2011 Free Software Foundation, Inc.
3 Contributed by Iain Sandoe <iains@gcc.gnu.org>
4
5 This file is part of GCC.
6
00b708da 7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9Software Foundation; either version 3, or (at your option) any later
10version.
8f8ba4fc 11
00b708da 12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
8f8ba4fc 16
00b708da 17Under Section 7 of GPL version 3, you are granted additional
18permissions described in the GCC Runtime Library Exception, version
193.1, as published by the Free Software Foundation.
20
21You should have received a copy of the GNU General Public License and
22a copy of the GCC Runtime Library Exception along with this program;
23see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
8f8ba4fc 24<http://www.gnu.org/licenses/>. */
25
621d0dd2 26#include "tsystem.h"
27#include <stddef.h>
28#include <dlfcn.h>
8f8ba4fc 29#include <mach-o/dyld.h>
621d0dd2 30#include <mach-o/getsect.h>
31
32#ifdef __LP64__
33#define GET_DATA_TMCT(mh,size) \
34 getsectdatafromheader_64 ((struct mach_header_64*) mh, \
35 "__DATA", "__tm_clone_table", (uint64_t *)size)
36#else
37#define GET_DATA_TMCT(mh,size) \
38 getsectdatafromheader (mh, "__DATA", "__tm_clone_table", (uint32_t *)size)
39#endif
8f8ba4fc 40
41#define WEAK __attribute__((weak))
b8f45854 42#define UNUSED __attribute__((unused))
8f8ba4fc 43
8f8ba4fc 44extern void _ITM_registerTMCloneTable (void *, size_t) WEAK;
45extern void _ITM_deregisterTMCloneTable (void *) WEAK;
46
621d0dd2 47#if defined(START) || defined(END)
48static inline void *getTMCloneTable (const void *f, size_t *tmct_siz)
49{
50 char *tmct_fixed, *tmct = NULL;
51 unsigned int i, img_count;
52 struct mach_header *mh;
53 Dl_info info;
54
55 if (! dladdr (f, &info) || info.dli_fbase == NULL)
56 abort ();
57
58 mh = (struct mach_header *) info.dli_fbase;
59 tmct_fixed = GET_DATA_TMCT (mh, tmct_siz);
60 *tmct_siz /= (sizeof (size_t) * 2);
61 /* No tm_clone_table or no clones. */
62 if (tmct_fixed == NULL || *tmct_siz == 0)
63 return NULL;
64
65 img_count = _dyld_image_count();
66 for (i = 0; i < img_count && tmct == NULL; i++)
67 {
68 if (mh == _dyld_get_image_header(i))
69 tmct = tmct_fixed + (unsigned long)_dyld_get_image_vmaddr_slide(i);
70 }
71
72 return tmct;
73}
74#endif
75
8f8ba4fc 76#ifdef START
77
78void __doTMRegistrations (void) __attribute__ ((constructor));
79
80void __doTMRegistrations (void)
81{
621d0dd2 82 size_t tmct_siz;
83 void *tmct;
84
85 tmct = getTMCloneTable ((const void *)&__doTMRegistrations, &tmct_siz);
86 if (_ITM_registerTMCloneTable != NULL && tmct != NULL)
87 _ITM_registerTMCloneTable (tmct, (size_t)tmct_siz);
8f8ba4fc 88}
89
90#endif
91
92#ifdef END
93
94void __doTMdeRegistrations (void) __attribute__ ((destructor));
95
96void __doTMdeRegistrations (void)
97{
621d0dd2 98 size_t tmct_siz;
99 void *tmct;
8f8ba4fc 100
621d0dd2 101 tmct = getTMCloneTable ((const void *)&__doTMdeRegistrations, &tmct_siz);
102 if (_ITM_deregisterTMCloneTable != NULL && tmct != NULL)
103 _ITM_deregisterTMCloneTable (tmct);
8f8ba4fc 104}
105
8f8ba4fc 106#endif
b8f45854 107
108/* Provide dummy functions to satisfy linkage for versions of the Darwin
109 tool-chain that that can't handle undefined weak refs at the link stage.
110 ??? Define these dummy functions only when !HAVE_ELF_STYLE_WEAKREF. */
111
112extern void *__cxa_allocate_exception (size_t) WEAK;
113extern void __cxa_throw (void *, void *, void *) WEAK;
114extern void *__cxa_begin_catch (void *) WEAK;
115extern void *__cxa_end_catch (void) WEAK;
116extern void __cxa_tm_cleanup (void *, void *, unsigned int) WEAK;
117
118extern void *_ZnwX (size_t) WEAK;
119extern void _ZdlPv (void *) WEAK;
120extern void *_ZnaX (size_t) WEAK;
121extern void _ZdaPv (void *) WEAK;
122
123typedef const struct nothrow_t { } *c_nothrow_p;
124
125extern void *_ZnwXRKSt9nothrow_t (size_t, c_nothrow_p) WEAK;
126extern void _ZdlPvRKSt9nothrow_t (void *, c_nothrow_p) WEAK;
127extern void *_ZnaXRKSt9nothrow_t (size_t, c_nothrow_p) WEAK;
128extern void _ZdaPvRKSt9nothrow_t (void *, c_nothrow_p) WEAK;
129
130void *__cxa_allocate_exception (size_t s UNUSED) { return NULL; }
131void __cxa_throw (void * a UNUSED, void * b UNUSED, void * c UNUSED)
132 { return; }
133void *__cxa_begin_catch (void * a UNUSED) { return NULL; }
134void *__cxa_end_catch (void) { return NULL; }
135void __cxa_tm_cleanup (void * a UNUSED, void * b UNUSED, unsigned int c UNUSED)
136 { return; }
137
138void *_ZnwX (size_t s UNUSED) { return NULL; }
139void _ZdlPv (void * a UNUSED) { return; }
140void *_ZnaX (size_t s UNUSED) { return NULL; }
141void _ZdaPv (void * a UNUSED) { return; }
142
143void *_ZnwXRKSt9nothrow_t (size_t s UNUSED, c_nothrow_p b UNUSED)
144 { return NULL; }
145void _ZdlPvRKSt9nothrow_t (void * a UNUSED, c_nothrow_p b UNUSED) { return; }
146void *_ZnaXRKSt9nothrow_t (size_t s UNUSED, c_nothrow_p b UNUSED)
147 { return NULL; }
148void _ZdaPvRKSt9nothrow_t (void * a UNUSED, c_nothrow_p b UNUSED) { return; }
149