[LLVMdev] Copy function pointer contents

Calixte Denizet calixte.denizet at scilab-enterprises.com
Tue Oct 21 08:04:35 PDT 2014


Is it safe to copy a function pointer contents from an ObjectImage ?
I made something like:

void (*fptr)() = nullptr;
llvm::object::symbol_iterator i = obj.begin_symbols();
if (!i->getType(type) && type == llvm::object::SymbolRef::ST_Function)
   llvm::StringRef name;
   uint64_t addr, size;
   if (!i->getName(name) && !i->getAddress(addr) && !i->getSize(size))
      llvm::sys::MemoryBlock mem = llvm::sys::Memory::AllocateRWX(size, 
      memcpy(mem.base(), (void *)addr, size);
      fptr = reinterpret_cast<void(*)()>(mem.base());

My first experiments shew that it works but I'd like to know it could 
have any side effects?
My goal is to delete a finalized module and just keep the copyed 
function (to decrease the memory use)

Best regards,


Calixte Denizet
Software Development Engineer
Scilab Enterprises
143bis rue Yves Le Coz - 78000 Versailles, France

More information about the llvm-dev mailing list