@@ -118,7 +118,7 @@ void *swift::swift_slowAlloc(size_t size, size_t alignMask) {
118
118
// i.e. 0 < alignment <= _minAllocationAlignment:
119
119
// The runtime may use either `free` or AlignedFree as long as it is
120
120
// consistent with allocation with the same alignment.
121
- void swift::swift_slowDealloc (void *ptr, size_t bytes , size_t alignMask) {
121
+ static void swift_slowDeallocImpl (void *ptr, size_t alignMask) {
122
122
if (alignMask <= MALLOC_ALIGN_MASK) {
123
123
#if defined(__APPLE__) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
124
124
malloc_zone_free (DEFAULT_ZONE (), ptr);
@@ -129,3 +129,34 @@ void swift::swift_slowDealloc(void *ptr, size_t bytes, size_t alignMask) {
129
129
AlignedFree (ptr);
130
130
}
131
131
}
132
+
133
+ void swift::swift_slowDealloc (void *ptr, size_t bytes, size_t alignMask) {
134
+ swift_slowDeallocImpl (ptr, alignMask);
135
+ }
136
+
137
+ #if defined(__APPLE__) && defined(__MACH__) && SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC
138
+ // On Darwin, define our own, hidden operator new/delete implementations. We
139
+ // don't want to pick up any overrides that come from other code, but we also
140
+ // don't want to expose our overrides to any other code. We can't do this
141
+ // directly in C++, as the compiler has an implicit prototype with default
142
+ // visibility. However, if we implement them as C functions using the C++
143
+ // mangled names, the compiler accepts them without complaint, and the linker
144
+ // still links all internal uses with these overrides.
145
+
146
+ __attribute__ ((visibility((" hidden" )))) extern "C" void *_Znwm(size_t size) {
147
+ return swift_slowAlloc (size, MALLOC_ALIGN_MASK);
148
+ }
149
+
150
+ __attribute__ ((visibility((" hidden" )))) extern "C" void _ZdlPv(void *ptr) {
151
+ swift_slowDeallocImpl (ptr, MALLOC_ALIGN_MASK);
152
+ }
153
+
154
+ __attribute__ ((visibility((" hidden" )))) extern "C" void *_Znam(size_t size) {
155
+ return swift_slowAlloc (size, MALLOC_ALIGN_MASK);
156
+ }
157
+
158
+ __attribute__ ((visibility((" hidden" )))) extern "C" void _ZdaPv(void *ptr) {
159
+ swift_slowDeallocImpl (ptr, MALLOC_ALIGN_MASK);
160
+ }
161
+
162
+ #endif
0 commit comments