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

2011-03-09 Thread Michael Vasiliev
On 03/07/2011 12:11 PM, 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.
>
> i can call it from some place with a flag that tells it to do nothing,
> but this is a ugly hack
> is there a directive telling gcc not to remove that certain function ?
>
I did not exactly try, but if there is -fdce, which is by default
enabled an -O*, there should be also -fno-dce and fno-tree-dce, is it not?

> thanks,
> erez.
>
>
> ___
> Linux-il mailing list
> Linux-il@cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Orna Agmon Ben-Yehuda
On Mon, Mar 7, 2011 at 3:30 PM, Elazar Leibovich  wrote:

> 2011/3/7 Orna Agmon Ben-Yehuda 
>
>
>>
>> On Mon, Mar 7, 2011 at 12:18 PM, Muli Ben-Yehuda  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
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Elazar Leibovich
2011/3/7 Orna Agmon Ben-Yehuda 

>
>
> On Mon, Mar 7, 2011 at 12:18 PM, Muli Ben-Yehuda  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
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


Re: looking for a way to tell gcc not to remove some code he thinks is unreachable (SOVED)

2011-03-07 Thread Erez D
As I was already manipulating the linker script, i added a KEEP(). now it
does not remove the funnction, or anything that is being addressed by it.

cheers,
erez.

On Mon, Mar 7, 2011 at 2:06 PM, Erez D  wrote:

>
>
> On Mon, Mar 7, 2011 at 1:33 PM, Muli Ben-Yehuda  wrote:
>
>> On Mon, Mar 07, 2011 at 12:27:08PM +0200, Erez D wrote:
>>
>> > int x;
>> >
>> > void a()
>>
>> extern void a()
>>
> doesn't work
> avr32-gcc 4.3.2
>
>>
>> > {
>> >   x=3;
>> > }
>> >
>> > int main()
>> > {
>> >   x=0;
>> >   return 1;
>> > }
>> >
>> > 
>> >
>> > the linker will remove function a() as it is not called from
>> > enywhere.  however, i need it to be there, including all of its
>> > content.
>>
>> gcc (ld) 4.4.3 does not remove it in this case. What linker are you
>> using?
>>
>> Cheers,
>> Muli
>>
>
>
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Erez D
On Mon, Mar 7, 2011 at 1:33 PM, Muli Ben-Yehuda  wrote:

> On Mon, Mar 07, 2011 at 12:27:08PM +0200, Erez D wrote:
>
> > int x;
> >
> > void a()
>
> extern void a()
>
doesn't work
avr32-gcc 4.3.2

>
> > {
> >   x=3;
> > }
> >
> > int main()
> > {
> >   x=0;
> >   return 1;
> > }
> >
> > 
> >
> > the linker will remove function a() as it is not called from
> > enywhere.  however, i need it to be there, including all of its
> > content.
>
> gcc (ld) 4.4.3 does not remove it in this case. What linker are you
> using?
>
> Cheers,
> Muli
>
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Erez D
On Mon, Mar 7, 2011 at 1:49 PM, Orna Agmon Ben-Yehuda wrote:

>
>
> On Mon, Mar 7, 2011 at 12:18 PM, Muli Ben-Yehuda  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 know this hack, but i preffered a direct method

thanks,
erez.

>
>
>> ___
>> Linux-il mailing list
>> Linux-il@cs.huji.ac.il
>> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>>
>
>
>
> --
> Orna Agmon Ben-Yehuda.
> http://ladypine.org
>
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Orna Agmon Ben-Yehuda
On Mon, Mar 7, 2011 at 12:18 PM, Muli Ben-Yehuda  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.


> ___
> Linux-il mailing list
> Linux-il@cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>



-- 
Orna Agmon Ben-Yehuda.
http://ladypine.org
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Muli Ben-Yehuda
On Mon, Mar 07, 2011 at 12:27:08PM +0200, Erez D wrote:

> int x;
> 
> void a()

extern void a()

> {
>   x=3;
> }
> 
> int main()
> {
>   x=0;
>   return 1;
> }
> 
> 
> 
> the linker will remove function a() as it is not called from
> enywhere.  however, i need it to be there, including all of its
> content.

gcc (ld) 4.4.3 does not remove it in this case. What linker are you
using?

Cheers,
Muli

___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Erez D
On Mon, Mar 7, 2011 at 12:34 PM, Raz  wrote:

> why do you think the linker removes the function ? what flags are using ?
> Please nm ( nm  ).
>
objdump -d does not show assembly for function a

>
> 2011/3/7 Erez D 
>
>>
>>
>> On Mon, Mar 7, 2011 at 12:18 PM, Muli Ben-Yehuda  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
>>>
>>> how ?
>> sorry, didn't get what you mean.
>>
>> i'll give an example:
>>
>> === my code 
>> int x;
>>
>> void a()
>> {
>>   x=3;
>> }
>>
>> int main()
>> {
>>   x=0;
>>   return 1;
>> }
>>
>> 
>>
>> the linker will remove function a() as it is not called from enywhere.
>> however, i need it to be there, including all of its content.
>>
>> how do i do that.
>>
>>
>> ___
>> Linux-il mailing list
>> Linux-il@cs.huji.ac.il
>> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>>
>>
>
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Raz
why do you think the linker removes the function ? what flags are using ?
Please nm ( nm  ).

2011/3/7 Erez D 

>
>
> On Mon, Mar 7, 2011 at 12:18 PM, Muli Ben-Yehuda  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
>>
>> how ?
> sorry, didn't get what you mean.
>
> i'll give an example:
>
> === my code 
> int x;
>
> void a()
> {
>   x=3;
> }
>
> int main()
> {
>   x=0;
>   return 1;
> }
>
> 
>
> the linker will remove function a() as it is not called from enywhere.
> however, i need it to be there, including all of its content.
>
> how do i do that.
>
>
> ___
> Linux-il mailing list
> Linux-il@cs.huji.ac.il
> http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
>
>
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Erez D
On Mon, Mar 7, 2011 at 12:18 PM, Muli Ben-Yehuda  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
>
> how ?
sorry, didn't get what you mean.

i'll give an example:

=== my code 
int x;

void a()
{
  x=3;
}

int main()
{
  x=0;
  return 1;
}



the linker will remove function a() as it is not called from enywhere.
however, i need it to be there, including all of its content.

how do i do that.
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Muli Ben-Yehuda
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


___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il


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

2011-03-07 Thread Erez D
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.

i can call it from some place with a flag that tells it to do nothing, but
this is a ugly hack
is there a directive telling gcc not to remove that certain function ?


thanks,
erez.
___
Linux-il mailing list
Linux-il@cs.huji.ac.il
http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il