[llvm-dev] Finding all pointers to functions

Russell Wallace via llvm-dev llvm-dev at lists.llvm.org
Mon Dec 21 21:11:22 PST 2015


I need to track down all pointers anywhere in a module that could be
pointing to functions (because some of the optimizations I want to do,
require either identifying every use of a function, or conservatively
identifying when such cannot be done).

A starting point is to look at all the global variables:

  for (auto &G : M.globals())
    for (auto &V : G.operands())
      if (auto F = dyn_cast<Function>(V))

Of course, instructions can also refer to functions, both as direct calls
and otherwise:

  for (auto &F : M) {
    for (auto &I : inst_range(F)) {
      for (auto &V : I.operands())
        if (auto F = dyn_cast<Function>(V))

But there are other things as well, for example it seems there is something
called a personality function that can be a pointer to another function, so
need to add that

    if (F.hasPersonalityFn())

It seems there are other things called prefix data and prologue data, which
are pointers to constants, which could contain pointers to functions, so
would need to include those as well.

Am I correct in thinking that prefix data and prologue data will not be
included in the global variables list, so do need special handling?

Could they be recursive? That is, could those constants contain pointers to
other constants... which end up containing pointers to functions... such
that none of the intermediate constant objects are in the global variable
list?

Is there anything else I'm missing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20151222/d1dd5ce0/attachment.html>


More information about the llvm-dev mailing list