]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
solaris: aligned allocation issues
authorPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 23 Apr 2023 11:51:37 +0000 (13:51 +0200)
committerPaul Floyd <pjfloyd@wanadoo.fr>
Sun, 23 Apr 2023 11:51:37 +0000 (13:51 +0200)
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
coregrind/m_replacemalloc/vg_replace_malloc.c
memcheck/tests/Makefile.am
memcheck/tests/cxx17_aligned_new.stderr.exp-solaris [new file with mode: 0644]
memcheck/tests/memalign_args.c
memcheck/tests/memalign_args.stderr.exp-darwin [new file with mode: 0644]
memcheck/tests/solaris/aligned_alloc.c

index 8470daebd1762fdb4d107f7c3a92fafbf3323664..d1af9de0d3cbb06d041f40046aca22dd12559222 100755 (executable)
@@ -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 \
index 78d0b33104bc0a07c7927490bfb3d617fed555a2..a71aa4b5b26f4a2f2c00175ff57b2596cfd38fdc 100644 (file)
@@ -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; \
index faf9130bcd18b127e2e293ac1ec08dc970a1cd6c..9bbbe7bec5c9f733953ea7ab8aaf690859339a6d 100644 (file)
@@ -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 (file)
index 0000000..54659a4
--- /dev/null
@@ -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)
index de765bcc2bf41eea219cad6e493e21348a774819..6946ae3a32fd61c0816d266c2dfc1fd37d5e9d03 100644 (file)
@@ -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 (file)
index 0000000..c255e02
--- /dev/null
@@ -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)
index c8e82e276f27b3cd5bec9951fad0456607aa916f..346595f29e52b2579f2699537f21ac808df64594 100644 (file)
@@ -1,12 +1,13 @@
 #include <stdlib.h>
 #include <assert.h>
 #include <errno.h>
+#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
 }