Re: compiling 32-bit binaries: chroot ia32-libs libc6-dev-i386 cross-compiling /usr/bin/ld libc.so
"Frankie Y. Liu" <frankie.y.liu@gmail.com> writes:
> 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.
You actualy should not need ia32-libs as there should be no
developement stuff in there. On amd64 all libraries needed in some
Build-Depends where split out and are build with gcc -m32, like
lib32z1.
But obviously the number of libraries is verry limited.
> 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.
A chroot will always work. It is the "solve it all" solution.
For finding libraries you can adjust your /etc/ld.so.con, as you said,
but for plugins, data dirs, ... that won't work. Packages would try
in /usr/lib/package/plugin.so, which is either missing or the 64bit
version.
So if you use a chroot then you should also invest some time into
[ds]chroot to run stuff there.
> 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.
I would install libc6-dev-i386 to get around that problem. I think
libc6 is the only common library having a linker script as .so file.
> 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.
That is rather complicated and would require you to setup
cross-compile versions of all libraries you need.
At that point it is way easier to create a new ia32-libs-something[-dev]
package that converts the libs you need to use
/emul/ia32-linux/usr/lib. You can use ia32-libs as template and
probably just have to adjust the package list and depend on ia32-libs.
MfG
Goswin
Reply to: