<div dir="ltr"><br><div>To be precise, I am not being able to insert any appropriate builder.SetInsertPoint() call inside doInitialization() method.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 3 May 2017 at 14:58, Dipanjan Das <span dir="ltr"><<a href="mailto:mail.dipanjan.das@gmail.com" target="_blank">mail.dipanjan.das@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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>==============================<wbr>==============================<wbr>========</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("<wbr>instrument_global_variable", Type::getVoidTy(Ctx), Type::getInt64Ty(Ctx), NULL);</div><div>                Value* args[] = {global.getOperand(0)};</div><div>                builder.CreateCall(instrument_<wbr>func, args);</div><div>            }</div><div>        }</div><div>    }</div></div><br clear="all"><div>==============================<wbr>==============================<wbr>========<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><span class="HOEnZb"><font color="#888888"><div><br></div>-- <br><div class="m_-2590656028524671879gmail_signature"><div dir="ltr"><span><div><div dir="ltr"><p>Thanks & Regards,</p>
<div>Dipanjan</div></div></div></span></div></div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span><div><div dir="ltr"><p>Thanks & Regards,</p>
<div>Dipanjan</div></div></div></span></div></div>
</div>