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

Max Neunhoeffer neunhoef at mcs.st-and.ac.uk
Mon Mar 28 08:22:57 CEST 2011

Dear Torbjörn,

On Sun, Mar 27, 2011 at 11:29:50PM +0200, Torbjorn Granlund wrote:
> neunhoef at mcs.st-and.ac.uk (Max Neunhoeffer) writes:
>   So m4 is used to create the actual assembler-source-code.
>   This step seems to go wrong, since the 5th assembler statement
>   in __gmpn_invert_limb which reads
>           movzwl  -1024+approx_tab(%eax, %eax), %eax      C %eax = v0
>   in invert_limb.asm is correctly translated into
>           movzwl  -1024+approx_tab(%eax, %eax), %eax
>   on Linux but incorrectly translated into
>           movzwl  -1024+__gmpn_invert_limb_tab, %eax
>   on MacOS.
>   This leads to the fact that in some lookup table the lookup does no
>   longer work. This trips up invert_limb and division.
>   Note that the file invert_limb.asm says:
>   C Make approx_tab global to work around Apple relocation bug.
>   ifdef(`DARWIN',`
>           define(`approx_tab', MPN(invert_limb_tab))
>                   GLOBL   approx_tab')
>   Is this the problem?
> I've read and reread your text.  Unfortunately, I don't understand what
> the error might be in the code you analyse.  As you can tell, we have
> worked around a Mac OS bug, supposedly with some success.
> Have you stepped though invert_limb on two systems, with the same input,
> and see that loaded data from the appox_tab (or whatever we rename it
> to) differs?
Yes. I have done exactly that and this is the first step where
a difference occurs. Of course, I run the debugger in our situation 
where GAP is linked against gmp.

I am no assembler expert, but as far as I see it the value
to be looked up is in the %eax register. However, the code
           movzwl  -1024+__gmpn_invert_limb_tab, %eax
does not actually use that (as far as I see), that is because during
the m4 translation the
    (%eax, %eax)
has vanished.
It seems also that in the relocatable version the error does not occur
(again, I am not so sure about this).
> I side note: It is absolutely impossible that "make check" passes if
> division does not work.  It it passes, there must be some linkage flags
Yes, I agree. So probably the tests run with another version which
works, maybe they use the shared library version?
>From GAP we link against the .a file.
> set in the environment of your system making some not miscompiled
> library version become picked up.
Quite possibly so, I do not know, however.

I suggest you contact John McDermott and let him give you ssh access
to a machine where the problem shows up.

> -- 
> Torbjörn

Max Neunhoeffer              http://www-groups.mcs.st-and.ac.uk/~neunhoef/
> > > > > > > > > > >  May the Source be with you! < < < < < < < < < < < < 
The University of St Andrews is a registered Scottish charity: No SC013532

More information about the gmp-bugs mailing list