Thread overview
[Issue 5264] New: x86_64 changes for druntime 2
Nov 24, 2010
Brad Roberts
Nov 24, 2010
Brad Roberts
Nov 24, 2010
Brad Roberts
Nov 24, 2010
Brad Roberts
Nov 25, 2010
Brad Roberts
Nov 28, 2010
Brad Roberts
Dec 02, 2010
Brad Roberts
Dec 08, 2010
Brad Roberts
November 24, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5264

           Summary: x86_64 changes for druntime 2
           Product: D
           Version: D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: druntime
        AssignedTo: sean@invisibleduck.org
        ReportedBy: braddr@puremagic.com


--- Comment #0 from Brad Roberts <braddr@puremagic.com> 2010-11-23 22:17:28 PST ---
Created an attachment (id=830)
most of the changes to get druntime 2 to build with dmd -m64

I spent a couple hours today working on getting druntime 2 to build with the x86_64 dmd compiler.  It's not 100% so far, but almost there.

What's broken:

1) lifetime.d has 4 va_arg calls commented out.  The compiler croaks with:

src/core/stdc/stdarg.d(229): Error: static assert  "not a valid argument type
for va_arg"
src/rt/lifetime.d(814):        instantiated from here: va_arg!(ulong)

2) lifetime.d _d_arrayappendcT needs to be altered to work with varargs properly.  The 64 bit support is fragile/hacky/whatever and I haven't pieced together how this code evolved between d1 and d2's runtimes.

3) lifetime.d _d_arrayshrinkfit() crashes the backend of the compiler:

function  _d_arrayshrinkfit
cod2.c:1769:  assert(stackpush == stackpushsave) // 0xfffffffc == 0

Normally I'd create 3 bugs since there's 3 different issues, but I don't think that'd be useful here.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 24, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5264


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|sean@invisibleduck.org      |braddr@puremagic.com


--- Comment #1 from Brad Roberts <braddr@puremagic.com> 2010-11-23 23:15:13 PST ---
Ok, for #2, I think the right answer is to change _d_arrayappendcT to this:

extern (C) void[] _d_arrayappendcT(TypeInfo ti, Array *x, ...)
{
    version(X86)
    {
        byte *argp = cast(byte*)(&ti + 2);
        return _d_arrayappendT(ti, x, argp[0..1]);
    }
    else version(X86_64)
    {
        va_list ap;
        va_start(ap, __va_argsave);
        byte[] argp;
        va_arg(ap, ti.next, argp);
        return _d_arrayappendT(ti, x, argp);
    }
    else
        static assert(false, "unknown version");
}

Builds at least, but can't test it yet.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 24, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5264



--- Comment #2 from Brad Roberts <braddr@puremagic.com> 2010-11-24 01:35:00 PST ---
ok, debugging #3.  There's actually a couple of different assert locations, though I suspect they're all related.  If the fix for this reduction doesn't solve all of them, I'll re-reduce the next one.

=========
module hrm;

struct BlkInfo { size_t size; }

extern (C) BlkInfo gc_qalloc(size_t sz, uint ba);

void __setArrayAllocLength(ref BlkInfo info)
{
    if (info.size) {}
}

extern (C) void foo()
{
    BlkInfo info = gc_qalloc(0, 0);
    __setArrayAllocLength(info);
}
======

$ ../dmd-trunk/src/dmd -c -m64 hrm.d
Internal error: backend/cod1.c 2554

Building in 32 bit mode (without -m64) works just fine.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 24, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5264



--- Comment #3 from Brad Roberts <braddr@puremagic.com> 2010-11-24 02:32:54 PST ---
for #3, call cleanup code in cod1.c funccall():

2936         if (tym1 == TYhfunc)
2937         {   // Hidden parameter is popped off by the callee
2938             c = genadjesp(c, -4);
2939             stackpush -= 4;

This code isn't aware of the 32 vs 64 bit calling convention differences yet?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 25, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5264



--- Comment #4 from Brad Roberts <braddr@puremagic.com> 2010-11-25 15:04:41 PST ---
I'm splitting #3 into a standalone bug report.  dmd-1.x exhibits the same problem and it's unrelated to druntime at all.  New bug 5275.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 28, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5264



--- Comment #5 from Brad Roberts <braddr@puremagic.com> 2010-11-28 14:49:52 PST ---
Looks like the cause of #1 is that only dmd 1 got one of the big vararg related change sets:

http://www.dsource.org/projects/dmd/changeset/717

Walter's merging those into dmd2 soon.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 02, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=5264


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #830 is|0                           |1
           obsolete|                            |


--- Comment #6 from Brad Roberts <braddr@puremagic.com> 2010-12-02 02:53:29 PST ---
Created an attachment (id=835)
remaining changes to pass semantic checks of druntime

(actually not all, see also bug 5263 for intrinsic cleanup)

This time I ran the druntime and phobos unittests on 32 bit.  They pass.  The 64 bit tests can't be run yet as there's still dmd codgen bugs while building druntime.

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


Brad Roberts <braddr@puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


--- Comment #7 from Brad Roberts <braddr@puremagic.com> 2010-12-08 00:33:38 PST ---
All of these changes have been checked in.  This doesn't mean that it work, just that it builds now. :)

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