From a821780d8ccbf4a1ade369d838d52486ec1571a2 Mon Sep 17 00:00:00 2001 From: Paul Floyd Date: Sun, 23 Apr 2023 13:51:37 +0200 Subject: [PATCH] solaris: aligned allocation issues Solaris 11.3 doesn't have aligned_alloc - add a configure time test memalign does not accept either a size or an alignment of zero --- configure.ac | 1 + coregrind/m_replacemalloc/vg_replace_malloc.c | 5 +++- memcheck/tests/Makefile.am | 2 ++ .../tests/cxx17_aligned_new.stderr.exp-solaris | 30 ++++++++++++++++++++++ memcheck/tests/memalign_args.c | 2 +- memcheck/tests/memalign_args.stderr.exp-darwin | 11 ++++++++ memcheck/tests/solaris/aligned_alloc.c | 5 ++-- 7 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 memcheck/tests/cxx17_aligned_new.stderr.exp-solaris create mode 100644 memcheck/tests/memalign_args.stderr.exp-darwin diff --git a/configure.ac b/configure.ac index 8470daebd..d1af9de0d 100755 --- a/configure.ac +++ b/configure.ac @@ -4803,6 +4803,7 @@ AC_CHECK_LIB([pthread], [pthread_create]) AC_CHECK_LIB([rt], [clock_gettime]) AC_CHECK_FUNCS([ \ + aligned_alloc \ clock_gettime\ copy_file_range \ epoll_create \ diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 78d0b3310..a71aa4b5b 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -1742,8 +1742,10 @@ extern int * __error(void) __attribute__((weak)); #if defined(VGO_solaris) #define VG_MEMALIGN_ALIGN_POWER_TWO 0 +#define VG_MEMALIGN_NO_ALIGN_ZERO 1 #else #define VG_MEMALIGN_ALIGN_POWER_TWO 1 +#define VG_MEMALIGN_NO_ALIGN_ZERO 0 #endif #if defined(VGO_solaris) @@ -1802,7 +1804,8 @@ extern int * __error(void) __attribute__((weak)); DO_INIT; \ MALLOC_TRACE("memalign(alignment %llu, size %llu)", \ (ULong)alignment, (ULong)size ); \ - if ((VG_MEMALIGN_NO_SIZE_ZERO && (alignment == 0)) \ + if ((VG_MEMALIGN_NO_SIZE_ZERO && (size == 0)) \ + || (VG_MEMALIGN_NO_ALIGN_ZERO && (alignment == 0)) \ || (VG_MEMALIGN_ALIGN_POWER_TWO && (alignment & (alignment - 1)) != 0) \ || (VG_MEMALIGN_ALIGN_FACTOR_FOUR && (alignment % 4 != 0))) { \ SET_ERRNO_EINVAL; \ diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index faf9130bc..9bbbe7bec 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -141,6 +141,7 @@ EXTRA_DIST = \ custom-overlap.stderr.exp custom-overlap.vgtest \ cxx17_aligned_new.stderr.exp cxx17_aligned_new.vgtest \ cxx17_aligned_new.stderr.exp_32 \ + cxx17_aligned_new.stderr.exp-solaris \ cxx17_aligned_new.stdout.exp \ sized_aligned_new_delete_args.stderr.exp \ sized_aligned_new_delete_args.vgtest \ @@ -226,6 +227,7 @@ EXTRA_DIST = \ memalign_test.stderr.exp-freebsd-clang \ memalign_args.vgtest memalign_args.stderr.exp \ memalign_args.stderr.exp-glibc \ + memalign_args.stderr.exp-darwin \ memcmptest.stderr.exp memcmptest.stderr.exp2 \ memcmptest.stdout.exp memcmptest.vgtest \ memmem.stderr.exp memmem.vgtest \ diff --git a/memcheck/tests/cxx17_aligned_new.stderr.exp-solaris b/memcheck/tests/cxx17_aligned_new.stderr.exp-solaris new file mode 100644 index 000000000..54659a4db --- /dev/null +++ b/memcheck/tests/cxx17_aligned_new.stderr.exp-solaris @@ -0,0 +1,30 @@ + +_ZnwmSt11align_val_t(size 64, al 64) = 0x........ +_ZdlPvSt11align_val_t(0x........) +_ZnamSt11align_val_t(size 320, al 64) = 0x........ +_ZdaPvSt11align_val_t(0x........) +_ZnwmSt11align_val_t(size 64, al 64) = 0x........ +_ZdlPvmSt11align_val_t(0x........) +_ZnamSt11align_val_t(size 320, al 64) = 0x........ +_ZdaPvmSt11align_val_t(0x........) +_ZnwmSt11align_val_tRKSt9nothrow_t(size 64, al 64) = 0x........ +_ZdlPvSt11align_val_tRKSt9nothrow_t(0x........) +_ZnamSt11align_val_tRKSt9nothrow_t(size 320, al 64) = 0x........ +_ZdaPvSt11align_val_tRKSt9nothrow_t(0x........) +_Znwm(4) = 0x........ +_ZdlPvSt11align_val_t(0x........) +_ZnwmRKSt9nothrow_t(4) = 0x........ +_ZdlPvm(0x........) +_Znam(20) = 0x........ +_ZdaPv(0x........) +_ZnamRKSt9nothrow_t(20) = 0x........ +_ZdaPv(0x........) + +HEAP SUMMARY: + in use at exit: ... bytes in ... blocks + total heap usage: ... allocs, ... frees, ... bytes allocated + +For a detailed leak analysis, rerun with: --leak-check=full + +For lists of detected and suppressed errors, rerun with: -s +ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) diff --git a/memcheck/tests/memalign_args.c b/memcheck/tests/memalign_args.c index de765bcc2..6946ae3a3 100644 --- a/memcheck/tests/memalign_args.c +++ b/memcheck/tests/memalign_args.c @@ -23,7 +23,7 @@ int main(void) (void)posix_memalign((void **)&mem,align,size); free(mem); -#if !defined(VGO_darwin) +#if defined(HAVE_ALIGNED_ALLOC) p = aligned_alloc(align, size); free(p); #endif diff --git a/memcheck/tests/memalign_args.stderr.exp-darwin b/memcheck/tests/memalign_args.stderr.exp-darwin new file mode 100644 index 000000000..c255e02f1 --- /dev/null +++ b/memcheck/tests/memalign_args.stderr.exp-darwin @@ -0,0 +1,11 @@ +Conditional jump or move depends on uninitialised value(s) + at 0x........: memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:19) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: posix_memalign (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:23) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: valloc (vg_replace_malloc.c:...) + by 0x........: main (memalign_args.c:31) diff --git a/memcheck/tests/solaris/aligned_alloc.c b/memcheck/tests/solaris/aligned_alloc.c index c8e82e276..346595f29 100644 --- a/memcheck/tests/solaris/aligned_alloc.c +++ b/memcheck/tests/solaris/aligned_alloc.c @@ -1,12 +1,13 @@ #include #include #include +#include "../../config.h" int main(void) { +#if defined(HAVE_ALIGNED_ALLOC) char* p = NULL; - // zero size p = aligned_alloc(0, 8); assert(p == NULL && errno == EINVAL); @@ -33,6 +34,6 @@ int main(void) } assert(p == NULL && errno == ENOMEM); - +#endif } -- 2.11.4.GIT