afl中llvm_mode下的afl-llvm-pass.so.cc源码解析

本文档详细解析了AFL中用于LLVM Mode的afl-llvm-pass.so.cc源码,重点介绍了如何在基本块前插入计算代码的Pass。讲解了ModulePass的作用,以及LLVMContext、插桩率、全局变量和IRBuilder的使用。还阐述了如何计算边的编号,涉及到LLVM中的Load、Store、CreateZExt等指令,并展示了如何更新共享内存中的计数器。
摘要由CSDN通过智能技术生成

菜鸟入门,如有任何不当之处,烦请各位路过的大佬指正,不胜感激!(顺便吐槽一句llvm的官方文档对于一些基本信息的分布真的很不合理诶!)

总述

该文件完成的主要内容就是编写一个能在基本块前插入相关计算代码的pass。所以这里只是实现将计算代码插入到相应的位置的功能,并没有实质上完成边的编号计算。只有在实际运行中,程序运行到改变的到达块时,才开始计算该边的编号。

详细剖析

首先在匿名的命名空间中,定义一个继承自ModulePass的AFLCoverage类。而对于ModulePass的理解我们可以参考官网对其的介绍:

The ModulePass class is the most general of all superclasses that you can use. Deriving from ModulePass indicates that your pass uses the entire program as a unit, referring to function bodies in no predictable order, or adding and removing functions.

因此选择继承不同类型的Pass父类就是从不同的粒度对程序进行处理。这里选择继承ModulePass就是对整个程序都进行处理。

 namespace {
   
    class AFLCoverage : public ModulePass {
   

然后在类外对类中的静态成员变量ID进行定义及初始化。该变量是pass标识符,即LLVM用于标识pass的。同时,在类外定义runOnModule()函数,该函数内容便是实现真正需求的部分。

char AFLCoverage::ID = 0;                                                                                                                                              

bool AFLCoverage::runOnModule(Module &M) {
   

然后获取LLVMContext。关于LLVMContext:

This is an important class for using LLVM in a threaded context. It (opaquely) owns and manages the core “global” data of LLVM’s core infrastructure, including the type and constant uniquing tables.
LLVMContext itself provides no locking guarantees, so you should be careful to have one context per thread.

LLVMContext &C = M.getContext();

然后获取插桩率来决定插桩密度。

char* inst_ratio_str = getenv("AFL_INST_RATIO");
unsigned int inst
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值