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

Alexander Kruppa akruppa at gmail.com
Thu Feb 21 16:30:06 CET 2013


2013/2/21 Zimmermann Paul <Paul.Zimmermann at loria.fr>:
>        Marco,
>
>> Can you please try if your test passes with "valgrind
>> --partial-loads-ok=yes" ?
>
> it still fails:

It also still fails with Valgrind 3.8.1, in the same way. One thing
that is slightly odd is that the error is reported as

==885== Invalid read of size 8

when it should be a read of size 16. The offending instruction is

   0x0000000000401a6f <+175>:	retq
   0x0000000000401a70 <+176>:	sub    $0x10,%rdx
=> 0x0000000000401a74 <+180>:	movaps (%rsi),%xmm0
   0x0000000000401a77 <+183>:	jb     0x401afe <__gmpn_copyd+318>
   0x0000000000401a7d <+189>:	nopl   (%rax)

so it seems to be a 16-byte transfer. Maybe Valgrind processes this
instruction as two transfers of 8 bytes each, and fails to realize
that this is a half-valid, half-invalid access and thus
--partial-loads-ok=yes fails to suppress it? If that should be the
case, it would be a bug in Valgrind, imho - notwithstanding that
--partial-loads-ok=yes is a last resort hack.

At any rate, if this error is by design for efficiency reasons, I
think it would be nice to have a configure option to make GMP choose
code that strictly adheres to correct memory access. Memory checkers
are not a silver bullet, but they are useful enough for debugging that
imho it would be a shame to reduce their utility with deliberate false
positives.

Alex


More information about the gmp-bugs mailing list