looking for a way to tell gcc not to remove some code he thinks is unreachable.

looking for a way to tell gcc not to remove some code he thinks is unreachable.

Orna Agmon Ben-Yehuda ladypine at gmail.com
Mon Mar 7 15:38:32 IST 2011


On Mon, Mar 7, 2011 at 3:30 PM, Elazar Leibovich <elazarl at gmail.com> wrote:

> 2011/3/7 Orna Agmon Ben-Yehuda <ladypine at gmail.com>
>
>
>>
>> On Mon, Mar 7, 2011 at 12:18 PM, Muli Ben-Yehuda <muli at il.ibm.com> wrote:
>>
>>> On Mon, Mar 07, 2011 at 12:11:36PM +0200, Erez D wrote:
>>>
>>> > I have a function which is not called in a regular way, so gcc
>>> > thinks it is dead code.  however it is not, and i am looking for a
>>> > way to tell the linker not to remove it.
>>>
>>> extern
>>>
>>>
>>> And set the function pointer to a global variable, so that the linker
>> cannot know if the value is used or not.
>> This trick I learned from Nadav Har'El worked through many compilers and
>> linkers over the past decade.
>>
>
> I wonder if link time optimization[1] would be able to catch this trick and
> remove the dead code after all.
>
> The smarter the compiler become, the smarter we should trick them into
> unexpected behavior
>
> [1] http://gcc.gnu.org/wiki/LinkTimeOptimization
>


Worst case, you can always print this value.
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.

-- 
Orna Agmon Ben-Yehuda.
http://ladypine.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20110307/2e6a7514/attachment-0001.html>


More information about the Linux-il mailing list