[Issue 5748] @naked annotation

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Mar 18 00:27:49 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5748



--- Comment #4 from Max Samukha <samukha at voliacable.com> 2011-03-18 00:24:35 PDT ---
(In reply to comment #0)
> I think that the "naked" that currently is usable inside asm blocks is a
> property of the whole function that contains the asm block and not just of the
> asm block, so I suggest to deprecate (and later remove) the "naked" and to add
> a @naked function annotation.
> 
> An example, from (from dmd\src\druntime\src\core\thread.d):
> 
> 
> version( D_InlineAsm_X86 ) {
>     static void* getBasePtr() {
>         asm {
>             naked;
>             mov EAX, EBP;
>             ret;
>         }
>     }
> 
>     obj.m_main.bstack = getBasePtr();
> } else version( D_InlineAsm_X86_64 ) {
>     static void* getBasePtr() {
>         asm {
>             naked;
>             mov RAX, RBP;
>             ret;
>         }
>     }
> 
>     obj.m_main.bstack = getBasePtr();
> }
> 
> 
> To:
> 
> version( D_InlineAsm_X86 ) {
>     @naked static void* getBasePtr() {
>         asm {
>             mov EAX, EBP;
>             ret;
>         }
>     }
> 
>     obj.m_main.bstack = getBasePtr();
> } else version( D_InlineAsm_X86_64 ) {
>     @naked static void* getBasePtr() {
>         asm {
>             mov RAX, RBP;
>             ret;
>         }
>     }
> 
>     obj.m_main.bstack = getBasePtr();
> }

(In reply to comment #3)
> (In reply to comment #2)
> > Should an attribute be necessarily part of function interface? MSVC uses
> > __declspec(naked), which is not part of the function interface
> > (http://msdn.microsoft.com/en-us/library/h5w10wxs%28v=vs.80%29.aspx). Also, the
> > GNU compiler uses __attribute__((naked)). Having "naked" in the assembly block
> > has never felt right, really.
> 
> Naked is an internal characteristic of a function, not an external one. It
> simply does not belong in the declaration, despite the existence of poorly
> designed extensions in other languages.
> 

But it is still a function characteristic and it definitely doesn't belong in
the assembly block, so I think "poorly designed" applies to D as well.

> Think of it this way - is it a good design to have to change your header files
> if you change your implementation?

You do not need to change header files with MSVC because the attribute is
permitted only in the function definition.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list