digitalmars.D.bugs - [Issue 701] New: Inline asm using incorrect offsets when used in inner function
- d-bugmail puremagic.com (54/54) Dec 20 2006 http://d.puremagic.com/issues/show_bug.cgi?id=701
- Sean Kelly (4/4) Dec 20 2006 Upon reflection, I'm not entirely sure what the correct behavior should
- d-bugmail puremagic.com (12/16) Jan 23 2007 This should be
- d-bugmail puremagic.com (13/13) Nov 13 2008 http://d.puremagic.com/issues/show_bug.cgi?id=701
- d-bugmail puremagic.com (10/10) Nov 26 2010 http://d.puremagic.com/issues/show_bug.cgi?id=701
- d-bugmail puremagic.com (13/17) Jan 29 2012 http://d.puremagic.com/issues/show_bug.cgi?id=701
http://d.puremagic.com/issues/show_bug.cgi?id=701 Summary: Inline asm using incorrect offsets when used in inner function Product: D Version: 0.177 Platform: PC OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: bugzilla digitalmars.com ReportedBy: sean f4.ca I expect the following code: void main() { int i = 0; void fn() { asm { naked; lea EAX, i; mov [EAX], 42; ret; } } fn(); printf( "i = %d\n", i ); } to print "42" but instead it prints "0". This is because the assembler uses the offset of 'i' that would be used within main() rather than adjusting for the inner function. Changing the code to this: void main() { int i = 0; void fn() { asm { naked; lea EAX, i; add EAX, 4; mov [EAX], 42; ret; } } fn(); printf( "i = %d\n", i ); } Prints "42" as desired, but a manual adjustment of offsets should not be necessary. This is particulrly problematic in situations where "naked" is not used, so the amount to adjust the offset by is not fixed. --
Dec 20 2006
Upon reflection, I'm not entirely sure what the correct behavior should be here. However, I think it's misleading that the code currently complies and silently produces the incorrect result. If nothing else, it would be nice if this worked with 'naked' not present.
Dec 20 2006
http://d.puremagic.com/issues/show_bug.cgi?id=701mov [EAX], 42;This should bemov int ptr [EAX], 42;I don't think there is a way to use a single "lea" to solve your problem, however lea seems to be broken: results in8d 45 e9 lea eax, [ebp-23] 8d 5d 19 lea ebx, [ebp+25]I'm not a master of all x86 addressing modes but it seems odd. --
Jan 23 2007
http://d.puremagic.com/issues/show_bug.cgi?id=701 clugdbug yahoo.com.au changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Inline asm using incorrect |Inline naked asm uses |offsets when used in inner |incorrect offsets |function | I'm changing the name of this issue, since it actually has nothing to do with inner functions. It applies to _any_ use of 'naked'. Basically naked calculates offsets assuming that a stack frame is present -- even though the main use of naked is to avoid having a stack frame! --
Nov 13 2008
http://d.puremagic.com/issues/show_bug.cgi?id=701 Andrei Alexandrescu <andrei metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED CC| |andrei metalanguage.com AssignedTo|nobody puremagic.com |bugzilla digitalmars.com -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 26 2010
http://d.puremagic.com/issues/show_bug.cgi?id=701 Walter Bright <bugzilla digitalmars.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution| |WONTFIX 01:41:00 PST ---I'm changing the name of this issue, since it actually has nothing to do with inner functions. It applies to _any_ use of 'naked'. Basically naked calculates offsets assuming that a stack frame is present -- even though the main use of naked is to avoid having a stack frame!Naked assumes you set up your own stack frame, not that you don't have one. I don't think there's any magic answer to this. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 29 2012