On 03/05/13 06:03, reed kotler wrote:
> On 05/02/2013 08:41 PM, Chung-Ju Wu wrote:
>> 2013/5/3 reed kotler <rkot...@mips.com>:
>>> Should a return statement be emitted in a function that has the naked
>>> attribute.
>>>
>>> There seems to be some confusion here and apparently disagreement
>>> between
>>> various
>>> gcc compilers.
>>>
>> IMHO, it depends on how you define the word 'naked' for a function
>> and how you expect one writing functions with 'naked' attribute.
>>
>> If you think one is supposed to have *complete* control in the function
>> (i.e. only inline assembly code, without using any C statement and
>> variables),
>> then the asm 'ret' can be omitted.  Porgrammers must explicitly
>> emit 'ret' in the inline asm.
>>
>> If you allow user using C statement in the function with 'naked'
>> attribute,
>> the asm 'ret' is still required.  Because compiler may produce a branch
>> to the epilogue position where 'ret' is expected to exist.
>>
>> AFAIK, there is no standard defining what 'naked' behavior should be.
>> So gcc leaves it to back-end developers.
>>
>>
>> Best regards,
>> jasonwucj
> I think that the compiler should respect any return statements you
> explicitly enter, but should not create any that are implied as in
> reaching the end of the function.
> 

100% agreed.

It is good to allow C code in "naked" functions - but the user must
obviously be aware of what they can and cannot do.  Anything using a
stack frame is right out, for example.


Reply via email to