5.6.1 Clang

简介

Clang 一个基于 LLVM 的编译器前端,支持 C/C++/Objective-C 等语言。其开发目标是替代 GCC。

在软件安全的应用中,已经有许多代码分析工具都基于 Clang 和 LLVM,开发社区也都十分活跃。

初步使用

首先我们来编译安装 LLVM 和 Clang:

$ 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 前端的主要流程如下:

Driver -> Lex -> Parse -> Sema -> CodeGen (LLVM IR)

参考资料

results matching ""

    No results matching ""