CTF-All-In-One/doc/5.6.1_clang.md
2018-08-05 17:43:10 +08:00

51 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 5.6.1 Clang
- [简介](#简介)
- [初步使用](#初步使用)
- [内部实现](#内部实现)
- [参考资料](#参考资料)
## 简介
Clang 一个基于 LLVM 的编译器前端,支持 C/C++/Objective-C 等语言。其开发目标是替代 GCC。
在软件安全的应用中,已经有许多代码分析工具都基于 Clang 和 LLVM开发社区也都十分活跃。
## 初步使用
首先我们来编译安装 LLVM 和 Clang
```text
$ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
$ cd llvm/tools
$ svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
$ svn co http://llvm.org/svn/llvm-project/lld/trunk lld # optional
$ svn co http://llvm.org/svn/llvm-project/polly/trunk polly # optional
$ cd clang/tools
$ svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra # optional
$ cd ../../../.. && cd llvm/projects
$ svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt # optional
$ svn co http://llvm.org/svn/llvm-project/openmp/trunk openmp # optional
$ svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx # optional
$ svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi # optional
$ svn co http://llvm.org/svn/llvm-project/test-suite/trunk test-suite # optional
$ cd ../.. && cd llvm
$
$ mkdir build && cd build
$ cmake -G Ninja ../
$ cmake --build .
$ cmake --build . --target install
```
## 内部实现
Clang 前端的主要流程如下:
```text
Driver -> Lex -> Parse -> Sema -> CodeGen (LLVM IR)
```
## 参考资料
- [llvm documentation](http://llvm.org/docs/index.html)