1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

Hide all malloc functions from compiler [BZ #32366]

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>
This commit is contained in:
H.J. Lu
2024-12-17 18:41:45 +08:00
parent bd0ea9ff7e
commit f9493a15ea
6 changed files with 29 additions and 4 deletions

View File

@@ -23,6 +23,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <support/check.h> #include <support/check.h>
#include "tst-malloc-aux.h"
/* This is not specifically needed for the test, but (1) does /* 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 something to the data so gcc doesn't optimize it away, and (2) may
help when developing future tests. */ help when developing future tests. */

View File

@@ -22,20 +22,35 @@
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
static void *(*volatile aligned_alloc_indirect)(size_t, size_t) = aligned_alloc; static __typeof (aligned_alloc) * volatile aligned_alloc_indirect
static void *(*volatile calloc_indirect)(size_t, size_t) = calloc; = aligned_alloc;
static void *(*volatile malloc_indirect)(size_t) = malloc; static __typeof (calloc) * volatile calloc_indirect = calloc;
static void *(*volatile realloc_indirect)(void*, size_t) = realloc; 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 aligned_alloc
#undef calloc #undef calloc
#undef malloc #undef malloc
#undef memalign
#undef posix_memalign
#undef pvalloc
#undef realloc #undef realloc
#undef valloc
#define aligned_alloc aligned_alloc_indirect #define aligned_alloc aligned_alloc_indirect
#define calloc calloc_indirect #define calloc calloc_indirect
#define malloc malloc_indirect #define malloc malloc_indirect
#define memalign memalign_indirect
#define posix_memalign posix_memalign_indirect
#define pvalloc pvalloc_indirect
#define realloc realloc_indirect #define realloc realloc_indirect
#define valloc valloc_indirect
#endif /* TST_MALLOC_AUX_H */ #endif /* TST_MALLOC_AUX_H */

View File

@@ -22,6 +22,8 @@
#include <support/support.h> #include <support/support.h>
#include <libc-diag.h> #include <libc-diag.h>
#include "tst-malloc-aux.h"
#define SIZE 4096 #define SIZE 4096
/* Wrap free with a function to prevent gcc from optimizing it out. */ /* Wrap free with a function to prevent gcc from optimizing it out. */

View File

@@ -23,6 +23,8 @@
#include <unistd.h> #include <unistd.h>
#include <libc-diag.h> #include <libc-diag.h>
#include "tst-malloc-aux.h"
static int errors = 0; static int errors = 0;
static void static void

View File

@@ -26,6 +26,8 @@
#include <support/capture_subprocess.h> #include <support/capture_subprocess.h>
#include <support/check.h> #include <support/check.h>
#include "tst-malloc-aux.h"
/* Run CALLBACK and check that the data on standard error equals /* Run CALLBACK and check that the data on standard error equals
EXPECTED. */ EXPECTED. */
static void static void

View File

@@ -23,6 +23,8 @@
#include <unistd.h> #include <unistd.h>
#include <libc-diag.h> #include <libc-diag.h>
#include "tst-malloc-aux.h"
static int errors = 0; static int errors = 0;
static void static void