0001-include-stdlib.h-only-expose-reallocarray-prototype-.patch 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. From bbb1a4f197624b0040e3228505eb2a725a8846f8 Mon Sep 17 00:00:00 2001
  2. From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  3. Date: Thu, 3 Apr 2025 22:56:49 +0200
  4. Subject: [PATCH] include/stdlib.h: only expose reallocarray() prototype when
  5. implementation is available
  6. MIME-Version: 1.0
  7. Content-Type: text/plain; charset=UTF-8
  8. Content-Transfer-Encoding: 8bit
  9. The reallocarray() primitive is only provided by the malloc-standard
  10. implementation: neither malloc nor malloc-simple provide it. This
  11. causes issues when building for example util-linux on noMMU platforms
  12. as:
  13. - noMMU platforms can't use malloc-standard, so either malloc or
  14. malloc-simple are used, which means reallocarray() is not
  15. implemented
  16. - util-linux detects the absence of reallocarray(), and provides its
  17. own implementation, but the prototype clashes with the prototype in
  18. uClibc's <stdlib.h>
  19. The combination of which causes the following build failure:
  20. In file included from lib/color-names.c:7:
  21. ./include/c.h:586:21: error: static declaration of ‘reallocarray’ follows non-static declaration
  22. 586 | static inline void *reallocarray(void *ptr, size_t nmemb, size_t size)
  23. | ^~~~~~~~~~~~
  24. In file included from ./include/c.h:16:
  25. /home/thomas/projets/buildroot/output/host/arm-buildroot-uclinux-uclibcgnueabi/sysroot/usr/include/stdlib.h:898:14: note: previous declaration of ‘reallocarray’ with type ‘void *(void *, size_t, size_t)’ {aka ‘void *(void *, unsigned int, unsigned int)’}
  26. 898 | extern void *reallocarray (void *__ptr, size_t __m, size_t __n);
  27. | ^~~~~~~~~~~~
  28. make[3]: *** [Makefile:12354: lib/libtcolors_la-color-names.lo] Error 1
  29. To fix this, let's not expose the prototype of reallocarray() if we
  30. don't provide the implementation for it.
  31. Upstream: https://mailman.openadk.org/mailman3/hyperkitty/list/devel@uclibc-ng.org/thread/BX4ENNZYO23YQJQF5XITW7TETSJHEFK5/
  32. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  33. ---
  34. include/stdlib.h | 4 ++++
  35. 1 file changed, 4 insertions(+)
  36. diff --git a/include/stdlib.h b/include/stdlib.h
  37. index d4e0b75e7..448c5e336 100644
  38. --- a/include/stdlib.h
  39. +++ b/include/stdlib.h
  40. @@ -986,9 +986,13 @@ extern int getpt (void);
  41. extern int getloadavg (double __loadavg[], int __nelem)
  42. __THROW __nonnull ((1));
  43. +/* reallocarray() only provided by the malloc-standard implementation */
  44. +#if defined(__MALLOC_STANDARD__)
  45. extern void *reallocarray (void *__ptr, size_t __m, size_t __n);
  46. #endif
  47. +#endif
  48. +
  49. #ifdef _LIBC
  50. extern int __drand48_iterate (unsigned short int xsubi[3], struct drand48_data *buffer) attribute_hidden;
  51. --
  52. 2.48.1