将自动工具软件构建为LLVM位码 [英] Building autotooled software to LLVM bitcode

查看:129
本文介绍了将自动工具软件构建为LLVM位码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用autotools构建系统将软件编译为LLVM位代码;也就是说,我希望最后获得的可执行文件是LLVM位代码,而不是实际的机器代码.

I would like to compile software using the autotools build system to LLVM bitcode; that is, I would like the executables obtained at the end to be LLVM bitcode, not actual machine code.

(目标是能够在整个程序上运行LLVM位代码分析工具.)

(The goal is to be able to run LLVM bitcode analysis tools on the whole program.)

我尝试指定CC="clang -emit-llvm -use-gold-plugins"configure脚本的变体,但无济于事.总是有问题(例如,程序包构建了.a静态库,链接器拒绝了该库).

I've tried specifying CC="clang -emit-llvm -use-gold-plugins" and variants to the configure script, to no avail. There is always something going wrong (e.g. the package builds .a static libraries, which are refused by the linker).

在我看来,正确的做法是LLVM位代码应作为交叉编译的目标.可以使用--host=进行设置,但没有这样的标准目标(即使Knuth的MMIX有目标).

It seems to me that the correct way to do it would be that LLVM bitcode should be a cross-compilation target. to be set with --host=, but there is no such standard target (even though there is a target for Knuth's MMIX).

到目前为止,我已经使用了kludges,例如使用CC="clang -emit-llvm -use-gold-plugins"进行编译以及手动运行链接线(使用llvm-ldllvm-link).这适用于简单的程序包,例如grep.

So far I've used kludges, such as compiling with CC="clang -emit-llvm -use-gold-plugins" and running linking lines (using llvm-ld or llvm-link) manually. This works for simple packages such as grep.

我想要一种健壮的方法,该方法可用于大多数(即使不是全部)配置脚本,包括当存在中间.a文件或中间目标时.

I would like a method that's robust and works with most, if not all, configure scripts, including when there are intermediate .a files, or intermediate targets.

推荐答案

有些方法类似于 .但是对于不使用中间静态库的简单构建,则可以做一些简单的事情.您需要的东西清单是

There are some methods like this. But for simple builds where intermediate static libraries are not used, then you can do something simpler. The list of things you will need are

  1. llvm,配置了金牌插件支持.请参考
  2. c
  3. dragonegg,如果您需要fortran,go等的前端.

关键是在编译时和链接时都为clang或dragonegg(front-end)启用"-flto".对于clang来说很简单:

The key is to enable '-flto' for either clang or dragonegg(front-end), both at compile time and link time. It is straightforward for clang:

CC = clang
CLINKER = clang
CFLAGS = -flto -c
CLINKFLAGS = -flto -Wl,-plugin-opt=also-emit-llvm

如果需要,添加其他"-plugin-opt"选项以指定特定于llvm的代码生成选项:

If needed, add additional '-plugin-opt' option to specify llvm-specific codegen option:

-Wl,-plugin-opt=also-emit-llvm,-plugin-opt=-disable-fp-elim

转储的整个问题字节码将与最终的可执行文件一起存放.

The dumped whole problem bytecode would be sitting along with your final executable.

使用Dragonegg时还需要另外两件事.

Two additional things are needed when using dragonegg.

首先,dragonegg不知道llvm gold插件的位置,需要在链接器标志中指定它,例如-Wl,-plugin=/path/to/LLVMgold.so,-plugin-opt=...

First, the dragonegg is not aware of the location of llvm gold plugin, it needs to be specified in the linker flags like this -Wl,-plugin=/path/to/LLVMgold.so,-plugin-opt=...

第二,dragonegg仅能够转储IR,而不能转储字节码.为此,您需要一个包装器脚本.我在此处创建了一个.对我来说很好.

Second, dragonegg is only able to dump IR rather than bytecode. You need a wrapper script for that purpose. I created one here. Works fine for me.

这篇关于将自动工具软件构建为LLVM位码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆