如何生成LLVM位码
How to generate LLVM bitcode
我想生成位码文件(.bc),因为它写在文档中:
安全
#include <stdio.h>
int main() {
printf("hello worldn");
return 0;
}
然后
% clang -O3 -emit-llvm hello.c -c -o hello.bc
和
% lli hello.bc
来运行代码,但是我有奇怪的输出:
lli: Attributes.cpp:367: static llvm::AttrListPtr llvm::AttrListPtr::get(llvm::LLVMContext &, ArrayRef<llvm::AttributeWithIndex>): Assertion `Attrs[i].Attrs.hasAttributes() && "Pointless attribute!"' failed.
0 lli 0x0000000000c944ff
1 lli 0x0000000000c94a79
2 libpthread.so.0 0x00007fbf12a88060
3 libc.so.6 0x00007fbf11d663e5 gsignal + 53
4 libc.so.6 0x00007fbf11d69b4b abort + 379
5 libc.so.6 0x00007fbf11d5ed8d __assert_fail + 221
6 lli 0x0000000000b8b285 llvm::AttrListPtr::get(llvm::LLVMContext&, llvm::ArrayRef<llvm::AttributeWithIndex>) + 517
7 lli 0x000000000051f14e llvm::BitcodeReader::ParseAttributeBlock() + 494
8 lli 0x00000000005249f1 llvm::BitcodeReader::ParseModule(bool) + 497
9 lli 0x0000000000526617 llvm::BitcodeReader::ParseBitcodeInto(llvm::Module*) + 359
10 lli 0x000000000052eae9 llvm::getLazyBitcodeModule(llvm::MemoryBuffer*, llvm::LLVMContext&, std::string*) + 569
11 lli 0x000000000052ee3f llvm::ParseBitcodeFile(llvm::MemoryBuffer*, llvm::LLVMContext&, std::string*) + 15
12 lli 0x00000000004ea29a llvm::ParseIR(llvm::MemoryBuffer*, llvm::SMDiagnostic&, llvm::LLVMContext&) + 170
13 lli 0x00000000004e7078 llvm::ParseIRFile(std::string const&, llvm::SMDiagnostic&, llvm::LLVMContext&) + 536
14 lli 0x00000000004e3a58 main + 312
15 libc.so.6 0x00007fbf11d5130d __libc_start_main + 237
16 lli 0x00000000004e1f49
Stack dump:
0. Program arguments: lli hello.bc
Aborted
有什么问题?为什么它不起作用?
这可能是您的特定LLVM/Clang版本的问题。您是否在启用断言的情况下从源代码编译它?您只需要获得修复该错误的新版本。(参见http://llvm.org/bugs/show_bug.cgi?id=15786查看旧版本的类似断言失败报告。)
FWIW -该程序在我的本地SVN构建(clang版本3.4 (trunk 182672))上运行良好。
相关文章:
- 将尾部调用void(i32,..)位转换为llvm::函数以获取FnAttribute
- 位移操作和位掩码未检测到重复字符
- 生成前缀位掩码
- 如何从__m64值的 lsb 创建 8 位掩码?
- 如何对无符号长 int 进行位掩码?
- 如何在C++中优雅地处理位掩码
- 将uint64_t位掩码转换为 std::布尔数组
- 优化从子位掩码生成父位掩码
- 如何链接两个LLVM位码模块?
- 基于模式创建位掩码作为 constexpr
- 如何从CPP源代码行号中获取LLVM位码行号?
- C++中的运行时位复制(位掩码)
- LLVM 的位码错误检测函数参数
- 递归函数,用于使用位掩码 c++ 显示集合的所有子集
- 字符串到 Unicode,Unicode 到十进制码位 (C++)
- 位掩码,用于确定数字是正数还是负数 c++
- 如何识别 LLVM 位码中的循环
- 将 LLVM 位码加载到模块中:无法将"std::unique_ptr<llvm::Module>"转换为"llvm::Module*"
- 如何生成LLVM位码
- Clang -编译一个C头到LLVM IR/位码