v5.0.1, Mac, 32-bit: gmp_snprintf problem for (high) multi-limb integers

John McDermott jjm at mcs.st-and.ac.uk
Mon Mar 14 11:03:29 CET 2011


Dear Torbjörn,

On 10 Mar 2011, at 22:57, Torbjorn Granlund wrote:

> Thanks for you excellent report!

It's our pleasure. Thanks very much for your help!

> I don't have access to any core2 mac, so I can ot attempt to reproduce
> this.

We are trying to arrange access for ourselves to a larger pool of Macs, for testing with various architectures. If you would like to have access to a machine on which we can reproduce the problem we can probably arrange that in the near future.

> Question: When you compile the failing test, are you sure you get the
> proper gmp.h?  It is a generated file, meaning that it will not support
> both a 32-bit build and a 32-bit build.

Yes, we have been quite careful about this.

> I am surprised that the GMP testsuite does not catch this problem.
> 
> Please try the following:
> 
> cd tests/mpz
> while true; do GMP_CHECK_RANDOMIZE=1 ./convert || break; done
> 
> Let it then run for a couple of minutes.

I ran this for over ten minutes on my machine, in a build setup which exhibits the issue, and saw nothing interesting. Many lines like

...
Seed GMP_CHECK_RANDOMIZE=975436106 (include this in bug reports)
Seed GMP_CHECK_RANDOMIZE=2270808398 (include this in bug reports)
...

were produced. And nothing else. I doubt you would be interested to see them all :) We reproduced this on another very similar Mac.

> Experiments seem to show this issue turns up around the stage when the
> numbers involved are getting as big as 22 limbs or so.
> 
> Non-incidentally, at 22 limbs, mpn_get_str will change algorithm, see
> the last lines of gmp-mparam.h in the top level build dir.

I see - that is interesting, and suggestive.

We will run more tests once we get our hands on these extra Macs and let you know the results.

For now, in case it is of any use to you to see the assembler code, I append below the result of

gcc -m32 test_gmp_snprintf.c -S -I gmpbuild/include

using the same version of gmp and test file which exhibit the issue.

John

> -- 
> Torbjörn

========== 8< ==========
	.cstring
LC1:
	.ascii "%Ni\0"
LC2:
	.ascii "%Nx\0"
	.const
	.align 2
LC0:
	.ascii "111738634087016687677581080419779823937672962105281999064930026947977838341505382863502660652163271927890657789545865354105698690880491419382732505129685548945886493976382779091529311779061982182942409366242406420035526825355893426176\0"
	.space 765
	.text
.globl _main
_main:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%ebx
	subl	$6068, %esp
	call	L7
"L00000000001$pb":
L7:
	popl	%ebx
	movl	12(%ebp), %eax
	movl	%eax, -6028(%ebp)
	leal	L___stack_chk_guard$non_lazy_ptr-"L00000000001$pb"(%ebx), %eax
	movl	(%eax), %eax
	movl	(%eax), %edx
	movl	%edx, -12(%ebp)
	xorl	%edx, %edx
	leal	LC0-"L00000000001$pb"(%ebx), %eax
	leal	-2012(%ebp), %ecx
	movl	%eax, %edx
	movl	$235, %eax
	movl	%eax, 8(%esp)
	movl	%edx, 4(%esp)
	movl	%ecx, (%esp)
	call	_memcpy
	leal	-1777(%ebp), %edx
	movl	$765, %eax
	movl	%eax, 8(%esp)
	movl	$0, 4(%esp)
	movl	%edx, (%esp)
	call	_memset
	leal	-2012(%ebp), %eax
	movl	%eax, (%esp)
	call	_puts
	leal	-2012(%ebp), %eax
	movl	%eax, (%esp)
	call	_strlen
	movl	%eax, -2024(%ebp)
	movl	$0, -2020(%ebp)
	jmp	L2
L3:
	movl	-2020(%ebp), %edx
	movl	-2020(%ebp), %eax
	movzbl	-2012(%ebp,%eax), %eax
	subl	$48, %eax
	movb	%al, -2012(%ebp,%edx)
	incl	-2020(%ebp)
L2:
	movl	-2020(%ebp), %eax
	cmpl	-2024(%ebp), %eax
	jl	L3
	movl	-2024(%ebp), %eax
	leal	-2012(%ebp), %edx
	movl	$10, 12(%esp)
	movl	%eax, 8(%esp)
	movl	%edx, 4(%esp)
	leal	-6024(%ebp), %eax
	movl	%eax, (%esp)
	call	___gmpn_set_str
	movl	%eax, -2016(%ebp)
	movl	-2016(%ebp), %eax
	movl	%eax, 16(%esp)
	leal	-6024(%ebp), %eax
	movl	%eax, 12(%esp)
	leal	LC1-"L00000000001$pb"(%ebx), %eax
	movl	%eax, 8(%esp)
	movl	$1000, 4(%esp)
	leal	-1012(%ebp), %eax
	movl	%eax, (%esp)
	call	___gmp_snprintf
	leal	-1012(%ebp), %eax
	movl	%eax, (%esp)
	call	_puts
	movl	-2024(%ebp), %eax
	leal	-2012(%ebp), %edx
	movl	$10, 12(%esp)
	movl	%eax, 8(%esp)
	movl	%edx, 4(%esp)
	leal	-6024(%ebp), %eax
	movl	%eax, (%esp)
	call	___gmpn_set_str
	movl	%eax, -2016(%ebp)
	movl	-2016(%ebp), %eax
	movl	%eax, 16(%esp)
	leal	-6024(%ebp), %eax
	movl	%eax, 12(%esp)
	leal	LC2-"L00000000001$pb"(%ebx), %eax
	movl	%eax, 8(%esp)
	movl	$1000, 4(%esp)
	leal	-1012(%ebp), %eax
	movl	%eax, (%esp)
	call	___gmp_snprintf
	leal	-1012(%ebp), %eax
	movl	%eax, (%esp)
	call	_puts
	leal	L___stack_chk_guard$non_lazy_ptr-"L00000000001$pb"(%ebx), %edx
	movl	(%edx), %edx
	movl	-12(%ebp), %ecx
	xorl	(%edx), %ecx
	je	L6
	call	___stack_chk_fail
L6:
	addl	$6068, %esp
	popl	%ebx
	leave
	ret
	.section __IMPORT,__pointers,non_lazy_symbol_pointers
L___stack_chk_guard$non_lazy_ptr:
	.indirect_symbol ___stack_chk_guard
	.long	0
	.subsections_via_symbols
========== 8< ==========


--
John McDermott
Scientific Officer
Centre for Interdisciplinary Research in Computational Algebra
School of Computer Science
University of St Andrews
North Haugh, St Andrews, Fife
KY16 9SX
SCOTLAND

(Room 330, Mathematical Institute)

tel +44 1334 463813
mob +44 7941 507531

The University of St Andrews is committed to sustainable practices and the preservation of the environment.
Please do not print this email unless absolutely necessary.

The University of St Andrews is a charity registered in Scotland : No SC01353



More information about the gmp-bugs mailing list