<div dir="ltr"><div dir="ltr"><div dir="ltr">Thanks for your reply.<div><br></div><div>What I want to do is that check the return address at every return site (for some security issue) . <br><div><br></div><div>(I will also do some analysis to get some candidate return target)</div><div><br></div><div>So the "ret" instruction will be transformed to </div></div><div><br></div><div>mov eax,[esp] // get the return address at the top of stack</div><div>cmp eax,0x08040000 // candidate 1</div><div>je 0x08040000</div><div>cmp eax,0x08040004 // candidate 2</div><div>je 0x08040004</div><div>cmp eax,0x08040008 // candidate 3</div><div>je 0x08040008</div><div><br></div><div>So if I want to do this transform at llvm ir level rather than backend,</div><div><br></div><div>I need to get the return address of current function in FunctionPass, right?</div><div><br></div><div>I found that intrinisc::returnaddress only returns a *void pointer. </div><div><br></div><div>c code:</div><div><br></div><div><div>int main(){</div><div> int a = __builtin_return_address(0);</div><div>}</div></div><div><br></div><div>llvm ir:</div><div><br></div><div><div>define i32 @main() #0 {</div><div>entry:</div><div> %a = alloca i32, align 4</div><div> %0 = call i8* @llvm.returnaddress(i32 0)</div><div> %1 = ptrtoint i8* %0 to i32</div><div> store i32 %1, i32* %a, align 4</div><div> ret i32 0</div><div>}</div></div><div><br></div><div>Can I use the return value of intrinisc::returnaddress to compare with "Function" class in llvm ir?</div><div><br></div><div>(Otherwise, I need to modify backend to do my intrumentation.)</div><div><br></div><div>Thanks</div></div></div></div><br><div class="gmail_quote"><div dir="ltr">Bekket McClane <<a href="mailto:bekket.mcclane@gmail.com">bekket.mcclane@gmail.com</a>> 於 2018年9月5日 週三 下午9:41寫道:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Correct...you can always call that intrinsic explicitly. However, I don't think it would help the original question, since the question is how to get the return address inside a LLVM Pass, instead of getting the return address after executing the program with Intrinsic::returnaddress inside.</div><div>Also, executing a program containing Intrinsic::returnaddress won't get you anything - even failed to pass the linking stage - without special support, since the intrinsic is just a function declaration.</div><div><br></div><div>Bests,</div><div>Bekket<br></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 5, 2018 at 5:00 AM <a href="http://mayuyu.io" target="_blank">mayuyu.io</a> <<a href="mailto:admin@mayuyu.io" target="_blank">admin@mayuyu.io</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">To my knowledge that intrinsic IS generated by frontends like Clang when using _builtin_return_address(), i could be wrong though<br>
<br>
Zhang<br>
<br>
> 在 2018年9月5日,10:47,Bekket McClane via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> 写道:<br>
> <br>
> and<br>
<br>
</blockquote></div>
</blockquote></div>