<div dir="ltr"><br><br><div class="gmail_quote">On Mon, Mar 7, 2011 at 3:30 PM, Elazar Leibovich <span dir="ltr"><<a href="mailto:elazarl@gmail.com">elazarl@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div dir="ltr"><div class="gmail_quote">2011/3/7 Orna Agmon Ben-Yehuda <span dir="ltr"><<a href="mailto:ladypine@gmail.com" target="_blank">ladypine@gmail.com</a>></span><div class="im"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><br><br><div class="gmail_quote"><div>On Mon, Mar 7, 2011 at 12:18 PM, Muli Ben-Yehuda <span dir="ltr"><<a href="mailto:muli@il.ibm.com" target="_blank">muli@il.ibm.com</a>></span> wrote:<br>
</div><div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Mon, Mar 07, 2011 at 12:11:36PM +0200, Erez D wrote:<br>
<br>
> I have a function which is not called in a regular way, so gcc<br>
> thinks it is dead code. however it is not, and i am looking for a<br>
> way to tell the linker not to remove it.<br>
<br>
</div>extern<br>
<br>
<br></blockquote></div><div>And set the function pointer to a global variable, so that the linker cannot know if the value is used or not.</div><div>This trick I learned from Nadav Har'El worked through many compilers and linkers over the past decade. </div>
</div></div></blockquote><div><br></div></div><div>I wonder if link time optimization[1] would be able to catch this trick and remove the dead code after all.</div><div><br></div><div>The smarter the compiler become, the smarter we should trick them into unexpected behavior</div>
<div><br></div><div>[1] <a href="http://gcc.gnu.org/wiki/LinkTimeOptimization" target="_blank">http://gcc.gnu.org/wiki/LinkTimeOptimization</a></div></div></div>
</blockquote></div><br><br><div>Worst case, you can always print this value.</div><div>Anyway, I prefer this trick, which is performed in code to the KEEP trick which requires changing the linker itself, because it is more portable.<br clear="all">
<br>-- <br>Orna Agmon Ben-Yehuda.<br><a href="http://ladypine.org">http://ladypine.org</a><br>
</div></div>