1

我想使用clang将httpd编译成 LLVM 字节码。首先,我尝试使用gcc对其进行编译,为此我执行了以下操作:

./configure --prefix=/home/varun/apache/httpd/gcc --with-included-apr
make
sudo make install

并且安装成功!

现在,我尝试使用 clang 编译它,为此我执行以下操作:

CC="clang" CFLAGS="-O4" ./configure --prefix=/home/varun/apache/httpd/clang --with-included-apr
make   # didn't come to this step
sudo make install # didn't come to this step

而且,配置本身失败。我选择了-O4,因为我读到 LLVM 输出字节码,如果你使用 -O4 或 -emit-llvm 作为 CFLAGS(它们都不工作)。

这是我得到的错误:

checking whether the C compiler works... no
configure: error: in `/home/varun/apache/httpd/httpd-2.4.3/srclib/apr':
configure: error: C compiler cannot create executables

这与链接器无法链接 LLVM 字节码文件有关吗?

4

3 回答 3

3

[我知道这与链接步骤有关,但无法正常工作。终于编译成功了,所以我在写我自己的答案]

方法 1(失败)

  1. 使用 Synaptic 包管理器在我的系统上安装了 clang。
  2. 安装了 binutils-gold,因为这是将 LLVMgold.so 作为插件提供给链接器所必需的。但是为此安装的clang,应该有gold插件。

尝试使用以下命令配置 httpd:

CC="clang" CFLAGS="-O4" ./configure --prefix=/home/varun/work/httpd/build --with-included-apr

这里,httpd 需要 --with-included-apr。-O4 是必需的,以便通过字节码进行编译。

此配置步骤本身失败,因为安装的 clang 没有适当的插件来使链接器能够链接字节码目标文件。

方法 2(成功)

  1. 安装 binutils-gold。也获得了binutils的源码。
  2. 编译LLVM,使用binutils源码编译,使LLVM拥有gold插件。

编译 LLVM,

../configure --with-binutils-include=/usr/src/binutils/binutils-2.22/include --enable-gold --prefix=/usr/local
make
sudo make install

ln -s /usr/local/lib/LLVMgold.so /usr/lib/bdf-plugins/LLVMgold.so

现在,编译httpd

CC="clang" CFLAGS="-O4" ./configure --prefix=/home/varun/work/httpd/build --with-included-apr
make
sudo make install
于 2012-12-13T06:16:18.013 回答
1

LLVM 字节码是 LLVM 中使用的中间表示。它不能由任何机器执行。这就是配置脚本抱怨的原因

C compiler cannot create executables.

不要输出 LLVM 字节码。尝试改用其他优化级别。(也不要使用-emit-llvmin CFLAGS)。

于 2012-12-13T03:54:51.330 回答
1

我在这里回答了一个非常相似的问题:

为 httpd 生成 LLVM IR

为大多数编写良好的项目构建 IR 实际上很容易。

我们工具的无耻插件:

https://github.com/SRI-CSL/whole-program-llvm

祝你好运。

于 2016-07-26T23:27:30.607 回答