CTF-All-In-One/doc/5.5_clang.md

49 lines
1.5 KiB
Markdown
Raw Normal View History

2018-03-12 18:04:31 +07:00
# 5.5 Clang
- [简介](#简介)
- [初步使用](#初步使用)
2018-03-15 22:16:56 +07:00
- [内部实现](#内部实现)
2018-03-12 18:04:31 +07:00
- [参考资料](#参考资料)
## 简介
Clang 一个基于 LLVM 的编译器前端,支持 C/C++/Objective-C 等语言。其开发目标是替代 GCC。
2018-03-15 22:16:56 +07:00
在软件安全的应用中,已经有许多代码分析工具都基于 Clang 和 LLVM开发社区也都十分活跃。
2018-03-12 18:04:31 +07:00
## 初步使用
2018-03-15 22:16:56 +07:00
首先我们来编译安装 LLVM 和 Clang
```bash
$ 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
2018-03-18 15:45:52 +07:00
$ cmake -G Ninja ../
$ cmake --build .
$ cmake --build . --target install
2018-03-15 22:16:56 +07:00
```
## 内部实现
Clang 前端的主要流程如下:
```
2018-03-18 15:45:52 +07:00
Driver -> Lex -> Parse -> Sema -> CodeGen (LLVM IR)
2018-03-15 22:16:56 +07:00
```
2018-03-12 18:04:31 +07:00
## 参考资料
- [llvm documentation](http://llvm.org/docs/index.html)