2

There is a term that compiler bootstrapping which fundamentally means compiling a new compiler with old compiled compiler. For example, even GCC is firstly compiling by a little part of GCC and so forth.

So, the question, is LLVM/Clang bootstrapped/compiled by another compiler like GCC or written from scratch and if, basically how? I can see some traces of GCC in LLVM library intuitively but I couldn't find exact proper information about that.

Celuk
  • 561
  • 7
  • 17

1 Answers1

2

No. LLVM can be compiled using any of a large number of compilers. When I cared about such things there were dozens of independent compilers. (Remember that only correctness matters — you can bootstrap using even the slowest compiler, that produces the slowest output and has shitty diagnostics.)

This legend has a basis though: On many systems, LLVM asks GCC about how to invoke the system linker, which can be fiddly.

arnt
  • 8,949
  • 5
  • 24
  • 32
  • Thanks for your answer, I understood that we can compile any LLVM project with any compiler but for example doesn't Clang have a predefined compiler? When I installed Clang as a package directly (not cloning and building library) to my pc (e.g. on linux `sudo apt install clang`) isn't it already compiled by another compiler like gcc or that I don't know? Actually, that is what I intended to ask in the broad sense. – Celuk Jul 02 '21 at 08:35
  • 2
    It's compiled by something or other. It may have been compiled by clang, even, either the previous version of the same debian package or by cross-compiling from another platform. These things usually involve several steps and can be quite tricky. – arnt Jul 02 '21 at 11:50
  • 2
    An example: Suppose you need clang for FumbleOS, and you have no compiler at all there. But you have a laptop running Windows. So you build clang on Windows (using Microsoft's compiler, or a clang you downloaded). When you see that that works, you change clang's CMakeLists.txt to compile for FumbleOS instead of Windows, and build clang again, producing a compiler for FumbleOS that runs on Windows. Next you use the second clang to build clang a third time, producing a FumbleOS executable that you can transfer from your laptop to the target. Tricky, but possible from almost any starting point. – arnt Oct 21 '21 at 15:10