English 中文(简体)
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).

问题回答

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.

Edit as of 2023-05-03: Latest released version gcc 13.1.0, binutils 2.40, gdb 13.1, cloog 0.18.1, isl 0.24, gmp 6.1.0, mpc 1.2.1, mpfr 4.1.0 all build together fine, at least for c,c++,fortran as the language set.

What you want to do is called a "combined tree" or "in-tree binutils" build. You can find documentation on how to proceed here and there.





相关问题
gcc -fPIC seems to muck with optimization flags

Following along from this question: how-do-i-check-if-gcc-is-performing-tail-recursion-optimization, I noticed that using gcc with -fPIC seems to destroy this optimization. I am creating a shared ...

Generate assembler code from C file in linux

I would like to know how to generate assembler code from a C program using Unix. I tried the gcc: gcc -c file.c I also used firstly cpp and then try as but I m getting errors. I m trying to build an ...

Getting rid of pre-compiled headers

OK, I have old Metrowerks code for Mac and Windows where the previous developer used pre-compiled headers for every project that this code base builds. How does one get rid of Pre-compiled headers, ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

How to compile for Mac OS X 10.5

I d like to compile my application for version 10.5 and forward. Ever since I upgraded to Snow Leopard and installed the latest XCode, gcc defaults to 10.6. I ve tried -isysroot /Developer/SDKs/...

热门标签