Linux thermal 2.6.29-rc8 #1 SMP Fri Mar 13 22:34:44 EDT 2009 x86_64 GNU/Linux I have a multithreaded program. When valgrind is run, I get a crash: x@thermal:/home/x/pt/src/main$ valgrind ./pt ==10484== Memcheck, a memory error detector. ==10484== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==10484== Using LibVEX rev 1888, a library for dynamic binary translation. ==10484== Copyright (C) 2004-2009, and GNU GPL'd, by OpenWorks LLP. ==10484== Using valgrind-3.5.0.SVN, a dynamic binary instrumentation framework. ==10484== Copyright (C) 2000-2009, and GNU GPL'd, by Julian Seward et al. ==10484== For more details, rerun with: -v ==10484== VG_(arena_memalign)(0x387E62B8, 8388608, 4096) bad alignment valgrind: the 'impossible' happened: VG_(arena_memalign) ==10484== at 0x3802A64C: report_and_quit (m_libcassert.c:140) ==10484== by 0x3802A764: panic (m_libcassert.c:215) ==10484== by 0x3802A7D2: vgPlain_core_panic_at (m_libcassert.c:220) ==10484== by 0x3802A7F1: vgPlain_core_panic (m_libcassert.c:225) ==10484== by 0x380361BE: vgPlain_arena_memalign (m_mallocfree.c:1593) ==10484== by 0x38002C64: vgMemCheck_new_block (mc_malloc_wrappers.c:198) ==10484== by 0x38002F43: vgMemCheck_memalign (mc_malloc_wrappers.c:265) ==10484== by 0x3804F2B0: vgPlain_scheduler (scheduler.c:1311) ==10484== by 0x380698F0: run_a_thread_NORETURN (syswrap-linux.c:89) ==10484== by 0x38069B1A: vgModuleLocal_start_thread_NORETURN (syswrap-linux.c:212) ==10484== by 0x3809421D: ??? (in /usr/local/lib/valgrind/memcheck-amd64-linux) ==10484== by 0xDEADBEEFDEADBEEE: ??? ==10484== by 0x100000001: ??? ==10484== by 0x3: ??? ==10484== by 0x5100001D5100001D: ??? ==10484== by 0x380AF9C1: typeOfIRExpr (irdefs.c:1933) ==10484== by 0x5000000C3899F418: ??? ==10484== by 0x380BD6D2: doAMode_M (hdefs.c:2061) ==10484== by 0x3899F3A0: ??? ==10484== by 0x389A0CC0: ??? ==10484== by 0x389A0CD8: ??? ==10484== by 0x40768FC82: ??? ==10484== by 0x40768FD10: ??? ==10484== by 0x380BFE1E: emit_AMD64Instr (hdefs.c:2735) ==10484== by 0x523899B580: ??? ==10484== by 0x3899B580: ??? ==10484== by 0xB: ??? ==10484== by 0x40768FC80: ??? ==10484== by 0x40768FD10: ??? ==10484== by 0x1FA: ??? ==10484== by 0x240: ??? ==10484== by 0x13: ??? ==10484== by 0x38172E3E: ??? (in /usr/local/lib/valgrind/memcheck-amd64-linux) ==10484== by 0x38098F00: myvprintf_str (m_debuglog.c:467) other threads ....
I think you've mixed up the order of the arguments to memalign. The alignment is given by the first arg, the size by the second. Valgrind is aborting because 8388608 is an inappropriate alignment value. I've improved the error message to make this clearer.
Julian, I ran into the exact same problem, and the arguments to memalign are correct. The particular application has to allocate 8MB-aligned memory segments for DMA to a disk array, and 8M alignment is perfectly appropriate. I modified the source code to check for 8M instead and everything worked. Suggesting increasing the value to 8388608 in the trunk source code. Thanks! / Alex Ivershen
Alex, can you please open a new bug with a title something like "increase maximum allowed alignment for memalign()". Thanks.