Bug 5818 – 64bit ASM can't have 32-bit stack operands

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2011-04-08T08:52:00Z
Last change time
2015-06-09T05:11:36Z
Assigned to
nobody
Creator
ibuclaw

Comments

Comment #0 by ibuclaw — 2011-04-08T08:52:52Z
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
Comment #1 by ibuclaw — 2011-04-08T09:11:16Z
Infact, examining an object jump output DMD emits a push to RAX, not EAX - so this is just dumb.
Comment #2 by braddr — 2011-06-16T00:56:24Z
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.