<div dir="ltr"><div>I read some paper from NDSS and USENIX Security about  protecting C++ virtual calls.</div><div><br></div><div>So now I know maybe these paper implementation must modify front-end/Clang.</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> 於 2020年6月19日 週五 上午2:16寫道:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, Jun 18, 2020 at 10:52 AM PenYiWang <<a href="mailto:s89162504@gmail.com" target="_blank">s89162504@gmail.com</a>> wrote:<br>
><br>
> So if I want to know whether a CallInst is a C++ virtual call or not.<br>
><br>
> I have to get the information at frontend/Clang.<br>
><br>
> and then pass the information to middle-end/LLVM IR by myself.<br>
><br>
> Is it right?<br>
<br>
Yes... but you maybe shouldn't be? What do you plan to do with that information?<br>
<br>
(not that there aren't/haven't been efforts to improve virtual call<br>
performance - I think there's something using ThinLTO to do a whole<br>
program analysis of virtual calls you could look into as examples of<br>
optimizations on virtual function calls)<br>
<br>
><br>
> Thank you<br>
><br>
><br>
><br>
> David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> 於 2020年6月19日 週五 上午1:26寫道:<br>
>><br>
>> On Thu, Jun 18, 2020 at 9:53 AM PenYiWang via llvm-dev<br>
>> <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
>> ><br>
>> > Hi<br>
>> ><br>
>> > I know that a virtual call looks like this :<br>
>> ><br>
>> >   %4 = load %class.base*, %class.base** %1, align 8<br>
>> >   %5 = bitcast %class.base* %4 to void (%class.base*)***<br>
>> >   %6 = load void (%class.base*)**, void (%class.base*)*** %5, align 8<br>
>> >   %7 = getelementptr inbounds void (%class.base*)*, void (%class.base*)** %6, i64 0<br>
>> >   %8 = load void (%class.base*)*, void (%class.base*)** %7, align 8<br>
>> >   call void %8(%class.base* %4)<br>
>> ><br>
>> > There may be some action to get function pointer on vtable .<br>
>> ><br>
>> > But, when I scan a llvm ir file, if I just see a CallInst and it is an indirect call<br>
>> ><br>
>> > Is there any way to know whether the CallInst is a virtual call or not ?<br>
>><br>
>> Not exactly, no - LLVM has no concept of virtual calls specifically -<br>
>> they are "just" indirect calls through a vtable. LLVM optimizations<br>
>> generally shouldn't be trying to reconstruct more high level semantics<br>
>> than exist in LLVM IR - an optimization to improve virtual function<br>
>> calls (using the existing IR - not accounting for some special cases<br>
>> that might involve adding extra metadata, etc) should be framed in<br>
>> terms of indirect calls in general (perhaps indirect calls from<br>
>> functions in constant arrays - maybe that's the specific subcase you<br>
>> want to target, etc).<br>
>><br>
>> - Dave<br>
</blockquote></div>