My general opinion is that to not allow the naked attribute is to
pontificate over a group of sophisticated gcc users that are fully
capable of understanding what the naked attribute does. They can read
the manual and accept the responsibility for using the feature.
The ramifications of the full inline asm syntax as you describe below,
are 100 times more complex to understand (and implement, test and
maintain in the compiler) than the naked attribute, and have way more
complex implications in things like LTO than functions with the naked
attribute.
People have a lot of reason to want to write assembly code in their C
program and I don't see why we feel that because we control the
compiler, that we should be preventing them from doing their job in a
way that they see fit to do it. Everyone has their own concept of best
practices and none are 100% the same.
The naked attribute completes "inline assembler". Without it, there are
things you just can't do.
While this is the gcc list, I can interject that for llvm, I implemented
mips16 stubs fully by creating high level IR for functions and then
compiling those functions with the naked attribute.
I think though that more documentation should be provided on the
attribute (as well as for the non simple forms of inline assembler...!)
Reed
On 05/03/2013 07:03 AM, Richard Sandiford wrote:
David Brown <da...@westcontrol.com> writes:
Personally, I've used "naked" when I want to write pure assembly code
and don't want extra stack frames or "return" codes. I don't want to
write stand-alone assembly files (I've written mountains of them in the
past, and hope they stay in the past). I am happier using the very nice
flexible gcc inline assembly syntax.
The full inline asm syntax, such as:
asm ("..." : "=r" (result) : "i" (100))
is specifically forbidden in naked functions, because in general GCC can
only satisfy the constraints by building its own frame:
Use this attribute on the ARM, AVR, MCORE, RX and SPU ports to indicate that
the specified function does not need prologue/epilogue sequences generated by
the compiler. It is up to the programmer to provide these sequences. The
only statements that can be safely included in naked functions are
@code{asm} statements _that do not have operands_. All other statements,
including declarations of local variables, @code{if} statements, and so
forth, should be avoided.
(my emphasis). Naked functions must have a body of the form:
{
asm ("....");
}
i.e. an asm with just a plain string, and no other statements or
local variables. So you don't really get any more flexibility
by using inline asms over using assembly files.
Thanks,
Richard