gnu-misc-discuss
[Top][All Lists]
Advanced

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

Re: How to build GNU toolchain for AMD64?


From: Michael Meissner
Subject: Re: How to build GNU toolchain for AMD64?
Date: Sat, 26 Jul 2008 00:30:48 -0400
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux)

khapi@yahoo.com writes:

> I'm using a Linux distro that doesn't have a 64-bit
> version, and after trying two that do (Ubuntu and
> Fedora) and seeing how incompatible they are
> with my hardware, I've decided to take a minimalist
> approach and build the toolchain and kernel myself.
> However, I've run into snags, and the information
> on the Web seems fragmented and dispersed.
>
> Binutils seem to build without problems:
>
> mkdir /opt64
> tar zxfv binutils-2.18.tar.gz
> cd binutils-2.18
> ./configure --prefix=/opt64 --target=x86_64-pc-linux-gnu
> make
> make install
>
> However gcc builds only the first stage and
> at the end of that, it complains that it cannot
> create the binary, seemingly because it doesn't
> know the name for it (gcc).
>
> export CFLAGS='-Dinhibit_libc'
> export PATH=/opt64/bin:$PATH
> tar jxfv gcc-4.3.1.tar.bz2
> cd gcc-4.3.1
> ./configure --prefix=/opt64 --target=x86_64-pc-linux-gnu --enable-
> languages=c --disable-shared --disable-multilib --enable-
> threads=single --build=x86_64-pc-linux-gnu
> make

First of all, I rarely get down to gnu.misc.discuss, so I might not see any
replies.  Hey, I was somewhat bored.

Second another poster mentioned that you should not build in the source
directory.

Third, you probably need to get and install gmp-4.2.2 and mpfr-2.3.1 in order
to build the compiler.

Now, you really don't want to do this, unless you really know the build
process.  I am posting from a 64-bit Fedora 8 system.  I have installed 64-bit
Suse, Red Hat, Opensuse, Ubuntu, etc. systems from distributions.  They all
work fine.

What you have to do is build a complete cross compilation system from
your 32-bit system to a 64-bit system.  It's been awhile since I've built a
complete cross system (probably 2001 or so), so I might be skipping one or two
steps.

First you build a cross compiler, putting the compiler in a directory.  You
want an ordinary cross compiler in this step, so eliminate the --build
argument.  This will build a compiler that runs on the 32-bit system but
generates code for the 64-bit system.  A sample build would be:

$ cd /src
$ tar -xvjf gcc-4.3.1.tar.bz2
$ tar -xvjf gmp-4.2.2.tar.bz2
$ tar -xvjf mpfr-2.3.1.tar.bz2
$ tar -xvfj binutils-2.18.tar.bz2
$ tar -xvfj glibc-2.7.tar.bz2
$ tar -xvfj glibc-ports-2.7.tar.bz2
$ tar -xvfj glibc-linuxthreads-2.7.tar.bz2
$ cd /build
$ mkdir binutils-2.18 gmp-4.2.2 mpfr-2.3.1 gcc-4.3.1 glibc-2.7
$ cd binutils-2.18
$ /src/binutils-2.18/configure --prefix=/install/binutils-2.18 \
        --target=x86_64-pc-linux-gnu
$ make all && make install
$ cd ../gmp-4.2.2
$ /src/gmp-4.2.2/configure --disable-shared --prefix=/install/gmp-4.2.2
$ make all && make install
$ cd ../mpfr-2.3.1
$ /src/mpfr-2.3.1/configure --disable-shared --prefix=/install/mpfr-2.3.1 \
        --with-gmp=/install/gmp-4.2.2
$ make all && make install
$ cd ../gcc-4.3.1
$ export PATH=/install/binutils-2.18:$PATH
$ /src/gcc-4.3.1/configure --prefix=/install/gcc-4.3.1 \
        --with-gmp=/install/gmp-4.2.2 \
        --with-mpfr=/install/mpfr-2.3.1 \
        --target=x86_64-pc-linux-gnu \
        --with-gnu-as=/install/binutils-2.18/bin/x86_64-pc-linux-gnu-as \
        --with-gnu-ld=/install/binutils-2.18/bin/x86_64-pc-linux-gnu-ld \
        --with-sysroot=/install/glibc
$ make all && install

Assuming everything builds, and I'm not missing a step, you should now have a
cross compiler that generates 64-bit code as:
        /install/gcc-4.3.1/bin/x86_64-pc-linux-gnu-gcc

Now using that you have a cross compiler (but no libraries), you need to build
glibc with a cross compiler.  I tended to use newlib, but in theory you would
do:

$ cd ../glibc-2.7
$ export PATH=/install/gcc-4.3.1:$PATH
$ CC=/install/gcc-4.3.1/bin/x86_64-pc-linux-gnu-gcc /src/glibc-2.7/configure \
        --prefix=/install/glibc-2.7 \
        --target=x86_64-pc-linux-gnu
$ make all && make install

Ok, now you have a compiler and basic system library.  Now you need to build
your kernel.  I don't really remember the steps to build a linux kernel using a
cross compiler, but after some amount of futzing about you manage to do this.

Next you need to build the initial binaries that you need on your system (bash,
init, etc.).  All of these have to be build with the cross compiler.

Finally, assemble your disk with all of the binaries stored in their correct
location.  Configure grub or lilo to boot to your 64-bit kernel.  Unless you
are really lucky, they you will spend the next cycle debugging what went wrong
in the boot process, until eventually you can boot into your new system.

Next you need to rebuild the compiler toolchain so that it runs on your 64-bit
system.  This is where you will use the --build=x86_64-pc-linux-gnu option.
You will need the cross compiler in your path to do this second stage build.

Once you have the compiler running in 64-bit mode under your new kernel, then
you need to build everything that you want in your new distribution.

-- 
Michael Meissner
email: mrmnews@the-meissners.org
http://www.the-meissners.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]