@@ -35,6 +35,12 @@ extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__));
3535extern " C" void __cxa_deleted_virtual (void ) __attribute__ ((__noreturn__));
3636
3737
38+ #if DEV_DEBUG_ABI_CPP
39+ extern " C" void _dbg_abi_print_pstr (const char * op, const char *function_name, const void * caller);
40+ #define DEBUG_NEW_OP_PRINTF () _dbg_abi_print_pstr(" new_op" , __PRETTY_FUNCTION__, NULL )
41+ #else
42+ #define DEBUG_NEW_OP_PRINTF () do { } while (false )
43+ #endif
3844/*
3945 This is what I perceived to be the intent of the original code.
4046
@@ -79,10 +85,12 @@ static void* _heap_new_align(std::size_t size, std::size_t alignment, const void
7985 "alignment - specifies the alignment. Must be a valid alignment
8086 supported by the implementation."
8187
82- I leave the validation to the umm_malloc library. See umm_memalign() for
83- details. Generally speaking, zero is handled as default and the default
84- is sizeof(umm_block), 8-bytes.
85- */
88+ I left the validation to the umm_malloc library. See umm_memalign() for
89+ details. Generally speaking, zero is handled as default, and the default
90+ is sizeof(umm_block), 8 bytes. Since the default is 8 bytes, the
91+ umm_malloc library is less strict about checking alignments less than 8
92+ bytes.
93+ */
8694
8795 void * p;
8896
@@ -101,18 +109,24 @@ static void* _heap_new_align(std::size_t size, std::size_t alignment, const void
101109// new_opa
102110void * operator new (std::size_t size, std::align_val_t alignment)
103111{
112+ DEBUG_NEW_OP_PRINTF ();
113+
104114 return _heap_new_align (size, std::size_t (alignment), __builtin_return_address (0 ));
105115}
106116
107117// new_opva
108118void * operator new [] (std::size_t size, std::align_val_t alignment)
109119{
120+ DEBUG_NEW_OP_PRINTF ();
121+
110122 return _heap_new_align (size, std::size_t (alignment), __builtin_return_address (0 ));
111123}
112124
113125// new_opant
114126void * operator new (std::size_t size, std::align_val_t alignment, const std::nothrow_t &) noexcept
115127{
128+ DEBUG_NEW_OP_PRINTF ();
129+
116130 __try {
117131 return _heap_new_align (size, std::size_t (alignment), __builtin_return_address (0 ));
118132 }
@@ -124,6 +138,8 @@ void* operator new (std::size_t size, std::align_val_t alignment, const std::not
124138// new_opvant
125139void * operator new [] (std::size_t size, std::align_val_t alignment, const std::nothrow_t &) noexcept
126140{
141+ DEBUG_NEW_OP_PRINTF ();
142+
127143 __try {
128144 return _heap_new_align (size, std::size_t (alignment), __builtin_return_address (0 ));
129145 }
@@ -135,18 +151,24 @@ void* operator new[] (std::size_t size, std::align_val_t alignment, const std::n
135151// new_op
136152void * operator new (std::size_t size)
137153{
154+ DEBUG_NEW_OP_PRINTF ();
155+
138156 return _heap_new_align (size, __STDCPP_DEFAULT_NEW_ALIGNMENT__, __builtin_return_address (0 ));
139157}
140158
141159// new_opv
142160void * operator new [] (std::size_t size)
143161{
162+ DEBUG_NEW_OP_PRINTF ();
163+
144164 return _heap_new_align (size, __STDCPP_DEFAULT_NEW_ALIGNMENT__, __builtin_return_address (0 ));
145165}
146166
147167// new_opnt
148168void * operator new (size_t size, const std::nothrow_t &) noexcept
149169{
170+ DEBUG_NEW_OP_PRINTF ();
171+
150172 __try {
151173 return _heap_new_align (size, __STDCPP_DEFAULT_NEW_ALIGNMENT__, __builtin_return_address (0 ));
152174 }
@@ -158,6 +180,8 @@ void* operator new (size_t size, const std::nothrow_t&) noexcept
158180// new_opvnt
159181void * operator new [] (size_t size, const std::nothrow_t &) noexcept
160182{
183+ DEBUG_NEW_OP_PRINTF ();
184+
161185 __try {
162186 return _heap_new_align (size, __STDCPP_DEFAULT_NEW_ALIGNMENT__, __builtin_return_address (0 ));
163187 }
@@ -188,16 +212,22 @@ static void* _heap_new(std::size_t size, const void* caller)
188212
189213void * operator new (std::size_t size)
190214{
215+ DEBUG_NEW_OP_PRINTF ();
216+
191217 return _heap_new (size, __builtin_return_address (0 ));
192218}
193219
194220void * operator new [] (std::size_t size)
195221{
222+ DEBUG_NEW_OP_PRINTF ();
223+
196224 return _heap_new (size, __builtin_return_address (0 ));
197225}
198226
199227void * operator new (size_t size, const std::nothrow_t &) noexcept
200228{
229+ DEBUG_NEW_OP_PRINTF ();
230+
201231 __try {
202232 return _heap_new (size, __builtin_return_address (0 ));
203233 }
@@ -208,6 +238,8 @@ void* operator new (size_t size, const std::nothrow_t&) noexcept
208238
209239void * operator new [] (size_t size, const std::nothrow_t &) noexcept
210240{
241+ DEBUG_NEW_OP_PRINTF ();
242+
211243 __try {
212244 return _heap_new (size, __builtin_return_address (0 ));
213245 }
@@ -230,41 +262,57 @@ void* operator new[] (size_t size, const std::nothrow_t&) noexcept
230262
231263void * operator new (size_t size, std::align_val_t alignment)
232264{
265+ DEBUG_NEW_OP_PRINTF ();
266+
233267 return _heap_abi_memalign (std::size_t (alignment), size, true , __builtin_return_address (0 ));
234268}
235269
236270void * operator new [] (size_t size, std::align_val_t alignment)
237271{
272+ DEBUG_NEW_OP_PRINTF ();
273+
238274 return _heap_abi_memalign (std::size_t (alignment), size, true , __builtin_return_address (0 ));
239275}
240276
241277void * operator new (size_t size, std::align_val_t alignment, const std::nothrow_t &)
242278{
279+ DEBUG_NEW_OP_PRINTF ();
280+
243281 return _heap_abi_memalign (std::size_t (alignment), size, false , __builtin_return_address (0 ));
244282}
245283
246284void * operator new [] (size_t size, std::align_val_t alignment, const std::nothrow_t &)
247285{
286+ DEBUG_NEW_OP_PRINTF ();
287+
248288 return _heap_abi_memalign (std::size_t (alignment), size, false , __builtin_return_address (0 ));
249289}
250290
251291void * operator new (size_t size)
252292{
293+ DEBUG_NEW_OP_PRINTF ();
294+
253295 return _heap_abi_memalign (__STDCPP_DEFAULT_NEW_ALIGNMENT__, size, true , __builtin_return_address (0 ));
254296}
255297
256298void * operator new [] (size_t size)
257299{
300+ DEBUG_NEW_OP_PRINTF ();
301+
258302 return _heap_abi_memalign (__STDCPP_DEFAULT_NEW_ALIGNMENT__, size, true , __builtin_return_address (0 ));
259303}
260304
261305void * operator new (size_t size, const std::nothrow_t &)
262306{
307+ DEBUG_NEW_OP_PRINTF ();
308+
263309 return _heap_abi_memalign (__STDCPP_DEFAULT_NEW_ALIGNMENT__, size, false , __builtin_return_address (0 ));
264310}
265311
266312void * operator new [] (size_t size, const std::nothrow_t &)
267313{
314+ DEBUG_NEW_OP_PRINTF ();
315+
268316 return _heap_abi_memalign (__STDCPP_DEFAULT_NEW_ALIGNMENT__, size, false , __builtin_return_address (0 ));
269317}
270318
@@ -275,32 +323,43 @@ void* operator new[] (size_t size, const std::nothrow_t&)
275323
276324void * operator new (size_t size)
277325{
326+ DEBUG_NEW_OP_PRINTF ();
327+
278328 return _heap_abi_malloc (size, true , __builtin_return_address (0 ));
279329}
280330
281331void * operator new [] (size_t size)
282332{
333+ DEBUG_NEW_OP_PRINTF ();
334+
283335 return _heap_abi_malloc (size, true , __builtin_return_address (0 ));
284336}
285337
286338void * operator new (size_t size, const std::nothrow_t &)
287339{
340+ DEBUG_NEW_OP_PRINTF ();
341+
288342 return _heap_abi_malloc (size, false , __builtin_return_address (0 ));
289343}
290344
291345void * operator new [] (size_t size, const std::nothrow_t &)
292346{
347+ DEBUG_NEW_OP_PRINTF ();
348+
293349 return _heap_abi_malloc (size, false , __builtin_return_address (0 ));
294350}
295351#endif // #elif !defined(__cpp_exceptions) #if defined(UMM_ENABLE_MEMALIGN)
296352#else
297353/*
298- Using weaklink C++ Exception handlers in libstdc
299- The "new" operators that express alignment should work through libstdc via
300- memalign() in the umm_malloc library.
354+ Using weaklink C++ Exception handlers in libstdc. The "new" operators that
355+ express alignment should work through libstdc via memalign() in the umm_malloc
356+ library.
357+
358+ Note that libstdc will fail errors in alignment value early. Thus, the
359+ UMM_STATS_FULL alignment error count will be zero.
301360
302- This saves 20 bytes in the UMM_ENABLE_MEMALIGN=1 case and 32 bytes when
303- UMM_ENABLE_MEMALIGN=0.
361+ This saves about 20 bytes in the UMM_ENABLE_MEMALIGN=1 case and 32 bytes when
362+ UMM_ENABLE_MEMALIGN=0.
304363
305364*/
306365// D <<
0 commit comments