[Issue 9969] New: dmd ABI mistake (cfloat static array initialisation)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Apr 20 08:22:42 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9969

           Summary: dmd ABI mistake (cfloat static array initialisation)
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: john.loughran.colvin at gmail.com


--- Comment #0 from John Colvin <john.loughran.colvin at gmail.com> 2013-04-20 16:22:40 BST ---
test.d:

import std.stdio;
void main()
{
    cfloat a[2];
}

$ dmd test.d
$ ./test
Segmentation fault (core dumped)

The problem is here:

0000000000000000 <_Dmain>:
   0:   55                      push   rbp
   1:   48 8b ec                mov    rbp,rsp
   4:   48 83 ec 10             sub    rsp,0x10
   8:   48 83 ec 08             sub    rsp,0x8
   c:   48 be 02 00 00 00 00    movabs rsi,0x2
  13:   00 00 00
  16:   ff 35 00 00 00 00    push   QWORD PTR [rip+0x0]        # 1c <_Dmain$
                        18: R_X86_64_PC32    .rodata-0x4
  1c:   48 8d 7d f0             lea    rdi,[rbp-0x10]
  20:   e8 00 00 00 00          call   25 <_Dmain+0x25>
                        21: R_X86_64_PC32    _memset64-0x4
  25:   48 83 c4 10             add    rsp,0x10
  29:   31 c0                   xor    eax,eax
  2b:   c9                      leave
  2c:   c3                      ret
  2d:   0f 1f 00                nop    DWORD PTR [rax]

0000000000000000 <_memset64>:
   0:   55                      push   rbp
   1:   48 8b ec                mov    rbp,rsp
   4:   48 83 ec 10             sub    rsp,0x10
   8:   49 89 f8                mov    r8,rdi
   b:   49 89 f1                mov    r9,rsi
   e:   48 89 f8                mov    rax,rdi
  11:   49 8d 0c d0             lea    rcx,[r8+rdx*8]
  15:   4c 3b c1                cmp    r8,rcx
  18:   73 0c                   jae    26 <_memset64+0x26>
  1a:   4d 89 08                mov    QWORD PTR [r8],r9
  1d:   49 83 c0 08             add    r8,0x8
  21:   49 39 c8                cmp    r8,rcx
  24:   72 f4                   jb     1a <_memset64+0x1a>
  26:   48 8b e5                mov    rsp,rbp
  29:   5d                      pop    rbp
  2a:   c3                      ret

long *_memset64(long *p, long value, size_t count)

_memset64 is extern(C). Dmd passes "p" correctly, but then tries to pass
"value" on the stack and passes the value for "count" as the second argument.
_memset64 attempts to use rdx as the count, which is garbage. Hence, segfault.

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


More information about the Digitalmars-d-bugs mailing list