<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">On 12/22/15 4:45 AM, Russell Wallace
      via llvm-dev wrote:<br>
    </div>
    <blockquote
cite="mid:CAH+nB+wvcO2GbB4_Qfr-E2t8pw5ORV=i=2uHShyrZ2ZnS30v7g@mail.gmail.com"
      type="cite">
      <meta http-equiv="Context-Type" content="text/html; charset=UTF-8">
      <div dir="ltr">Oh, I just came across Function::hasAddressTaken.
        Maybe I can just use that instead?<br>
      </div>
    </blockquote>
    <br>
    You could conservatively assume that any function that has its
    address taken has a pointer to it that escapes into memory or
    external code.  To make things a little more accurate, you could
    scan the uses of any function for which hasAddressTaken() returns
    true and see if any of its uses escapes its function or escapes into
    memory or external code.  I believe hasAddressTaken() returns true
    if the function is subjected to a cast instruction, and functions
    are often casted if they are used in a call that uses a different
    signature than the function's declared signature.<br>
    <br>
    To get anything more accurate, you'll need to use alias analysis or
    points-to analysis.  DSA tracks function pointers in the heap and
    can tell you whether the function is called from external code. 
    However, DSA's accuracy currently suffers if it is run after LLVM's
    optimizations, and the code needs some serious TLC.<br>
    <br>
    Regards,<br>
    <br>
    John Criswell<br>
    <br>
    <blockquote
cite="mid:CAH+nB+wvcO2GbB4_Qfr-E2t8pw5ORV=i=2uHShyrZ2ZnS30v7g@mail.gmail.com"
      type="cite">
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Tue, Dec 22, 2015 at 5:11 AM,
          Russell Wallace <span dir="ltr"><<a moz-do-not-send="true"
              href="mailto:russell.wallace@gmail.com" target="_blank">russell.wallace@gmail.com</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote">
            <div dir="ltr">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).<br>
              <br>
              A starting point is to look at all the global variables:<br>
              <br>
                for (auto &G : M.globals())<br>
                  for (auto &V : G.operands())<br>
                    if (auto F = dyn_cast<Function>(V))<br>
              <br>
              Of course, instructions can also refer to functions, both
              as direct calls and otherwise:<br>
              <br>
                for (auto &F : M) {<br>
                  for (auto &I : inst_range(F)) {<br>
                    for (auto &V : I.operands())<br>
                      if (auto F = dyn_cast<Function>(V))<br>
              <br>
              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<br>
              <br>
                  if (F.hasPersonalityFn())<br>
              <br>
              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.<br>
              <br>
              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?<br>
              <br>
              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?<br>
              <br>
              Is there anything else I'm missing?<br>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>
<a class="moz-txt-link-freetext" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
John Criswell
Assistant Professor
Department of Computer Science, University of Rochester
<a class="moz-txt-link-freetext" href="http://www.cs.rochester.edu/u/criswell">http://www.cs.rochester.edu/u/criswell</a></pre>
  </body>
</html>