Issue 21914 - naked assembler functions get wrong offset to parameters
Summary: naked assembler functions get wrong offset to parameters
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: backend, iasm, pull
Depends on:
Blocks:
 
Reported: 2021-05-12 00:41 UTC by Walter Bright
Modified: 2021-05-12 05:00 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Walter Bright 2021-05-12 00:41:08 UTC
Consider the function:

  extern (C++) int insbad(int a, int b) {
    asm {
	naked            ;
	mov EAX,a-4+[ESP] ;
	mov EBX,b-4+[ESP] ;
    }
  }

In 2.079 and earlier, the inline assembler assumed that an EBP was set up and provided offsets to the parameters accordingly. Hence, in the above code, a -4 was inserted to correct for not having EBP pushed on the stack.

Somewhere between 2.079 and 2.090 this was changed to not consider EBP, and the offsets look like this for the above function:

  ?insbad@@YAHHH@Z:
         mov	EAX,[ESP]    // should be 4[ESP]
	 mov	EBX,4[ESP]   // should be 8[ESP]

The problem looks to be the computation of Para.size in cgcod.d from this PR:

 https://github.com/dlang/dmd/pull/9620/files

i.e. my fault.
Comment 1 Dlang Bot 2021-05-12 00:58:38 UTC
@WalterBright created dlang/dmd pull request #12515 "fix Issue 21914 - naked assembler functions get wrong offset to param…" fixing this issue:

- fix Issue 21914 - naked assembler functions get wrong offset to parameters

https://github.com/dlang/dmd/pull/12515
Comment 2 Dlang Bot 2021-05-12 05:00:42 UTC
dlang/dmd pull request #12515 "fix Issue 21914 - naked assembler functions get wrong offset to param…" was merged into master:

- 872e13dac456da7bdc9fedb62bc71cdd8a31434d by Walter Bright:
  fix Issue 21914 - naked assembler functions get wrong offset to parameters

https://github.com/dlang/dmd/pull/12515