<div dir="ltr">Hi Dmitry,<div><br></div><div>Sorry for the late reply. For CFI specific code generation, pcc is a better person to answer. But on the issue of global variables being optimized, that hasn't happened yet. That would be great if you wanted to pick that up!</div><div><br></div><div>In your original email example, it seems like the file static i=53 could be constant propagated since there are no other defs, and the code in get_fptr simplified during the compile step, but I assume this is part of a more complex example where it is not possible to do this? Also note that with r327254 we started importing global variables. Do you know why we don't import in your case? I wonder if it has to do with it being CFI inserted code?</div><div><br></div><div>Teresa</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Apr 17, 2018 at 9:17 AM <<a href="mailto:dmitry.mikulin@sony.com" target="_blank">dmitry.mikulin@sony.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I watched  Teresa’s talk on ThinLTO from last year’s CppCon, and it sounded like adding global variable information to the summaries was in the works, or at least in planning. Can someone (Teresa?) please share the current status? If it’s part of future plans, are there any specific proposals that can be picked up and worked on?<br>
<br>
Thanks!<br>
<br>
<br>
> On Apr 9, 2018, at 6:51 PM, via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> <br>
> Hi,<br>
> <br>
> I’m working on setting up ThinLTO+CFI for a C application which uses a lot of function pointers. While functionally it appears stable, it’s performance is significantly degraded, to the tune of double digit percentage points compared to regular LTO+CFI.<br>
> <br>
> Looking into possible causes I see that under ThinLTO+CFI iCall type checks almost always generate jump table entries for indirect calls, which creates another level of indirection for every such call. On top of that it breaks the link order layout because real function names point to jump table entries. It appears that I’m hitting a limitation in ThinLTO on how much information it can propagate across modules, particularly information about constants. In the example below, the fact that “i” is effectively a constant, is lost under ThinLTO, and the inlined copy of b.c:get_fptr() in a.c does not eliminate the conditional, which, for CFI purposes requires to generate a type check/jump table.<br>
> <br>
> I was wondering if there was a way to mitigate this limitation.<br>
> <br>
> a.c<br>
> =============================<br>
> typedef int (*fptr_t) (void);<br>
> fptr_t get_fptr();<br>
> int main(int argc, char *argv[])<br>
> {<br>
>  fptr_t fp = get_fptr();<br>
>  return fp();<br>
> }<br>
> <br>
> <br>
> b.c<br>
> =============================<br>
> typedef int (*fptr_t) (void);<br>
> int foo(void) { return 11; }<br>
> int bar(void) { return 22; }<br>
> <br>
> static fptr_t fptr = bar;<br>
> static int i = 53;<br>
> <br>
> fptr_t get_fptr(void)<br>
> {<br>
>  if (i >= 0)<br>
>    fptr = foo;<br>
>  else<br>
>    fptr = bar;<br>
> <br>
>  return fptr;<br>
> }<br>
> <br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="m_-6854738011569243965gmail_signature" data-smartmail="gmail_signature"><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td style="border-top-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px">Teresa Johnson |</td><td style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px"> Software Engineer |</td><td style="border-top-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td style="border-top-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px"> 408-460-2413</td></tr></tbody></table></span></div>