Bug 272940 - valgrind refuses to work with memalign() on for large align requests
Summary: valgrind refuses to work with memalign() on for large align requests
Status: RESOLVED DUPLICATE of bug 203877
Alias: None
Product: valgrind
Classification: Developer tools
Component: memcheck (show other bugs)
Version: unspecified
Platform: Unlisted Binaries Linux
: NOR normal
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-10 14:58 UTC by Pierre Habouzit
Modified: 2011-08-23 10:17 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Pierre Habouzit 2011-05-10 14:58:28 UTC
edmonds@chase{0}:~/code/test$ cat memalign.c
    #include <stdlib.h>

    #define size (1 << 21)

    int main(void) {
            void *ptr;
            posix_memalign(&ptr, size, size);
            free(ptr);
            return 0;
    }
    edmonds@chase{0}:~/code/test$ gcc -O0 -ggdb -Wall -o memalign memalign.c
    edmonds@chase{0}:~/code/test$ valgrind ./memalign                       
    ==31507== Memcheck, a memory error detector.
    ==31507== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
    ==31507== Using LibVEX rev 1854, a library for dynamic binary translation.
    ==31507== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
    ==31507== Using valgrind-3.3.1-Debian, a dynamic binary instrumentation framework.
    ==31507== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
    ==31507== For more details, rerun with: -v
    ==31507== 
    VG_(arena_memalign)(0x3879AB60, 2097152, 2097152)
    bad alignment
    valgrind: the 'impossible' happened:
       VG_(arena_memalign)
    ==31507==    at 0x380194CC: report_and_quit (m_libcassert.c:140)
    ==31507==    by 0x380195E4: panic (m_libcassert.c:210)
    ==31507==    by 0x38019652: vgPlain_core_panic_at (m_libcassert.c:215)
    ==31507==    by 0x38019671: vgPlain_core_panic (m_libcassert.c:220)
    ==31507==    by 0x380228BE: vgPlain_arena_memalign (m_mallocfree.c:1392)
    ==31507==    by 0x38002909: vgMemCheck_new_block (mc_malloc_wrappers.c:195)
    ==31507==    by 0x38002BEA: vgMemCheck_memalign (mc_malloc_wrappers.c:259)
    ==31507==    by 0x38033F08: vgPlain_scheduler (scheduler.c:1277)
    ==31507==    by 0x380448D3: run_a_thread_NORETURN (syswrap-linux.c:89)

    sched status:
      running_tid=1

    Thread 1: status = VgTs_Runnable
    ==31507==    at 0x4C1FFCF: memalign (vg_replace_malloc.c:460)
    ==31507==    by 0x4C20068: posix_memalign (vg_replace_malloc.c:569)
    ==31507==    by 0x400536: main (memalign.c:7)


    Note: see also the FAQ.txt in the source distribution.
    It contains workarounds to several common problems.

    If that doesn't help, please report this bug to: www.valgrind.org

    In the bug report, send all the above text, the valgrind
    version, and what Linux distro you are using.  Thanks.

    edmonds@chase{1}:~/code/test$

there is a check in coregrind/m_mallocfree.c:1385 which reads,

   // Check that the requested alignment seems reasonable; that is, is
   // a power of 2.
   if (req_alignB < VG_MIN_MALLOC_SZB
       || req_alignB > 1048576
       || VG_(log2)( req_alignB ) == -1 /* not a power of 2 */) {
      VG_(printf)("VG_(arena_memalign)(%p, %lu, %lu)\nbad alignment",
                  a, req_alignB, req_pszB );
      VG_(core_panic)("VG_(arena_memalign)");
      /*NOTREACHED*/
   }

the comment or the code is wrong, as there are certainly powers of 2
larger than 1048576.

This is Debian bug #489297 (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=489297)
Comment 1 Tom Hughes 2011-08-23 10:17:15 UTC

*** This bug has been marked as a duplicate of bug 203877 ***