Intel OSX support

William Stein wstein at gmail.com
Thu Jul 27 00:11:49 CEST 2006


Hello,

As was discussed on this list in February (and in several other
lists), GMP-4.2.*
does not compile (as a shared library) with assembly support on Intel-based
OS X computers.   As far as I can tell from all subsequent discussions, nobody
seems to have taken responsibility to address this problem, and the statement
"[2006-05-04] GMP does not build on MacInteltosh machines. No fix planned."
on the GMP website is not encouraging.     So I'm trying to fix this problem
myself, since I'm the main developer of SAGE
(http://modular.math.washington.edu/sage),
which makes extensive use of GMP, and we want SAGE to support OS X well
(I mainly use Linux myself, but many SAGE users use OS X.)

In the rest of this email all discussion involves using the *newest* *(this is
important) version of XCode on an Intel based mac with the latest OS upgrades
and gmp-4.2.1.tar.bz2 downloaded from the GMP site.  (If you don't use the
latest XCode, you'll likely have additional problems.)

If we build GMP using
   ./configure --enable-cxx=yes --enable-shared --disable-static
   make

then (as mentioned in previous posts) the compilation fails with errors that
involves two small blocks of assembly code that have an invalid (for
OS X) @ symbol in them:

       mpn/dive_1.asm, lines 79-88, and mpn/mode1o.s, lines 77-86,

both which are this block of code:

ifdef(`PIC',`
        call    L(movl_eip_ebp)
        addl    $_GLOBAL_OFFSET_TABLE_, %ebp
        movl    modlimb_invert_table at GOT(%ebp), %ebp
        movzbl  (%eax,%ebp), %ebp                       C inv 8 bits

',`
dnl non-PIC
        movzbl  modlimb_invert_table(%eax), %ebp        C inv 8 bits
')


These blocks involve whether or not PIC is defined.
I read somewhere online that PIC should not be defined for OSX, so I completely
commented out these two blocks of code (using dnl).    The entire GMP build
then completes successfully (and many many sample calculations I try work
perfectly, and are VERY fast compared to the non-assembly version of GMP
for OS X.)    Doing "make check" there is exactly one failure (I realize this is
just the make test in the tests/mpn directory, and there are many
other tests that
didn't get run).

make  check-TESTS
PASS: t-asmtype
PASS: t-aors_1
PASS: t-divrem_1
t-fat.c:132: GNU MP assertion failed: wp[0] == 321
FAIL: t-fat
PASS: t-get_d
PASS: t-instrument
PASS: t-iord_u
PASS: t-mp_bases
PASS: t-perfsqr
PASS: t-scan
==================================
1 of 10 tests failed
Please report to gmp-bugs at swox.com

This is perhaps not surprising, given that I commented out a line in the
assembler code that inverts an integer -- of course GMP shouldn't work correctly
with that line missing.  If I put back the non-PIC versions, I get this error
on compilation:

ld: mpn/.libs/dive_1.o has external relocation entries in non-writable
section (__TEXT,__text) for symbols:
___gmp_modlimb_invert_table
/usr/bin/libtool: internal link edit command failed

This is also exactly what I'd also get if I made no changes to the GMP source
code, but gave the --with-pic=no option to configure.

QUESTION:  What should the line of assembler be to either correctly
get that symbol, or to do the inversion (possibly without using the table)?

-- 
William Stein
Associate Professor of Mathematics
University of Washington


More information about the gmp-discuss mailing list