]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Hide all malloc functions from compiler [BZ #32366]
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 17 Dec 2024 10:41:45 +0000 (18:41 +0800)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 17 Dec 2024 12:51:08 +0000 (20:51 +0800)
Since -1 isn't a power of two, compiler may reject it, hide memalign from
Clang 19 which issues an error:

tst-memalign.c:86:31: error: requested alignment is not a power of 2 [-Werror,-Wnon-power-of-two-alignment]
   86 |   p = memalign (-1, pagesize);
      |                 ^~
tst-memalign.c:86:31: error: requested alignment must be 4294967296 bytes or smaller; maximum alignment assumed [-Werror,-Wbuiltin-assume-aligned-alignment]
   86 |   p = memalign (-1, pagesize);
      |                 ^~

Update tst-malloc-aux.h to hide all malloc functions and include it in
all malloc tests to prevent compiler from optimizing out any malloc
functions.

Tested with Clang 19.1.5 and GCC 15 20241206 for BZ #32366.

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Reviewed-by: Sam James <sam@gentoo.org>
malloc/tst-mallinfo2.c
malloc/tst-malloc-aux.h
malloc/tst-malloc-backtrace.c
malloc/tst-memalign.c
malloc/tst-safe-linking.c
malloc/tst-valloc.c

index 2c02f5f700f5051e98e91d8b7954fbe954eea122..f072b9f24b575792ba30faafd16b01ed53dbc949 100644 (file)
@@ -23,6 +23,8 @@
 #include <stdlib.h>
 #include <support/check.h>
 
+#include "tst-malloc-aux.h"
+
 /* This is not specifically needed for the test, but (1) does
    something to the data so gcc doesn't optimize it away, and (2) may
    help when developing future tests.  */
index 54908b4a2464d51005c8c2de70a114a444f771b3..3e1b61ce3414dad4d33138ee330a98afda711304 100644 (file)
 
 #include <stddef.h>
 #include <stdlib.h>
-
-static void *(*volatile aligned_alloc_indirect)(size_t, size_t) = aligned_alloc;
-static void *(*volatile calloc_indirect)(size_t, size_t) = calloc;
-static void *(*volatile malloc_indirect)(size_t) = malloc;
-static void *(*volatile realloc_indirect)(void*, size_t) = realloc;
+#include <malloc.h>
+
+static __typeof (aligned_alloc) * volatile aligned_alloc_indirect
+  = aligned_alloc;
+static __typeof (calloc) * volatile calloc_indirect = calloc;
+static __typeof (malloc) * volatile malloc_indirect = malloc;
+static __typeof (memalign) * volatile memalign_indirect = memalign;
+static __typeof (posix_memalign) * volatile posix_memalign_indirect
+  = posix_memalign;
+static __typeof (pvalloc) * volatile pvalloc_indirect = pvalloc;
+static __typeof (realloc) * volatile realloc_indirect = realloc;
+static __typeof (valloc) * volatile valloc_indirect = valloc;
 
 #undef aligned_alloc
 #undef calloc
 #undef malloc
+#undef memalign
+#undef posix_memalign
+#undef pvalloc
 #undef realloc
+#undef valloc
 
 #define aligned_alloc aligned_alloc_indirect
 #define calloc calloc_indirect
 #define malloc malloc_indirect
+#define memalign memalign_indirect
+#define posix_memalign posix_memalign_indirect
+#define pvalloc pvalloc_indirect
 #define realloc realloc_indirect
+#define valloc valloc_indirect
 
 #endif /* TST_MALLOC_AUX_H */
index c7b1d65e5c95c437e35120776577ec4f547bb9f8..65fa91f6fdbdce91383f1045f372d47ba448a563 100644 (file)
@@ -22,6 +22,8 @@
 #include <support/support.h>
 #include <libc-diag.h>
 
+#include "tst-malloc-aux.h"
+
 #define SIZE 4096
 
 /* Wrap free with a function to prevent gcc from optimizing it out.  */
index 563f6413d2da506b30e83f3b3f0ca87b99ff4a86..ac9770d3f96313a77e3149a3ac8ec5e39aa5bc38 100644 (file)
@@ -23,6 +23,8 @@
 #include <unistd.h>
 #include <libc-diag.h>
 
+#include "tst-malloc-aux.h"
+
 static int errors = 0;
 
 static void
index 5302575ad1f6b44f61937737c418b4ba2c12ce4e..59d45d0da53734f6c4b9fef9efac4a3563c144c1 100644 (file)
@@ -26,6 +26,8 @@
 #include <support/capture_subprocess.h>
 #include <support/check.h>
 
+#include "tst-malloc-aux.h"
+
 /* Run CALLBACK and check that the data on standard error equals
    EXPECTED.  */
 static void
index 9bab8c6470d4fd95b489a7ee92ed8b94400075e7..0243d3dfd494d329eebd047047775e4cca4c4901 100644 (file)
@@ -23,6 +23,8 @@
 #include <unistd.h>
 #include <libc-diag.h>
 
+#include "tst-malloc-aux.h"
+
 static int errors = 0;
 
 static void