[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: how to support 32- & 64-bit versions of libraries



"Steve M. Robbins" <steve@sumost.ca> writes:

> Goswin,
>
> 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 [1] 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"
>     ...
>
> However, in the case at hand it is the same architecture.  One
> 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?

-m32 defines __i386__ while -m64 defined __x86_64__ and so on for each
architecture. So just use the architecture defines. The Redhat trick
already does the job.

There are also things like __WORDSIZE that could be of use.

> 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.
>
>     `-m32'
>     `-m64'
>          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?

Add 'Build-depends: gcc-multilib' which pulls in libc6-dev-amd64 for
you as well and then -m64 will work. g++-4.3-multilib for C++ code
which then also pulls in lib64stdc++6.

MfG
        Goswin


Reply to: