fla*_*urn 5 compiler-construction llvm
有人可以解释一下 LLVM 中编译器和编译器驱动程序之间的区别吗?
任何帮助表示赞赏。
小智 6
的compiler是积分编译过程的一部分; 的compiler driver是编译过程的级联和经理。
但我们通常会将这两个概念混淆,称它们为编译器。
编译器由多个部分组成,当程序源被编译成可执行文件时,它会经历许多不同的步骤。
Source code -> preprocessing -> compilation -> assembly -> linking.
不同的编译器组件负责不同的阶段。
例如,编译是在充电Compiler(cc1为C,cc1plus对于CXX,cc1obj对目标C等)(其中cc1,cc1plus,cc1obj等都是真的Compilers。该Compiler用途的源代码作为输入,并且作为汇编代码输出)。
as负责将汇编代码转换为二进制代码,并ld负责链接。
为了方便这个过程,我们通常只使用
clang hello.c -o hello
ac源码来完成构建到最终的可执行文件。
但实际上,在这个过程中,clang是compiler driver,以自动化的方式连接了整个编译过程。它做了很多工作,它以适当的参数和顺序调用编译器中的每个工具,并最终生成一个可执行文件。
clang hello.c -o hello命令的详细参数可以通过命令查看clang hello.c -o hello -v
在我的终端上,它显示:
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"
Run Code Online (Sandbox Code Playgroud)
很明显,clang(the compiler driver)依次调用了两个工具( cc1(the Compiler) 和ld(the linker)) 并带有非常复杂的参数。
另外,在以下链接中,llvm-project 使用了术语“编译器驱动程序”,这可能有助于您更好地理解它。
https://llvm.org/docs/HowToCrossCompileLLVM.html
https://llvm.org/docs/LinkTimeOptimization.html
我想,编译器是指整个编译器,而编译器驱动程序对应于驱动编译管道的逻辑。驱动程序的任务是为各种文件调用正确的工具(例如,clang调用cc1C/C++ 源代码、ld目标文件等)并为它们设置正确的标志。
| 归档时间: |
|
| 查看次数: |
1998 次 |
| 最近记录: |