我正在尝试使用lli
解释/JIT 编译a.bc
使用共享对象中定义的函数的位码文件afl-llvm-rt.so
。当我尝试像这样使用 lli
lli -dlopen ./afl-llvm-rt.so a.bc
我得到:
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: lli -load ./afl-llvm-rt.o a.bc
#0 0x00007fa2a620f833 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xa99833)
#1 0x00007fa2a620dbe0 llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xa97be0)
#2 0x00007fa2a620fe65 (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xa99e65)
#3 0x00007fa2a57683c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
zsh: segmentation fault (core dumped) lli -load ./afl-llvm-rt.o a.bc
进一步调查gdb
显示未设置函数地址:
> gdb lli
(gdb) r -load ./afl-llvm-rt.o a.bc
Starting program: /usr/bin/lli -load ./afl-llvm-rt.o a.bc
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x00007ffff7fca021 in sancov.module_ctor_trace_pc_guard ()
#2 0x00007ffff4f46118 in llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) () from /lib/x86_64-linux-gnu/libLLVM-12.so.1
#3 0x00007ffff4ef9a57 in llvm::ExecutionEngine::runStaticConstructorsDestructors(llvm::Module&, bool) () from /lib/x86_64-linux-gnu/libLLVM-12.so.1
#4 0x00007ffff4f4587f in llvm::MCJIT::runStaticConstructorsDestructors(bool)
() from /lib/x86_64-linux-gnu/libLLVM-12.so.1
#5 0x000000000041391b in main ()
但是,如果我像往常一样编译文件clang a.bc ./afl-llvm-rt.so
,输出可执行文件就可以了。
如何进行动态lli
链接?a.bc
afl-llvm-rt.so
编辑:我编译afl-llvm-rt.so
为 LLVM IR 文件,然后我llvm-link a.bc afl-llvm-rt.bc -o result.bc
将它们链接在一起。之后,我尝试lli result.bc
了,它给出了以下内容:
ocelaiwo@E490:~/Misc/ff> lli result.bc
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: lli result.bc
#0 0x00007efc8d3d9833 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xa99833)
#1 0x00007efc8d3d7be0 llvm::sys::RunSignalHandlers() (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xa97be0)
#2 0x00007efc8d3d9e65 (/lib/x86_64-linux-gnu/libLLVM-12.so.1+0xa99e65)
#3 0x00007efc8c9323c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x153c0)
zsh: segmentation fault (core dumped) lli result.bc
但如果 I clang result.bc -o result
,result
可执行文件执行得很好。