<div dir="ltr">Hi Philip,<div><br></div><div>could you please explain what do you mean by `return PC on the stack`, is it the value in the rip (instruction pointer) after I call foo() from main()?</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Kavindu Gimhan Zoysa,</div><div>BSc(Hons) | ENTC | UoM,<br></div><div dir="ltr">SSE | WSO2<div><br></div><div><a href="https://github.com/KavinduZoysa" target="_blank">GitHub</a> <a href="https://www.linkedin.com/in/kavindu-gimhan-zoysa-85939a122/" target="_blank">LinkedIn</a> <a href="https://medium.com/@kavindugimhanzoysa" target="_blank">Medium</a></div></div></div></div></div></div></div></div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 20 May 2021 at 22:27, Philip Reames <<a href="mailto:listmail@philipreames.com">listmail@philipreames.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
  
    
  
  <div>
    <p>This is out of scope for LLVM, but let me give you a high level
      summary.</p>
    <p>Your GC needs to be able to walk all stack frames on the stack at
      point of suspension.  This can be done by using libunwind,
      manually writing your own stack crawler, etc..</p>
    <p>Once you have the ability to walk the stack, each return PC on
      the stack will correspond to a stack map entry in the stack map
      section.  In this case, the return PC for the foo call will
      correspond to an entry in that section.  All of the offsets in
      that entry refer to the frame corresponding to main.  Your stack
      walker must be able to turn those into actual addresses.</p>
    <p>For callee saved registers - which I *think* is the case you're
      actually asking about - , you can either a) disable that by
      tweaking your copy of LLVM, or b) use the callee saved register
      information generated for eh_frame to translate CSRs into their
      spill locations.  If you want to avoid dealing with this, look at
      the "no_callee_saved_registers" function attribute.  It's a very
      blunt hammer, but you can come back later and refine.  <br>
    </p>
    <p>This is a pretty standard GC implementation technique.  Any off
      the shelf GC you use should already be able to do this.</p>
    <p>Philip<br>
    </p>
    <div>On 5/20/21 7:50 AM, Kavindu Gimhan
      Zoysa via llvm-dev wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div dir="ltr">
        <div>Hi all,</div>
        <div><br>
        </div>
        <div>Let's say I have an example like this</div>
        <div><br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><i>fn
            foo() {<br>
                 heapRef2 = getHeapRef()<br>
                 readStackMap()<br>
            }<br>
            fn main() {<br>
                heapRef1 = getHeapRef()<br>
                foo();<br>
            }</i></blockquote>
        <div><br>
        </div>
        <div>When we start to read stack map in foo(), our stack has two
          heap references (heapRef1 and heapRef2). From the LLVM stack
          map we can get the location of <b>heapRef2</b>, using let's
          say rsp + offset. </div>
        <div><br>
        </div>
        <div>But, When we consider about <b>heapRef1, </b>its' offset
          is given with respect to its' function(main) rsp or rbp.<b> </b>But
          at this moment those registers are pointed to foo()'s stack
          frame locations. There fore how do we get the location of <b>heapRef1?</b></div>
        <div><br>
        </div>
        <div>Highly appreciate your input on this.</div>
        <div><br>
        </div>
        <div>Thank you,</div>
        <div>Kavindu</div>
        <br clear="all">
        <div>
          <div dir="ltr">
            <div dir="ltr">
              <div dir="ltr">
                <div dir="ltr">
                  <div dir="ltr">
                    <div>Kavindu Gimhan Zoysa,</div>
                    <div>BSc(Hons) | ENTC | UoM,<br>
                    </div>
                    <div dir="ltr">SSE | WSO2
                      <div><br>
                      </div>
                      <div><a href="https://github.com/KavinduZoysa" target="_blank">GitHub</a> <a href="https://www.linkedin.com/in/kavindu-gimhan-zoysa-85939a122/" target="_blank">LinkedIn</a> <a href="https://medium.com/@kavindugimhanzoysa" target="_blank">Medium</a></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>_______________________________________________
LLVM Developers mailing list
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
  </div>

</blockquote></div>