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: Chung-Ju Wu <jasonwucj at gmail dot com>
- To: reed kotler <rkotler at mips dot com>
- Cc: gcc at gcc dot gnu dot org, rdsandiford at googlemail dot com
- Date: Fri, 3 May 2013 11:41:51 +0800
- Subject: Re: return statement in a function with the naked attribute
- References: <5182EC4D dot 4070207 at mips dot com>
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