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

compiling 32-bit binaries: chroot ia32-libs libc6-dev-i386 cross-compiling /usr/bin/ld libc.so



Dear debian-amd64's,


Problem: I would like to compile 32-bit binaries and explore the
different options.

Question:  What are the recommended solutions?


Here are a few I have tried or am pondering about:


1)  The:  gcc -m32 and ia32-libs libc6-dev-i386  solution

This seems to be fairly straight forward, but maintaining different
32-bit libraries, not already packaged together with ia32-libs-* would
seem to be a hassle, and it doesn't seem to be the right thing to do.


2)  The:  compile in a chroot environment  solution

This would allow one to use all the packaged libraries for 32-bit, and
would be fairly straight forward to maintain.  I like the fact that I
don't have to rely on ia32 packages, since they contain a subset of
the libraries that I need.

It seems that by adding to the ld library path in
/etc/ld.so.conf.d/___.conf to my chroot libraries, and ln -s ...
ld-linux.so.2 seems to let me run most of my 32-bit programs in a
64-bit enviroment without the need to chroot to the 32-bit environment
to run these binaries.


3)  The:  gcc -m32  and chroot libs  solution

I would still prefer to compile on a 64-bit shell, i.e. not compiling
under a chroot environment.  Making the object files using gcc -m32
works ok (-I to include chroot includes)  but I ran into some trouble
in linking (with -L pointing to chroot libraries),

/usr/bin/ld sources the script in libc.so (the one in the chroot
environment) but libc.so contains an absolute path to /lib/libc.so.6
as opposed to a relative path to ../lib/libc.so.6.  Since /lib/ is by
default 64-bit stuff it cannot link correctly.  There seems to be a
workaround if I were to compile ld with the --sysroot option (and
include the TARGET_SYSTEM_ROOT_RELOCATABLE flag).  But I haven't
gotten far enough to tell if this would work.

In essence this is similar to solution 1) but without the reliance on
ia32-libs-* and libc6-dev-i386, instead, it would use the existing
libraries already installed in the 32-bit chroot.


4)  The:  cross-compile toolchain

This solution would be similar to the one above (building from a
64-bit environment), but would involve creating a dedicated toolchain
(gcc, ld, etc...) for cross-compiling.  I have read a few how-to's but
it seems to be a viable option.  I was wondering if someone has set
this up, in particular pointing to 32-bit libraries installed from a
chroot environment.

This probably has a higher chance to success, but I requires more
work.  If there is a way of getting solution 3) working, I would
prefer that instead.


Thanks!



cat /proc/{version,cpuinfo}
Linux version 2.6.20-15-generic (gcc version 4.1.2 (Ubuntu 4.1.2-0 ubuntu4))
Intel(R) Core(TM)2 CPU          6600  @ 2.40GHz



Reply to: