www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5818] New: 64bit ASM can't have 32-bit stack operands

reply d-bugmail puremagic.com writes:
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



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: -------
Apr 08 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5818


Iain Buclaw <ibuclaw ubuntu.com> changed:

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



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: -------
Apr 08 2011
prev sibling parent d-bugmail puremagic.com writes:
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



---
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: -------
Jun 16 2011