[Issue 21914] New: naked assembler functions get wrong offset to parameters

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 12 00:41:08 UTC 2021


https://issues.dlang.org/show_bug.cgi?id=21914

          Issue ID: 21914
           Summary: naked assembler functions get wrong offset to
                    parameters
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: regression
          Priority: P1
         Component: dmd
          Assignee: nobody at puremagic.com
          Reporter: bugzilla at digitalmars.com

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 at 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.

--


More information about the Digitalmars-d-bugs mailing list