[PATCH v2 0/3] MR69: include: Add __WINE_MALLOC attribute and use it for allocation functions.

Brendan Shanks (@bshanks) wine at gitlab.winehq.org
Mon May 16 13:16:48 CDT 2022


With this patch, lib/wine/x86_64-windows/ ends up 100 KB smaller, and I would expect performance benefits too.


>From https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-malloc-function-attribute:

Attribute malloc indicates that a function is malloc-like, i.e., that the pointer P returned by the function cannot alias any other pointer valid when the function returns, and moreover no pointers to valid objects occur in any storage addressed by P. In addition, the GCC predicts that a function with the attribute returns non-null in most cases.

Using the attribute with no arguments is designed to improve optimization by relying on the aliasing property it implies. Functions like malloc and calloc have this property because they return a pointer to uninitialized or zeroed-out, newly obtained storage. However, functions like realloc do not have this property, as they may return pointers to storage containing pointers to existing objects. Additionally, since all such functions are assumed to return null only infrequently, callers can be optimized based on that assumption.

--
  v2: crypt32/tests: Fix mismatched deallocation function.
      include: Add __WINE_DEALLOC attribute and use it for allocation functions.
      include: Add __WINE_MALLOC attribute and use it for allocation functions.
 
https://gitlab.winehq.org/wine/wine/-/merge_requests/69



More information about the wine-devel mailing list