Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build modern (4.x) GCC to target a 2.4.x kernel on the same architecture as the host?

The question is relatively straight forward: how can I build a GCC of the 4.x series (along with binutils and friends) that targets a 2.4 ABI on the same architecture as the host for the compiler?

The host system would be x86 or x86_64 and the only requirement is that the built ELF files run on an old kernel as long as the ABI matches. (Kernel sources/headers exist)

A compatible libc would be required as well in order to link it in. However, I can dynamically link against it as well, since I know the (g)libc version.

Any pointers would be much appreciated. I'm somewhat familiar with crosstool-ng, but that doesn't even seem to support 2.4 kernels anymore (for obvious reasons).

like image 350
0xC0000022L Avatar asked Oct 23 '11 18:10

0xC0000022L


People also ask

What does gcc do in C?

gcc performs the compilation step to build a program, and then it calls other programs to assemble the program and to link the program's component parts into an executable program that you can run.

What is build host?

So, build is the machine you're building on (no change there), host is the machine you're building for (the target libraries are built for the target, so host is the target you specified), and target doesn't apply (because you're not building a compiler, you're building libraries).


1 Answers

Probably the easiest way is to setup a modern tool chain on an old OS.

RHEL 2.1 or 3 might be best, as they were supported until recently.

Compiling gcc 4 may be tricky since you'll need maths libraries as well. You may have to do a multi-stage approach.

EDIT:

For compiling newer gcc:

  1. Compile latest make - add to PATH
  2. Unpack gcc
  3. Unpack mpfr, gmp, mpc into the gcc directory
  4. symlink the versioned directories to the base (mpfr, gmp, mpc).
  5. Build and install gcc

Something like this:

cd ~/software
tar xjf $DOWNLOAD/gcc/gcc-core-${GCCVER}.tar.bz2 || failure "unpack gcc failed"
tar xjf $DOWNLOAD/gcc/gcc-g++-${GCCVER}.tar.bz2 || failure "unpack g++ failed"

cd gcc-${GCCVER}

tar xjf $DOWNLOAD/gmp-5.0.2.tar.bz2 || failure "unpack gmp failed"
#tar xjf $DOWNLOAD/gmp-4.3.2.tar.bz2 || failure "unpack gmp failed"
ln -s gmp-* gmp
tar xjf $DOWNLOAD/mpfr-2.4.2.tar.bz2 || failure "unpack mpfr failed"
#tar xjf $DOWNLOAD/mpfr-2.4.2.tar.bz2 || failure "unpack mpfr failed"
ln -s mpfr-* mpfr
tar xzf $DOWNLOAD/mpc-0.9.tar.gz || failure "unpack mpc failed"
ln -s mpc-* mpc

cd ..
mkdir gcc-build
cd gcc-build
../gcc-${GCCVER}/configure --prefix=/opt/tools || failure "configure failed"
make || failure "make failed"
make install || failure "install failed"
like image 187
Douglas Leeder Avatar answered Oct 02 '22 00:10

Douglas Leeder