Building in 32-bit mode on amd64?

I have some C source that I've been dragging along with me to newer systems since 4.3BSD on a VAX :p. Because of its age and the fact that it started out as obfuscated code from a vendor, it is pretty much impossible to clean it up enough to compile properly in native mode on amd64. As some examples, the newest gcc that will tolerate its syntax is gcc34, it needs -fwritable_strings, and other disgusting anachronisms.

This is on 8.1-PRERELEASE.

I managed to get everything to compile nicely by adding the -m32 option to the gcc command line. However, linking isn't working, as referenced in these two old PR's:

http://www.freebsd.org/cgi/query-pr.cgi?pr=76224
http://www.freebsd.org/cgi/query-pr.cgi?pr=112215

Is the answer still "that won't work", or have there been developments since those PR's to allow this to work?
 
I am pretty sure that you can build whole /usr/src in 32bit mode on a amd64 machine as I have done it to install WINE from chroot. Ill take a closer look tomorrow regarding this.
 
cc -m32 -march=i686 -mmmx -msse -msse2 -mfancy-math-387 -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 -o hello hello.c

Code:
% file hello
hello: ELF 32-bit LSB executable, Intel 80386, version 1 (FreeBSD), dynamically linked (uses shared libs), for FreeBSD 8.0 (800504), not stripped

% ./hello
Hello world!

% uname -a
FreeBSD expl 8.0-STABLE FreeBSD 8.0-STABLE #3: Wed Mar 10 12:39:39 GMT 2010     expl@expl:/usr/obj/usr/src/sys/EXPL_KERNEL  amd64

Seems to work fine.
 
expl said:
cc -m32 -march=i686 -mmmx -msse -msse2 -mfancy-math-387 -DCOMPAT_32BIT -L/usr/lib32 -B/usr/lib32 -o hello hello.c
Seems to work fine.
Indeed. The executables are slightly larger than the ones generated natively on i386, but (in very brief testing) they appear to work fine. Thanks!
 
Back
Top