GMP 5.1.1: Valgrind reports incorrect read in __gmpn_copyd (called from __gmpz_mul_2exp)

Leif Leonhardy not.really at online.de
Sat Feb 23 22:39:03 CET 2013


bodrato at mail.dm.unipi.it wrote:
> [...]
>
>> I.e., instead of telling the memory checker
>> to ignore those invalid accesses, actually making them valid
>
> You are right, this is not a very good strategy. The best one I can see is:
>   - patch Valgrind so that --partial-loads-ok=yes works also for SSE etc...;
> [...]


With the preliminary(?) patches from [1] (by Patrick J. LoPresti, not 
me) applied to Valgrind 3.8.1, "--partial-loads-ok" for me works as 
expected for the test_mpmod testcase with GMP 5.1.1 on 
core2-unknown-linux-gnu (actually a Xeon E5345, FWIW):


$ valgrind --partial-loads-ok=no ./test_mpmod
==22111== Memcheck, a memory error detector
==22111== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==22111== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==22111== Command: ./test_mpmod
==22111==
==22111== Invalid read of size 16
==22111==    at 0x4C65B34: __gmpn_copyd (in 
/home/leif/src/gmp-5.1.1-build.eno-gcc-4.6.3/.libs/libgmp.so.10.1.1)
==22111==    by 0x4C2B54F: __gmpz_mul_2exp (in 
/home/leif/src/gmp-5.1.1-build.eno-gcc-4.6.3/.libs/libgmp.so.10.1.1)
==22111==    by 0x4007CD: main (in /home/leif/tmp/eno/test_mpmod)
==22111==  Address 0x4e9c5a0 is 976 bytes inside a block of size 984 alloc'd
==22111==    at 0x4A07821: realloc (vg_replace_malloc.c:662)
==22111==    by 0x4C1A29B: __gmp_default_reallocate (in 
/home/leif/src/gmp-5.1.1-build.eno-gcc-4.6.3/.libs/libgmp.so.10.1.1)
==22111==    by 0x4C2E469: __gmpz_realloc (in 
/home/leif/src/gmp-5.1.1-build.eno-gcc-4.6.3/.libs/libgmp.so.10.1.1)
==22111==    by 0x4C2F1E5: __gmpz_set (in 
/home/leif/src/gmp-5.1.1-build.eno-gcc-4.6.3/.libs/libgmp.so.10.1.1)
==22111==    by 0x4007B4: main (in /home/leif/tmp/eno/test_mpmod)
==22111==
==22111==
==22111== HEAP SUMMARY:
==22111==     in use at exit: 0 bytes in 0 blocks
==22111==   total heap usage: 8 allocs, 8 frees, 7,032 bytes allocated
==22111==
==22111== All heap blocks were freed -- no leaks are possible
==22111==
==22111== For counts of detected and suppressed errors, rerun with: -v
==22111== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)


$ valgrind --partial-loads-ok=yes ./test_mpmod
==19231== Memcheck, a memory error detector
==19231== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==19231== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==19231== Command: ./test_mpmod
==19231==
==19231==
==19231== HEAP SUMMARY:
==19231==     in use at exit: 0 bytes in 0 blocks
==19231==   total heap usage: 8 allocs, 8 frees, 7,032 bytes allocated
==19231==
==19231== All heap blocks were freed -- no leaks are possible
==19231==
==19231== For counts of detected and suppressed errors, rerun with: -v
==19231== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)


Probably better than "manually" creating suppressions; not sure how many
you get with the full GMP-ECM testcase / its test suite.


A cumulative, "rebased" (offset changes only) patch is available here [2].

Note that you can apparently also vote for its inclusion at [1]. :-)


HTH,

-leif


[1] https://bugs.kde.org/show_bug.cgi?id=294285
     ("Bug 294285 - --partial-loads-ok does not work for 16-byte SSE loads")

[2] 
http://boxen.math.washington.edu/home/leif/tmp/valgrind-3.8.1-partial_loads_16_bytes.patch
     (To be applied with '-p1' in the valgrind-3.8.1 directory.)

-- 
() The ASCII Ribbon Campaign
/\   Help Cure HTML E-Mail


More information about the gmp-bugs mailing list