5

I currently try to understand how cross-compilers work. I'm a bit confused about the two-staged compiler compilation process.

As far as I read, the following procedure is applied:

  • Compile bintutils for the target architecture
  • Compile GCC (stage 1)
  • Compile newlib/eglibc/... with GCC
  • Compile GCC with the libc (stage 2)

Why is there a second stage involved? Couldn't I just invoke the first stage compiler with some flag like -lc to include libc?

Martin
  • 295
  • 1
  • 3
  • 12

1 Answers1

0

I'm not sure why gcc has such a complicated build process. My clang/LLVM based ELLCC (http://ellcc.org) cross tool chain project builds like this:

  1. Compile the compiler (using either gcc or a pre-built version of the ELLCC compiler available from the web site.).
  2. Use the compiler to build the C++ and C libraries for all targets.
  3. Build binutils and gdb for all targets (for all targets: don't make target specific utilitities except for the assemblers. ld, gdb, objdump, etc. all support this)
  4. (optional) Use your newly built compiler to cross build itself for all the targets.

BTW, ELLCC currently supports ARM, Microblaze, Mips, PowerPC, and x86 targets for Linux and bare metal execution environments.

Richard Pennington
  • 19,673
  • 4
  • 43
  • 72
  • Richard: I am running into problems trying to build a simple "hello world" program on Windows. I get "ecc.exe: error: unable to execute command: Couldn't execute program 'C:\ellcc\ellcc\bin/ecc-ld.exe'Unknown error" – Raman Sharma Dec 17 '14 at 18:48
  • Raman: Apparently it has something to do with how the files are untar-ed: https://sites.google.com/a/gautherot.net/www/introdcttioellcc – Richard Pennington Dec 17 '14 at 19:55
  • Ah yes. That fixed it. I noticed that what it produces on Windows is a static binary. Is there something that would link dynamically to the various runtimes like CRT etc.? – Raman Sharma Dec 17 '14 at 23:22
  • Sorry, currently I am only making static libraries. Eventually I'd like to add .so support. The C library, musl, does support dynamic, I just haven't gotten around to building it that way. – Richard Pennington Dec 17 '14 at 23:31
  • Richard: Another question. So when I building using this compiler on Windows, which C Library do you link to? – Raman Sharma Jan 15 '15 at 01:47
  • Raman: The compiler comes with a bunch of C and C++ libraries built for the specific target. They are located in ellcc/libecc/lib. – Richard Pennington Jan 15 '15 at 02:05
  • Yeah, what I was wondering was how did you actually build those libraries. Are there any instructions somewhere? Also, do you not build gdbserver with your tools? – Raman Sharma Jan 15 '15 at 03:15
  • To build the libraries, go to "ellcc/libecc" and type "make". I had some issues building GDB server, and haven't gotten around to figuring them out yet. – Richard Pennington Jan 15 '15 at 16:29
  • Richard: I am kinda stuck here. I am trying to use the cross-built toolchain to remote debug from Windows to Linux. The problem I am facing is that the gdb client which comes as a part of your distribution needs to be built with expat enabled (thanks google!) in order to work correctly with the gdbserver on my remote Linux machine. However I am at a loss trying to figure out how to build the gdb from your sources with that option enabled. – Raman Sharma Jan 16 '15 at 08:26