Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

bootstrapping - Recipe for compiling binutils & gcc together?

According the the gcc build instructions you can build binutils concurrently with building gcc (as well as gmp,mpc,etc).

Here's what that page says :

If you also intend to build binutils (either to upgrade an existing installation or for use in place of the corresponding tools of your OS), unpack the binutils distribution either in the same directory or a separate one. In the latter case, add symbolic links to any components of the binutils you intend to build alongside the compiler (bfd, binutils, gas, gprof, ld, opcodes, ...) to the directory containing the GCC sources.

Likewise the GMP, MPFR and MPC libraries can be automatically built together with GCC. Unpack the GMP, MPFR and/or MPC source distributions in the directory containing the GCC sources and rename their directories to gmp, mpfr and mpc, respectively (or use symbolic links with the same name).

This works fine for gmp,mpc, mpfr, but I can't seem to get it to build all of binutils. Nor can I figure out how to get it to build the new gold linker from binutils. The versions in question are gcc-4.4.2 and binutils-2.20.

A step by step instruction would be great (for me, and for others who run into this issue as well).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This should still be supported OK, as it's commonly used for building cross-compilers.

In fact, I've just done this with gcc 4.6.0 and binutils 2.21 (with gmp, mpc and mpfr at appropriate versions), and the following seemed to work fine:

  • Get all the archives of the stuff you're going to build (gcc-4.6.0.tar.bz2, binutils-2.21.tar.bz2 etc) into a new dir, e.g. src
  • Un-tar them all in this directory, so you end up with gcc-4.6.0/ binutils-2.21/ gmp-5.0.2/ and more sitting alongside one another

    tar jxvf gcc-4.6.0.tar.bz2
    ... (unpack others here, watch file lists scroll past)
    
  • cd gcc-4.6.0 and symlink the gmp, mpc and mpfr directories without their version numbers in the links, e.g:

    ln -s ../gmp-5.0.2 gmp
    
  • Now symlink everything from the binutils dir which doesn't exist in the gcc dir, so anything which already exists will take priority but the binutils tools will look be visible to the build:

    for file in ../binutils-2.21/* ; do ln -s "${file}" ; done
    
  • Change up a dir and make a build directory to build all this in separately to the sources (this always used to be the recommended method, and it tends to still be more reliable than building inside the source dir):

    cd .. ; mkdir build
    
  • At this point you should have a set of directories and links which looks something like this:

    binutils-2.21/
    build/
    gcc-4.6.0/
       gmp -> ../gmp-5.0.2
       mpc -> ../mpc-0.9
       mpfr -> ../mpfr-3.0.1
       bfd -> ../binutils-2.21/bfd
       binutils -> ../binutils-2.21/binutils
       gas -> ../binutils-2.21/gas
       ... (lots more symlinks for binutils here, plus existing gcc stuff)
    gmp-5.0.2/
    mpc-0.9/
    mpfr-3.0.1/
    
  • Configure the whole lot from this dir, with whatever options you need to pass to configure:

    ../gcc-4.6.0/configure --prefix=/foo/bar --enable-languages=c,c++,ada
    
  • Build, wait, install (you'll probably want to use make -j4 or so here to get some builds in parallel as it's going to take a while) :

    make -j4 ; make install
    

Add the destination to your path if it's not already (and perhaps the lib dir to LD_LIBRARY_PATH if this is outside of those specified in /etc/ld.so.conf, as mentioned in the messages about installing libraries during the make install step), and everything should be up and running with this new version.

It's probably worth checking that you're using this installed version once you've opened a new shell, with :

    `which gcc`

and

    `which as`

..as well as that the version is as you expect with:

    `gcc --version`

and

    `as --version`

..as well as (of course) testing that the installed version builds executables fine with some simple examples before you let it loose on your code-base :)

Edit: The comments below contain some sets of versions which are known to work together. Not all combinations will work, so you might need to go through some trial and error for different combinations to those mentioned!

Much later edit: gdb is also possible to include in this build (again requires compatible component versions - see comments). Add this as the last thing after binutils in a similar way, using for f in ../gdb-8.1.1/* ; do ln -s "${f}" ; done and the build will automatically pick it up.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...