[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 14:58:17 PDT 2017
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170503/d2f6c4d0/attachment.html>
More information about the llvm-dev
mailing list