Search code examples
gccx86-64glibc32-bit

Building crti.o for i386


I am trying to build a cross-compiler with x86_64 being the host and i386 being the target. I'm getting the (all to common) crti.o: No such file error. Instead of grabbing an already built crti.o and crtn.o from a distro... how might I go about building these files explicitly from glibc (or possibly gcc) sources?

FYI, I am well aware of the -m32 option for x86_64 compilers. I'd prefer to just have a 32bit-only compiler environment. Also, the reason I don't want to use any of the gazillion already build i386 compilers is because I plan on mixing and matching glibc/binutils/gcc versions depending on my testing needs.

Thanks, Chenz


Solution

  • Are you sure you're using configuring the cross-compile correctly? It should be

    CBUILD = CHOST = x86_64-pc-linux-gnu
    CTARGET = i386-pc-linux-gnu

    as you're running a build on an x86_64, for a compiler to run on an x86_64, which generates code for an i386.

    If you used CHOST = i386-pc-linux-gnu, you'll be trying to generate 32-bit binaries, which will need to link with a 32-bit libc. Which is fine, if you already have a 32-bit libc, but it sounds like you don't.

    i.e.

    $ tar xvjf gcc-*.tar.bz2
    $ cd gcc-*/
    $ mkdir build
    $ cd build
    $ ../configure --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=i386-pc-linux-gnu