After I encountered illegal instruction signals whith dmd-generated code [1] I eventually bootstrapped GDC 11.3 and 12.1. Unfortunately the problem persists. A statically linked program receives SIGILL, as gdb says this happens here:
(gdb) bt
#0 0x080b7e8a in rt.minfo.ModuleGroup.__ctor() ()
#1 0x080b0095 in _d_dso_registry ()
#2 0x0805dbdc in gdc.dso_ctor ()
#3 0x08103290 in __libc_csu_init ()
#4 0x08102d34 in __libc_start_main ()
#5 0x0804c51d in _start ()
(gdb) disass
Dump of assembler code for function _D2rt5minfo11ModuleGroup6__ctorMFNbNcNiAyPS6object10ModuleInfoZSQCkQCkQCh:
0x080b7e80 <+0>: mov 0x4(%esp),%eax
0x080b7e84 <+4>: movq 0x8(%esp),%xmm0
=> 0x080b7e8a <+10>: movq %xmm0,(%eax)
0x080b7e8e <+14>: ret
I have checked the build log: The D runtime has been compiled with -m32
. According to GCC's documentation [2] the option -m32
means “The -m32 option [...] generates code that runs on any i386 system.” Obviously this is not the case:
module structtest;
struct MyStruct {
int [] i;
this (int [] i)
{
this.i = i;
}
}
compiling with gdc -m32 -O2 -c
and inspecting the generated code with objdump
gives this:
[...]
Disassembly of section .text.ref structtest.MyStruct structtest.MyStruct.__ctor(int[]):
00000000 <ref structtest.MyStruct structtest.MyStruct.__ctor(int[])>:
0: 8b 44 24 04 mov 0x4(%esp),%eax
4: f3 0f 7e 44 24 08 movq 0x8(%esp),%xmm0
a: 66 0f d6 00 movq %xmm0,(%eax)
e: c3 ret
[...]
Compiling with gdc -m32 -march=pentium3 -O2 -c
generated the expected code:
00000080 <ref structtest.MyStruct structtest.MyStruct.__ctor(int[])>:
80: 8b 44 24 04 mov 0x4(%esp),%eax
84: 8b 54 24 08 mov 0x8(%esp),%edx
88: 8b 4c 24 0c mov 0xc(%esp),%ecx
8c: 89 10 mov %edx,(%eax)
8e: 89 48 04 mov %ecx,0x4(%eax)
91: c3 ret
But this does of course not change the code which is already compiled into libgphobos.a ...
[1] http://forum.dlang.org/thread/suwlbzlgqdylfauwgteu@forum.dlang.org
DMD 2.090.1: SIGILL, Illegal instruction on (ahem) intel Pentium III
[2] https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html