Re: how to support 32- & 64-bit versions of libraries
On Tue, Mar 31, 2009 at 09:50:49PM -0500, Steve M. Robbins wrote:
> Thanks very much for the succinct lesson on biarch and multiarch.
> On Wed, Mar 18, 2009 at 07:31:18PM +0100, Goswin von Brederlow wrote:
> > If you want to support 64bit (and n32) gmp on ppc, s390, sparc, mips
> > and mipsel NOW then look at zlib as an example.
> Great. So I've gone through the zlib example in some detail, along
> with the solutions provided by Matthias K. and Bill A. Inspired by
> zlib, I figured I might as well build lib32xxx and lib64xxx wherever
> possible, rather than just on amd64 and ppc, respectively.
> I'd greatly appreciate it if interested parties would have a look
> at what I've done  and offer constructive criticism.
> I've run into a roadblock, however, in that the header gmp.h is
> generated by configure. It has some parameters (size of a limb) that
> depend on whether compiled for 32 or 64 bits. So on amd64, for
> example, I have two incompatible gmp.h files. Matthias provided a
> gmp.h wrapper from Redhat that selects between architecture variants
> based on preprocessor symbols, e.g.
> #if defined(__i386__)
> #include "gmp-i386.h"
> #elif defined(__ia64__)
> #include "gmp-ia64.h"
I am surprised that I did not hit problems while using them.
I suppose I always used long instead of mp_limb_t
> However, in the case at hand it is the same architecture. Onqe
> variant is compiled with -m32 and the other with -m64. Is there a
> symbol that can distinguish the two so that I can use the Redhat
> trick? Other solutions?
Maybe gcc -m32 should be configured to look at /emul/ia32-linux/usr/include
before /usr/include on amd64, so you could put the 32bit include files
their. This seems the cleanest solution.
> Incidentally, the zlib debian/rules uses "gcc -m64" on architectures
> s390, sparc, i386, and powerpc. The info page on compiler options for
> gcc 4.3, however, says:
> These `-m' switches are supported in addition to the above on AMD
> x86-64 processors in 64-bit environments.
> Generate code for a 32-bit or 64-bit environment. The 32-bit
> environment sets int, long and pointer to 32 bits and
> generates code that runs on any i386 system. The 64-bit
> environment sets int to 32 bits and long and pointer to 64
> bits and generates code for AMD's x86-64 architecture. For
> darwin only the -m64 option turns off the `-fno-pic' and
> `-mdynamic-no-pic' options.
> Does it really work to use -m64 on an i386? Does amd64 code result?
Yes, though you might need to build-depend on gcc-multilib.
Imagine a large red swirl here.