2

I am trying to build a gcc cross compiler. I understand that before compiling the cross compiler I need to have the target binutils built already. why the building of the compiler need the target binutils ? the compiler alone only takes high level code and turn it to the assembly that I defined it in the compiler sources. so why do I need the target bintools for compiling the cross compiler ? It is written in all of the cross compiler documentation that I need them to be build before compiling the cross compiler. (e.g. http://wiki.osdev.org/Building_GCC and http://www.ifp.illinois.edu/~nakazato/tips/xgcc.html).

3 Answers 3

2

GCC needs an assembler to transform the assembly it generates into object files (machine code), and a linker to link object files together to produce executables and shared libraries. It also needs an archiver to produce static libraries/archives.

Those three are usually provided by the binutils package (among other useful tools): the GNU assembler as, linker ld and the ar archiver.

Sign up to request clarification or add additional context in comments.

6 Comments

I am compiling the cross compiler on linux and it will run on linux but will produce exe file for other machine (host != linux). So when I compile the cross compiler I need to use the as and ld of the current OS that I am in. So in my understanding ,in order to compile the cross compiler I do not need the host binutils. I only need the host bintools whenever I want to compile sources for the host, and than the output from the cross compiler while have to use as and ld for the host. So my qeustion is, why do I need them before compiling the cross compiler ?
You need at least the assembler to build things like crt*.o for the target, and probably linker too (esp. if you're going to build the C++ standard library).
Ok , I understand that when compiling sources for the target I need the target bintools but it doesn't answer the question why do I need them to build the cross compiler. I am not going to run the cross compiler on the target... I run it on the host but take the exe file it generate and run them on the target.... BTW in the above comment when I wrote host I meant target.
The C runtime "startup"/teardown files crt*.o are in target machine code. They don't run on the host, they're linked into target binaries. And they're not built each time you compile some code, they're built as part of the (cross-)compiler.
So what you are saying is that I need the target bintools in order to link the crt.o files. And that is done when building the cross compiler ?! BTW it can't be object file because it means that crt file already compiled, but how they compiled without the cross compiler to specify the available instructions ?
|
1

Your key question seems to be:

why the building of the compiler need the target binutils ?

As described in Building a cross compiler, part of the build process for a GNU cross-compiler is to build runtime libraries for the target using the newly-compiled cross-compiler. So the binutils for the target need to be present for that step to succeed.

It may be possible to build the cross-compiler first, using empty files for the subset of binutils components that gcc needs - such as as and ld and ar and ranlib - then build and install the target binutils components into the proper locations, then build the target runtime libraries.

But it would be less error-prone to do things the following way (and the documentation recommends this): build binutils for the target first, place the specified executables in gcc's source tree, then build the cross-compiler.

Comments

0

The binutils (binary utilities) provide low-level handling of binary files, such as linking, assembling, and parsing ELF files. The GCC compiler depends on these tools to create an executable, because it generates object files that binutils assemble into an executable image.

ELF is the format that Linux uses for binary executable files. The GCC compiler relies on binutils to provide much of the platform-specific functionality.

Here your are cross-compiling for some other architecture not for x86. So resulting binutils are platform-specific

while configuring has to give --host!=target. i.e --host=i686-pc-linux-gnu where --target=arm-none-linux-gnueabi. So resulting executable are not same which host already having binutils.

addition the basic things needs to be known.

The build machine, where the toolchain is built.

The host machine, where the toolchain will be executed.

The target machine, where the binaries created by the toolchain are executed.

So binutils will be having tools to generate and manipulate binaries for a given CPU architecture. Not for the one host is using

1 Comment

I think you misunderstood me - why do I need the target bintools before I can compile the cross compiler ?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.