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