<div dir="ltr"><div><br></div><div>My objective is to instrument a module such that the addresses of all global variables are printed out BEFORE even any real code is executed, i.e. during module initialization. I slipped in the following code snippet in the doIntialization() method of a FunctionPass. Unfortunately, I can't see any code inserted in the IR generated.</div><div><br></div><div>====================================================================</div><div><br></div><div><div>bool doInitialization(Module &M) override {</div><div>        for (auto &global : M.getGlobalList()) {</div><div>            if (isa<GlobalVariable>(global)) {</div><div>                errs() << "[global]: " << global << '\n';</div><div>                auto &Ctx = M.getContext();</div><div>                IRBuilder<> builder(Ctx);</div><div>                Constant *instrument_func = M.getOrInsertFunction("instrument_global_variable", Type::getVoidTy(Ctx), Type::getInt64Ty(Ctx), NULL);</div><div>                Value* args[] = {global.getOperand(0)};</div><div>                builder.CreateCall(instrument_func, args);</div><div>            }</div><div>        }</div><div>    }</div></div><br clear="all"><div>====================================================================<br></div><div><br></div><div>The code above yields a pass which, when executed against application bitcode, prints out all the global variables (because of the errs() statement) correctly. However, I can't collect the address information at run-time.</div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><span><div><div dir="ltr"><p>Thanks & Regards,</p>
<div>Dipanjan</div></div></div></span></div></div>
</div>