Thursday, June 19, 2008

-m32 vs. -m64

Finally I was able to compile GCC with --enable-multilib. At least the C front end on openSUSE 10.2. I had troubles with Ubuntu 7.10 earlier, but it was long ago. I have to check it again. At that time it wasn't an issue for me to --disable-multilib, but now I want to do some experiments with -m32 on 64-bit platforms.

According to http://gcc.gnu.org/ml/gcc-help/2007-01/msg00352.html, Ubuntu places the libraries into unstandard locations and not into ${PREFIX}/lib and ${PREFIX}/lib64, but into ${PREFIX}/lib32 and ${PREFIX}/lib. It confuses GCC, because the MULTILIB_OSDIRNAMES in ${SRCDIR}/gcc/config/i386/t-linux64 was not modified accordingly. (Yes. It works for me now on Ubuntu 8.04.) The file command shows the differences.

Compiled with -m64 or without -m32:

a.out: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), for GNU/Linux 2.6.4, not stripped

With -m32:

a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.4, dynamically linked (uses shared libs), for GNU/Linux 2.6.4, not stripped

With -m32 it's possible to build 32-bit applications on 64-bit platforms. The only prerequisite is a GCC configured with --enable-multilib. The 32-bit libraries will be installed into ${PREFIX}/lib and the 64-bit libraries will be installed into ${PREFIX}/lib64. The following results show that there's no noticable difference in the sizes of data types between an application compiled on a native 32-bit system and between an application compiled on a 64-bit system with -m32. The test program was obvious.

Results with -m64 or without -m32 and with -m32:

sizeof (char) = 1 / 1
sizeof (short) = 2 / 2
sizeof (int) = 4 / 4
sizeof (long) = 8 / 4
sizeof (long long) = 8 / 8

sizeof (float) = 4 / 4
sizeof (double) = 8 / 8
sizeof (long double) = 16 / 12

sizeof (int *) = 8 / 4
sizeof (void *) = 8 / 4

Okay, it's not a big deal anyway, but there were no posts in the blog for a month. :)

No comments: