This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: return statement in a function with the naked attribute
- From: David Brown <david at westcontrol dot com>
- To: reed kotler <rkotler at mips dot com>
- Cc: Chung-Ju Wu <jasonwucj at gmail dot com>, <gcc at gcc dot gnu dot org>, <rdsandiford at googlemail dot com>
- Date: Fri, 3 May 2013 14:00:31 +0200
- Subject: Re: return statement in a function with the naked attribute
- References: <5182EC4D dot 4070207 at mips dot com> <CADj25HOvsRV1wJKtdot9EyzZ1gc6TtpQMdF8tQp5OiBza9jxDw at mail dot gmail dot com> <5183371D dot 6040207 at mips dot com>
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 <rkotler@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.