Bug 5748 – @naked annotation

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2011-03-17T10:02:00Z
Last change time
2011-03-18T07:27:29Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2011-03-17T10:02:29Z
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(); }
Comment #1 by bugzilla — 2011-03-17T11:21:28Z
naked is not a property of the function's interface, and therefore should properly not be part of its declaration.
Comment #2 by samukha — 2011-03-17T15:47:07Z
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.
Comment #3 by bugzilla — 2011-03-17T16:04:04Z
(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. Think of it this way - is it a good design to have to change your header files if you change your implementation?
Comment #4 by samukha — 2011-03-18T00:24:35Z
(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.
Comment #5 by bugzilla — 2011-03-18T01:04:49Z
(In reply to comment #4) > > 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 Internal only. It is not externally visible and simply does not logically belong in the description of the external interface. > and it definitely doesn't belong in > the assembly block, so I think "poorly designed" applies to D as well. Naked only makes sense if you have inline assembly, so physically associating it with that makes sense. There is no obvious syntax for it, but putting it in the function's external interface is just wrong. > > 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. Sorry, but major yuk to that :-)
Comment #6 by samukha — 2011-03-18T01:55:04Z
(In reply to comment #5) > (In reply to comment #4) > > > 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 > > Internal only. It is not externally visible and simply does not logically > belong in the description of the external interface. > > > and it definitely doesn't belong in > > the assembly block, so I think "poorly designed" applies to D as well. > > Naked only makes sense if you have inline assembly, so physically associating > it with that makes sense. There is no obvious syntax for it, but putting it in > the function's external interface is just wrong. Only if you think about function attributes as attributes of the function's interface. > > > > 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. > > Sorry, but major yuk to that :-) Maybe, you are right. Minor issue, anyway. Doesn't deserve a major yuk.
Comment #7 by clugdbug — 2011-03-18T07:27:29Z
Somewhat related is the Pervert Bug: (bug 2350). Really, the compiler should be a lot stricter on what it allows inside a naked function. IMHO, the main reason people feel that there's a need for annotation, is that DMD currently allows a lot of garbage to compile. If the compiler were adequately strict, it'd be clear it was an asm-only issue.