PR rtl-optimization/83699
[official-gcc.git] / libitm / alloc_cpp.cc
blob4bbf077f2ad606d10d7e905f521eca6385b6e16d
1 /* Copyright (C) 2009-2018 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Transactional Memory Library (libitm).
6 Libitm is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #include "libitm_i.h"
27 using namespace GTM;
29 /* Mangling the names by hand requires that we know how size_t is handled.
30 We've gotten the letter from autoconf, now substitute it into the names.
31 Everything below uses X as a placeholder for clarity. */
33 #define S1(x,y) x##y
34 #define S(x,y) S1(x,y)
36 #define _ZnwX S(_Znw,MANGLE_SIZE_T)
37 #define _ZnaX S(_Zna,MANGLE_SIZE_T)
38 #define _ZdlPvX S(_ZdlPv,MANGLE_SIZE_T)
39 #define _ZnwXRKSt9nothrow_t S(S(_Znw,MANGLE_SIZE_T),RKSt9nothrow_t)
40 #define _ZnaXRKSt9nothrow_t S(S(_Zna,MANGLE_SIZE_T),RKSt9nothrow_t)
41 #define _ZdlPvXRKSt9nothrow_t S(S(_ZdlPv,MANGLE_SIZE_T),RKSt9nothrow_t)
43 #define _ZGTtnwX S(_ZGTtnw,MANGLE_SIZE_T)
44 #define _ZGTtnaX S(_ZGTtna,MANGLE_SIZE_T)
45 #define _ZGTtdlPvX S(_ZGTtdlPv,MANGLE_SIZE_T)
46 #define _ZGTtnwXRKSt9nothrow_t S(S(_ZGTtnw,MANGLE_SIZE_T),RKSt9nothrow_t)
47 #define _ZGTtnaXRKSt9nothrow_t S(S(_ZGTtna,MANGLE_SIZE_T),RKSt9nothrow_t)
48 #define _ZGTtdlPvXRKSt9nothrow_t S(S(_ZGTtdlPv,MANGLE_SIZE_T),RKSt9nothrow_t)
50 /* Everything from libstdc++ is weak, to avoid requiring that library
51 to be linked into plain C applications using libitm.so. */
53 extern "C" {
55 extern void *_ZnwX (size_t) __attribute__((weak));
56 extern void _ZdlPv (void *) __attribute__((weak));
57 extern void _ZdlPvX (void *, size_t) __attribute__((weak));
58 extern void *_ZnaX (size_t) __attribute__((weak));
59 extern void _ZdaPv (void *) __attribute__((weak));
61 typedef const struct nothrow_t { } *c_nothrow_p;
63 extern void *_ZnwXRKSt9nothrow_t (size_t, c_nothrow_p) __attribute__((weak));
64 extern void _ZdlPvRKSt9nothrow_t (void *, c_nothrow_p) __attribute__((weak));
65 extern void _ZdlPvXRKSt9nothrow_t
66 (void *, size_t, c_nothrow_p) __attribute__((weak));
67 extern void *_ZnaXRKSt9nothrow_t (size_t, c_nothrow_p) __attribute__((weak));
68 extern void _ZdaPvRKSt9nothrow_t (void *, c_nothrow_p) __attribute__((weak));
70 #if !defined (HAVE_ELF_STYLE_WEAKREF)
71 void *_ZnwX (size_t) { return NULL; }
72 void _ZdlPv (void *) { return; }
73 void _ZdlPvX (void *, size_t) { return; }
74 void *_ZnaX (size_t) { return NULL; }
75 void _ZdaPv (void *) { return; }
77 void *_ZnwXRKSt9nothrow_t (size_t, c_nothrow_p) { return NULL; }
78 void _ZdlPvRKSt9nothrow_t (void *, c_nothrow_p) { return; }
79 void _ZdlPvXRKSt9nothrow_t (void *, size_t, c_nothrow_p) { return; }
80 void *_ZnaXRKSt9nothrow_t (size_t, c_nothrow_p) { return NULL; }
81 void _ZdaPvRKSt9nothrow_t (void *, c_nothrow_p) { return; }
82 #endif /* HAVE_ELF_STYLE_WEAKREF */
84 /* Wrap the delete nothrow symbols for usage with a single argument.
85 Perhaps should have a configure type check for this, because the
86 std::nothrow_t reference argument is unused (empty class), and most
87 targets don't actually need that second argument. So we _could_
88 invoke these functions as if they were a single argument free. */
89 static void
90 del_opnt (void *ptr)
92 _ZdlPvRKSt9nothrow_t (ptr, NULL);
95 static void
96 del_opvnt (void *ptr)
98 _ZdaPvRKSt9nothrow_t (ptr, NULL);
101 static void
102 delsz_opnt (void *ptr, size_t sz)
104 _ZdlPvXRKSt9nothrow_t (ptr, sz, NULL);
107 /* Wrap: operator new (std::size_t sz) */
108 void *
109 _ZGTtnwX (size_t sz)
111 void *r = _ZnwX (sz);
112 if (r)
113 gtm_thr()->record_allocation (r, _ZdlPv);
114 return r;
117 /* Wrap: operator new (std::size_t sz, const std::nothrow_t&) */
118 void *
119 _ZGTtnwXRKSt9nothrow_t (size_t sz, c_nothrow_p nt)
121 void *r = _ZnwXRKSt9nothrow_t (sz, nt);
122 if (r)
123 gtm_thr()->record_allocation (r, del_opnt);
124 return r;
127 /* Wrap: operator new[] (std::size_t sz) */
128 void *
129 _ZGTtnaX (size_t sz)
131 void *r = _ZnaX (sz);
132 if (r)
133 gtm_thr()->record_allocation (r, _ZdaPv);
134 return r;
137 /* Wrap: operator new[] (std::size_t sz, const std::nothrow_t& nothrow) */
138 void *
139 _ZGTtnaXRKSt9nothrow_t (size_t sz, c_nothrow_p nt)
141 void *r = _ZnaXRKSt9nothrow_t (sz, nt);
142 if (r)
143 gtm_thr()->record_allocation (r, del_opvnt);
144 return r;
147 /* Wrap: operator delete(void* ptr) */
148 void
149 _ZGTtdlPv (void *ptr)
151 if (ptr)
152 gtm_thr()->forget_allocation (ptr, _ZdlPv);
155 /* Wrap: operator delete (void *ptr, const std::nothrow_t&) */
156 void
157 _ZGTtdlPvRKSt9nothrow_t (void *ptr, c_nothrow_p nt UNUSED)
159 if (ptr)
160 gtm_thr()->forget_allocation (ptr, del_opnt);
163 /* Wrap: operator delete[] (void *ptr) */
164 void
165 _ZGTtdaPv (void *ptr)
167 if (ptr)
168 gtm_thr()->forget_allocation (ptr, _ZdaPv);
171 /* Wrap: operator delete[] (void *ptr, const std::nothrow_t&) */
172 void
173 _ZGTtdaPvRKSt9nothrow_t (void *ptr, c_nothrow_p nt UNUSED)
175 if (ptr)
176 gtm_thr()->forget_allocation (ptr, del_opvnt);
179 /* Wrap: operator delete(void* ptr, std::size_t sz) */
180 void
181 _ZGTtdlPvX (void *ptr, size_t sz)
183 if (ptr)
184 gtm_thr()->forget_allocation (ptr, sz, _ZdlPvX);
187 /* Wrap: operator delete (void *ptr, std::size_t sz, const std::nothrow_t&) */
188 void
189 _ZGTtdlPvXRKSt9nothrow_t (void *ptr, size_t sz, c_nothrow_p nt UNUSED)
191 if (ptr)
192 gtm_thr()->forget_allocation (ptr, sz, delsz_opnt);
195 } // extern "C"