Can someone explain what is the difference between compiler and compiler driver in LLVM?
Any help is appreciated.
the compiler
is a part of the integral compilation process; the compiler driver
is the concatenation and manager of the compilation process.
But we usually confuse these two concepts and call them compiler.
A compiler consists of multiple parts, and when a program source is compiled into an executable, it goes through a number of different steps.Source code -> preprocessing -> compilation -> assembly -> linking
.
Different compiler components are in charge of different stages.
For example, compilation is in charge of the Compiler
(cc1
for c, cc1plus
for cxx, cc1obj
for Objective-C etc.) (where cc1
, cc1plus
, cc1obj
, etc. are really the Compilers
. The Compiler
uses source code as inputs and output as assembly code).as
is responsible for transforming assembly code to binary code, and the ld
is responsible for linking.
In order to facilitate the process, we usually only useclang hello.c -o hello
to complete the construction of a c source to the final executable.
But in fact, in this process, clang
is the compiler driver
, which connects the entire compilation process in an automated way. It does a lot of work, it calls every tool in the compiler with the appropriate parameters and order, and eventually produces an executable file.
the detailed parameters of the clang hello.c -o hello
command can be seen by command clang hello.c -o hello -v
And on my terminal, it displays:
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/huangshaomang/research/LLVM/ollvmsimon/build/bin
"/home/huangshaomang/research/LLVM/build/bin/clang-8" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-emit-obj" "-mrelax-all" "-disable-free" "-main-file-name" "hello.c" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-resource-dir" "/home/huangshaomang/research/LLVM/build/lib/clang/8.0.0" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/home/huangshaomang/research/LLVM/build/lib/clang/8.0.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdebug-compilation-dir" "/home/huangshaomang/research/linker_loader/test_constructor" "-ferror-limit" "19" "-fmessage-length" "233" "-fobjc-runtime=gcc" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-o" "/tmp/hello-5168fe.o" "-x" "c" "hello.c" "-faddrsig"
"/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "hello" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crt1.o" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/crtbegin.o" "-L/usr/lib/gcc/x86_64-linux-gnu/5.4.0" "-L/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu" "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../.." "-L/home/huangshaomang/research/LLVM/build/bin/../lib" "-L/lib" "-L/usr/lib" "/tmp/hello-5168fe.o" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/crtend.o" "/usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../x86_64-linux-gnu/crtn.o"
It is clear, clang
(the compiler driver
) called two tools (cc1
(the Compiler
) and ld
(the linker
)) in turn with very complex parameters.
Also, In the following links, llvm-project used the term 'compiler driver', which may help you understand it better.
https://llvm.org/docs/HowToCrossCompileLLVM.html
https://llvm.org/docs/LinkTimeOptimization.html
I guess, compiler refers to compiler as a whole, while compiler driver corresponds to logic that drives compilation pipeline. Driver task is to call right tools for various files (for example, clang
calls cc1
for C/C++ sources, ld
for object files, etc.) and to set proper flags for them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With