Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Feb 2006 15:49:26 +1000
From:      Paul Koch <paul.koch@statseeker.com>
To:        freebsd-amd64@freebsd.org
Subject:   Compiling using -m32 on a 64bit platform
Message-ID:  <200602271549.26372.paul.koch@statseeker.com>

next in thread | raw e-mail | index | archive | help
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


Is this an error in header files (eg. /usr/include/machine/_types.h), or 
are we really missing something basic here ?

machine/_types.h on a 64bit machine:
 typedef long  __int64_t;

shouldn't this be:
 typedef long long  __int64_t;

because a int64_t should always be 8 bytes, and a 'long' on a 32bit 
machine is 4 bytes, while a 'long' on a 64bit machine is 8 bytes.  A 
'long long' is 8 bytes on both.


We tried making the above change to _types.h, but crash and burn, this 
just caused flow on affects to other fundamental types.

	Paul.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200602271549.26372.paul.koch>