Thread overview
[Issue 5818] New: 64bit ASM can't have 32-bit stack operands
Apr 08, 2011
Iain Buclaw
Apr 08, 2011
Iain Buclaw
Jun 16, 2011
Brad Roberts
April 08, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5818

           Summary: 64bit ASM can't have 32-bit stack operands
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: nobody@puremagic.com
        ReportedBy: ibuclaw@ubuntu.com


--- Comment #0 from Iain Buclaw <ibuclaw@ubuntu.com> 2011-04-08 08:52:52 PDT ---
This is a question rolled into a report (it's affecting me, at least). This excerpt (in core/thread.d for D2; in gc/gcx.d for D1 and D2) - the "push EAX" instruction is not legal x86_64 asm code - according to the GNU 64bit Assembler, which is strong enough an argument for me to follow - so is not compilable with the GDC 64bit compiler (and maybe LDC too).

asm
{
    push RAX ;
    push RBX ;
    push RCX ;
    push RDX ;
    push RSI ;
    push RDI ;
    push RBP ;
    push R8  ;
    push R9  ;
    push R10  ;
    push R11  ;
    push R12  ;
    push R13  ;
    push R14  ;
    push R15  ;
--> push EAX ;   // 16 byte align the stack    <-- This line causes the error
    mov sp[RBP],RSP     ;
}


So, what to do?

Well, first I think druntime should consider revising this code for a start. And secondly, DMD should be hardened to catch and disallow this.


Some thoughts for how to change it:

In 32bit mode:
pusha (afaik) saves (e)ax, cx, dx, bx, sp, bp, si, di
popa restores (e)di, si, bp, bx, dx, cx, ax  (note, stack is not popped)

In GCC builtins:
unwind_init (what is currently being used in place of the above illegal code in
GDC) saves only the rbx, r12, r13, r14 and r15 registers.

Regards

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 08, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5818


Iain Buclaw <ibuclaw@ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw@ubuntu.com


--- Comment #1 from Iain Buclaw <ibuclaw@ubuntu.com> 2011-04-08 09:11:16 PDT ---
Infact, examining an object jump output DMD emits a push to RAX, not EAX - so this is just dumb.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 16, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=5818


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |braddr@puremagic.com
         Resolution|                            |FIXED


--- Comment #2 from Brad Roberts <braddr@puremagic.com> 2011-06-16 00:56:24 PDT ---
Fixed: https://github.com/D-Programming-Language/druntime/commit/d3d75983cdd36622ce02338988c35b0ba8b445e9#src/gc/gcx.d

DMD also fixed across several commits that greatly improved the accuracy/strictness of the inline assembler checking for 64 bit code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------