Glibc2 on Linux: GCC

Note that this documentation is historic. It may no longer be very relevant. There will be no updates or further releases.

Introduction

This is the first step in installing glibc-2. We first make sure that gcc is updated to the newest version, before we compile system-critical stuff. Here I describe how you compile gcc to produce native code: code that runs with your current libc-5 and on your current system. Compiling gcc as a cross-compiler is done later on.

Preparing for compilation

Even though this is a relative step-by-step guide, it would be wise to read the most important documentation yourself; especially the README and INSTALL files. The newest version as of the writing of this document is gcc-2.8.1; installation of newer versions may differ, and some of the patches may not apply cleanly.

Patches

You should apply at least the first patch; it is needed if you want to follow this step-by-step guide.

For old-time users of these pages: there is no longer any need for patches to enable a target alias and to use the glibc-version of assert.h, as both things are now the default. The C++ include dir can now also be set during configuration, and g++ always calls the correct compiler.

File Description
gcc281-p1.diff Nicer Installation
gcc281-p2.diff Disable strength reduction

You can apply these patches by entering the gcc directory and using the following command:

(bash) patch -p1 -E < filename

Compiling and installing gcc

I will assume you use bash as shell; if not, some commands may slightly differ. I will explain each step.

(bash) ./configure --with-gnu-as --with-gnu-ld --prefix=/usr \
--host=i486-pc-linux-gnulibc1 \
--target=i486-pc-linux-gnulibc1

We configure gcc to use the gnu assembler and loader, to live in /usr/... (instead of the default /usr/local/...), and to use the same host and target. Remember to replace those with the ones of your machine, but make sure host and target are the same.

(bash) make LANGUAGES=c

We will first compile gcc with our old compiler, and than use that gcc to compile gcc again - in that way, bugs in the old compiler have a minimal chance of effecting your newly created compiler. To compile the compiler again, we only need the C-compiler - not the C++ and objective-C compilers. This shortens the compilation time.

(bash) make stage1

This moves the compiler into a subdirectory, where it can live while we use it to compile the final compiler.

(bash) make CC="stage1/xgcc -Bstage1/" CFLAGS="-s -O2" \
target_alias=i486-linux-libc5

This is a bit tricky. This command compiles the compiler we will install. The CC argument is needed to use the intermediate compiler the previous make installed in the stage1 directory. We want the final compiler to be optimized and stripped, so we specify those options in CFLAGS. And we want to call the target as specified by target_alias above.

(bash) make install CC="stage1/xgcc -Bstage1/" CFLAGS="-s -O2" \
target_alias=i486-linux-libc5

Now we can install the compiler. Remember you must be root to do this. If you want to know what will be installed, you can add prefix=/tmp/usr to install the compiler at a temporary location. Do not forget to do a proper installation afterwards!

(bash) ln -sfn ../lib/gcc-lib/i486-linux-libc5/2.8.1/cpp /usr/bin/cpp

Many programs expect a version of cpp somewhere in the path. Really old programs (or programs for other Unixes) may even look for cpp in /lib/cpp; you might want to consider to create that link too.

(bash) ln -sfn gcc /usr/bin/cc
(bash) ln -sfn gcc /usr/i486-linux-libc5/bin/cc
(bash) ln -sfn ../../bin/gcc /usr/i486-linux-libc5/bin/gcc
(bash) ln -sfn g++ /usr/i486-linux-libc5/bin/c++
(bash) ln -sfn ../../bin/g++ /usr/i486-linux-libc5/bin/g++
(bash) ln -sfn ../../bin/protoize /usr/i486-linux-libc5/bin/protoize
(bash) ln -sfn ../../bin/unprotoize /usr/i486-linux-libc5/bin/unprotoize

None of these links are vital, but I recommend making them still. Many makefiles call your C-compiler as cc. And the links in /usr/i486-linux-libc5/bin will be useful later (believe me!).

Checking the installation

Calling gcc -v should output something like below now:

(bash) gcc -v
Reading specs from /usr/lib/gcc-lib/i486-linux-libc5/2.8.1/specs
gcc version 2.8.1

Calling gcc -print-search-dirs should output something like this:

(bash) gcc -print-search-dirs
install: /usr/lib/gcc-lib/i486-linux-libc5/2.8.1/
programs: /usr/lib/gcc-lib/i486-linux-libc5/2.8.1/:/usr/lib/gcc-lib/i486-linux-libc5/:/usr/lib/gcc/i486-linux-libc5/2.8.1/:/usr/lib/gcc/i486-linux-libc5/:/usr/i486-linux-libc5/bin/i486-linux-libc5/2.8.1/:/usr/i486-linux-libc5/bin/
libraries: /usr/lib/gcc-lib/i486-linux-libc5/2.8.1/:/usr/lib/gcc/i486-linux-libc5/2.8.1/:/usr/i486-linux-libc5/lib/i486-linux-libc5/2.8.1/:/usr/i486-linux-libc5/lib/:/usr/lib/i486-linux-libc5/2.8.1/:/usr/lib/:/lib/i486-linux-libc5/2.8.1/:/lib/:/usr/lib/i486-linux-libc5/2.8.1/:/usr/lib/

You can find a manifest of all installed files here.

What to do if everything fails

If something went hideously wrong, and you can't compile at all anymore (which is unlikely), you can probably still use the old version of your compiler. Look in /usr/lib/gcc-lib, where a subdirectory for your old target should be, and beneath that a subdirectory for the old compiler version. If these are still present, you can probably still use the compiler if you use the following invocation:

(bash) gcc -V 2.7.2.1 -b i486-linux ....

Substitute the version and target names you found in the directory structure.