annotate libgcc/config/darwin-crt-tm.c @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Provide the runtime infrastructure for the transactional memory lib.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 Copyright (C) 2011-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3 Contributed by Iain Sandoe <iains@gcc.gnu.org>
kono
parents:
diff changeset
4
kono
parents:
diff changeset
5 This file is part of GCC.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 GCC is free software; you can redistribute it and/or modify it under
kono
parents:
diff changeset
8 the terms of the GNU General Public License as published by the Free
kono
parents:
diff changeset
9 Software Foundation; either version 3, or (at your option) any later
kono
parents:
diff changeset
10 version.
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
kono
parents:
diff changeset
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
kono
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
kono
parents:
diff changeset
15 for more details.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 Under Section 7 of GPL version 3, you are granted additional
kono
parents:
diff changeset
18 permissions described in the GCC Runtime Library Exception, version
kono
parents:
diff changeset
19 3.1, as published by the Free Software Foundation.
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 You should have received a copy of the GNU General Public License and
kono
parents:
diff changeset
22 a copy of the GCC Runtime Library Exception along with this program;
kono
parents:
diff changeset
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
kono
parents:
diff changeset
24 <http://www.gnu.org/licenses/>. */
kono
parents:
diff changeset
25
kono
parents:
diff changeset
26 #include "tsystem.h"
kono
parents:
diff changeset
27 #include <stddef.h>
kono
parents:
diff changeset
28 #include <dlfcn.h>
kono
parents:
diff changeset
29 #include <mach-o/dyld.h>
kono
parents:
diff changeset
30 #include <mach-o/getsect.h>
kono
parents:
diff changeset
31
kono
parents:
diff changeset
32 #ifdef __LP64__
kono
parents:
diff changeset
33 #define GET_DATA_TMCT(mh,size) \
kono
parents:
diff changeset
34 getsectdatafromheader_64 ((struct mach_header_64*) mh, \
kono
parents:
diff changeset
35 "__DATA", "__tm_clone_table", (uint64_t *)size)
kono
parents:
diff changeset
36 #else
kono
parents:
diff changeset
37 #define GET_DATA_TMCT(mh,size) \
kono
parents:
diff changeset
38 getsectdatafromheader (mh, "__DATA", "__tm_clone_table", (uint32_t *)size)
kono
parents:
diff changeset
39 #endif
kono
parents:
diff changeset
40
kono
parents:
diff changeset
41 #define WEAK __attribute__((weak))
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 extern void _ITM_registerTMCloneTable (void *, size_t) WEAK;
kono
parents:
diff changeset
44 extern void _ITM_deregisterTMCloneTable (void *) WEAK;
kono
parents:
diff changeset
45
kono
parents:
diff changeset
46 #if defined(START) || defined(END)
kono
parents:
diff changeset
47 static inline void *getTMCloneTable (const void *f, size_t *tmct_siz)
kono
parents:
diff changeset
48 {
kono
parents:
diff changeset
49 char *tmct_fixed, *tmct = NULL;
kono
parents:
diff changeset
50 unsigned int i, img_count;
kono
parents:
diff changeset
51 struct mach_header *mh;
kono
parents:
diff changeset
52 Dl_info info;
kono
parents:
diff changeset
53
kono
parents:
diff changeset
54 if (! dladdr (f, &info) || info.dli_fbase == NULL)
kono
parents:
diff changeset
55 abort ();
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 mh = (struct mach_header *) info.dli_fbase;
kono
parents:
diff changeset
58 tmct_fixed = GET_DATA_TMCT (mh, tmct_siz);
kono
parents:
diff changeset
59 *tmct_siz /= (sizeof (size_t) * 2);
kono
parents:
diff changeset
60 /* No tm_clone_table or no clones. */
kono
parents:
diff changeset
61 if (tmct_fixed == NULL || *tmct_siz == 0)
kono
parents:
diff changeset
62 return NULL;
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 img_count = _dyld_image_count();
kono
parents:
diff changeset
65 for (i = 0; i < img_count && tmct == NULL; i++)
kono
parents:
diff changeset
66 {
kono
parents:
diff changeset
67 if (mh == _dyld_get_image_header(i))
kono
parents:
diff changeset
68 tmct = tmct_fixed + (unsigned long)_dyld_get_image_vmaddr_slide(i);
kono
parents:
diff changeset
69 }
kono
parents:
diff changeset
70
kono
parents:
diff changeset
71 return tmct;
kono
parents:
diff changeset
72 }
kono
parents:
diff changeset
73 #endif
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75 #ifdef START
kono
parents:
diff changeset
76
kono
parents:
diff changeset
77 void __doTMRegistrations (void) __attribute__ ((constructor));
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 void __doTMRegistrations (void)
kono
parents:
diff changeset
80 {
kono
parents:
diff changeset
81 size_t tmct_siz;
kono
parents:
diff changeset
82 void *tmct;
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 tmct = getTMCloneTable ((const void *)&__doTMRegistrations, &tmct_siz);
kono
parents:
diff changeset
85 if (_ITM_registerTMCloneTable != NULL && tmct != NULL)
kono
parents:
diff changeset
86 _ITM_registerTMCloneTable (tmct, (size_t)tmct_siz);
kono
parents:
diff changeset
87 }
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 #endif
kono
parents:
diff changeset
90
kono
parents:
diff changeset
91 #ifdef END
kono
parents:
diff changeset
92
kono
parents:
diff changeset
93 void __doTMdeRegistrations (void) __attribute__ ((destructor));
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 void __doTMdeRegistrations (void)
kono
parents:
diff changeset
96 {
kono
parents:
diff changeset
97 size_t tmct_siz;
kono
parents:
diff changeset
98 void *tmct;
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 tmct = getTMCloneTable ((const void *)&__doTMdeRegistrations, &tmct_siz);
kono
parents:
diff changeset
101 if (_ITM_deregisterTMCloneTable != NULL && tmct != NULL)
kono
parents:
diff changeset
102 _ITM_deregisterTMCloneTable (tmct);
kono
parents:
diff changeset
103 }
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 #endif