digitalmars.D.bugs - [Issue 701] New: Inline asm using incorrect offsets when used in inner function
- d-bugmail puremagic.com Dec 20 2006
- Sean Kelly <sean f4.ca> Dec 20 2006
- d-bugmail puremagic.com Jan 23 2007
- d-bugmail puremagic.com Nov 13 2008
- d-bugmail puremagic.com Nov 26 2010
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=701 ------- Comment #2 from thomas-dloop kuehne.cn 2007-01-23 06:05 -------mov [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: # asm{ # lea EAX, [EBP-24] + 1; # lea EBX, 1 - [EBP-24]; # } 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 | ------- Comment #3 from clugdbug yahoo.com.au 2008-11-13 12:50 ------- 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









Sean Kelly <sean f4.ca> 