[llvm-dev] How to instrument a module to spit out the addresses of global variables during initialization?
Dipanjan Das via llvm-dev
llvm-dev at lists.llvm.org
Wed May 3 15:50:36 PDT 2017
To be precise, I am not being able to insert any
appropriate builder.SetInsertPoint() call inside doInitialization() method.
On 3 May 2017 at 14:58, Dipanjan Das <mail.dipanjan.das at gmail.com> wrote:
>
> 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.
>
> ====================================================================
>
> bool doInitialization(Module &M) override {
> for (auto &global : M.getGlobalList()) {
> if (isa<GlobalVariable>(global)) {
> errs() << "[global]: " << global << '\n';
> auto &Ctx = M.getContext();
> IRBuilder<> builder(Ctx);
> Constant *instrument_func = M.getOrInsertFunction("instrument_global_variable",
> Type::getVoidTy(Ctx), Type::getInt64Ty(Ctx), NULL);
> Value* args[] = {global.getOperand(0)};
> builder.CreateCall(instrument_func, args);
> }
> }
> }
>
> ====================================================================
>
> 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.
>
> --
>
> Thanks & Regards,
> Dipanjan
>
--
Thanks & Regards,
Dipanjan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170503/b41c9899/attachment.html>
More information about the llvm-dev
mailing list