@@ -56,6 +56,7 @@ void *__real_malloc(size_t size);
5656void * __real_calloc (size_t count , size_t size );
5757void * __real_realloc (void * block , size_t size );
5858void __real_free (void * block );
59+ void __real__aligned_free (void * block );
5960char * __real_strdup (const char * text );
6061size_t __real__msize (void * block );
6162/* Wrappers must call __real_* for anything that is itself wrapped: a plain
@@ -155,9 +156,58 @@ void __wrap__aligned_free(void *block) {
155156 mi_free (block );
156157 return ;
157158 }
158- __real_free (block );
159+ /* A CRT aligned block has its own bookkeeping header. Plain free is not
160+ * its matching deallocator. */
161+ __real__aligned_free (block );
162+ }
163+
164+ #if defined(CBM_MEM_GLOBAL_OVERRIDE ) && CBM_MEM_GLOBAL_OVERRIDE
165+ /* LLVM-MinGW's static C++ runtime calls _aligned_malloc through the linker's
166+ * wrapper but its aligned operator delete can call the CRT import pointer
167+ * __imp__aligned_free directly. --wrap=_aligned_free does not rewrite that
168+ * import-pointer reference. Provide the six C++ ABI delete entry points so
169+ * every aligned new/delete pair reaches the same owner-aware deallocator. */
170+ void cbm_cxx_aligned_delete (void * block ) __asm__("_ZdlPvSt11align_val_t" );
171+ void cbm_cxx_aligned_delete (void * block ) {
172+ __wrap__aligned_free (block );
173+ }
174+
175+ void cbm_cxx_aligned_delete_nothrow (void * block ,
176+ const void * tag ) __asm__("_ZdlPvSt11align_val_tRKSt9nothrow_t" );
177+ void cbm_cxx_aligned_delete_nothrow (void * block , const void * tag ) {
178+ (void )tag ;
179+ __wrap__aligned_free (block );
180+ }
181+
182+ void cbm_cxx_aligned_delete_sized (void * block , size_t size ,
183+ size_t alignment ) __asm__("_ZdlPvySt11align_val_t" );
184+ void cbm_cxx_aligned_delete_sized (void * block , size_t size , size_t alignment ) {
185+ (void )size ;
186+ (void )alignment ;
187+ __wrap__aligned_free (block );
159188}
160189
190+ void cbm_cxx_aligned_array_delete (void * block ) __asm__("_ZdaPvSt11align_val_t" );
191+ void cbm_cxx_aligned_array_delete (void * block ) {
192+ __wrap__aligned_free (block );
193+ }
194+
195+ void cbm_cxx_aligned_array_delete_nothrow (void * block , const void * tag ) __asm__(
196+ "_ZdaPvSt11align_val_tRKSt9nothrow_t" );
197+ void cbm_cxx_aligned_array_delete_nothrow (void * block , const void * tag ) {
198+ (void )tag ;
199+ __wrap__aligned_free (block );
200+ }
201+
202+ void cbm_cxx_aligned_array_delete_sized (void * block , size_t size ,
203+ size_t alignment ) __asm__("_ZdaPvySt11align_val_t" );
204+ void cbm_cxx_aligned_array_delete_sized (void * block , size_t size , size_t alignment ) {
205+ (void )size ;
206+ (void )alignment ;
207+ __wrap__aligned_free (block );
208+ }
209+ #endif
210+
161211void * __wrap_realloc (void * block , size_t size ) {
162212 if (!block ) {
163213 void * fresh = mi_malloc (size );
0 commit comments