Compiling using -m32 on a 64bit platform

Ruslan Ermilov ru at freebsd.org
Mon Feb 27 04:41:24 PST 2006


On Mon, Feb 27, 2006 at 03:49:26PM +1000, Paul Koch wrote:
> Hi,
> 
> We have a locally written application which is currently deployed on 
> i386, and we have recently ported it to amd64.  Unfortunately, in our 
> 64bit compile, some of our libraries and executables still need to be 
> compiled for a 32bit architecture.  Our application setup is a server 
> (i386 or amd64 based) which communicates with remote network appliances 
> (i386 based) and the server downloads various binaries to the remote 
> appliances.
> 
> 
> The issues we have come across are to do with the size of various types. 
> For example:
> 
> int64_t
>  - compiled on a 32bit machine is 64bits
>  - compiled on a 64bit machine is 64bits
>  - compiled on a 64bit machine with -m32 is 32bits !!
> 
> Sample:
> 
> #include <sys/types.h>
> #include <stdio.h>
> 
> int
> main (int argc, char **argv)
> {
>    printf ("sizeof (int64_t): %d\n", (int) sizeof (int64_t));
> 
>    return 0;
> }
> 
> $ cc -Wall -m32 -L/usr/lib32 -B/usr/lib32 -o test_32 test.c
> $ cc -Wall -o test_64 test.c
> 
> $ ./test_32
> sizeof (int64_t): 4
> 
> $ ./test_64
> sizeof (int64_t): 8
> 
You want to adopt the same approach that's used to compile 32-bit
runtime support on amd64.  In the above, at the very minimum, you
miss the 32-bit (i386) versions of includes.  The infrastructure
to allow users to build their 32-bit apps is not ready, so you'll
have to roll your own.  Fortunately, this should be easy to do.
You can try it by using the make command from src/Makefile.inc1,
as will be shown by "make -f Makefile.inc1 -V LIB32MAKE", after
completing buildworld on amd64.  For example,

: Script started on Mon Feb 27 14:37:44 2006
: $ uname -srm
: FreeBSD 7.0-CURRENT amd64
: $ cat Makefile
: LIB32MAKE!=	cd /usr/src && ${MAKE} -f Makefile.inc1 -V LIB32MAKE
: 
: .for target in depend all
: ${target}32:
: 	@cd ${.CURDIR} && ${LIB32MAKE} ${target}
: .endfor
: 
: PROG=	test_32
: SRCS=	test.c
: NO_MAN=
: 
: .include <bsd.prog.mk>
: $ make all32
: Warning: Object directory not changed from original /tmp
: cc -m32 -march=k8 -mfancy-math-387 -DCOMPAT_32BIT  -I/usr/obj/usr/src/lib32/usr/include  -L/usr/obj/usr/src/lib32/usr/lib32  -B/usr/obj/usr/src/lib32/usr/lib32 -O2 -fno-strict-aliasing -pipe  -c test.c
: cc -m32 -march=k8 -mfancy-math-387 -DCOMPAT_32BIT  -I/usr/obj/usr/src/lib32/usr/include  -L/usr/obj/usr/src/lib32/usr/lib32  -B/usr/obj/usr/src/lib32/usr/lib32 -O2 -fno-strict-aliasing -pipe   -o test_32 test.o 
: $ file test_32
: test_32: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked (uses shared libs), not stripped
: $ ./test_32
: sizeof (int64_t): 8
: Script done on Mon Feb 27 14:38:03 2006


Cheers,
-- 
Ruslan Ermilov
ru at FreeBSD.org
FreeBSD committer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-amd64/attachments/20060227/e94faef7/attachment.bin


More information about the freebsd-amd64 mailing list