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

bodrato at bodrato at
Fri Feb 22 12:22:27 CET 2013

Ciao Alexander,

Il Gio, 21 Febbraio 2013 4:30 pm, Alexander Kruppa ha scritto:

> case, it would be a bug in Valgrind, imho - notwithstanding that
> --partial-loads-ok=yes is a last resort hack.

Valgrind documentation reads: "code that behaves in this way is in
violation of the the ISO C/C++ standards, and should be considered
But the code in GMP that needs this option is not a piece of portable C
code, but an assembly optimised portion of code that is used only on some
CPUs where it is known that it's safe! I'd not consider it broken.

> 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

If you do not care about efficiency, GMP compiled with --disable-assembly
should adhere to ISO C standards (if it doesn't, that's a bug!).

Removing the files listed by $(grep -rl fastsse mpn/x86_64), before
./configure, can be another hack.

> a shame to reduce their utility with deliberate false positives.

Does "deliberate" means "intentional"? As the corresponding Italian word
I can assure you that the goal of that code is not "to reduce" usefulness
of memory checkers by triggering "false positives" :-D

A possible compromise can be a set of valgrind-friendly custom allocation
I attach a draft proposal I wrote looking at Valgrind documentation. It
marks as "undefined" the bytes (if any) after each allocated memory area,
filling an "aligned" block of bytes. The right mark should be
"addressable", without changing the "defined/undefined" status (can those
bytes already be in use?) but I was not able to find the corresponding
Because of this, the proposed code doesn't mark the bytes before the
initial block...

I hope this can help.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: valgrind_friendly_mm.c
Type: text/x-csrc
Size: 2606 bytes
Desc: not available
URL: <>

More information about the gmp-bugs mailing list