[dmd-internals] Help with dl_* functions in DMD
Jacob Carlborg via dmd-internals
dmd-internals at puremagic.com
Sun Dec 20 12:11:27 PST 2015
I’m trying to generate code using the dl_* functions in DMD. The corresponding D code would be the following:
struct TLS
{
int* function (TLS*) thunk;
size_t key;
size_t offset;
}
extern (C) __gshared TLS bar;
extern (C) int main (int i, char**)
{
auto foo = *bar.thunk(&bar);
return 0;
}
The code that DMD is generating, for the above “main” functions, is:
pushq %rbp
movq %rsp, %rbp
movq _bar(%rip), %rdi
movq %rdi, %rax
callq *_main(%rax)
movl _main(%rax), %ecx
xorl %eax, %eax
popq %rbp
retq
What I’ve got so far is the following code below, instead of [1]:
switch (op * 2 + x)
{
case OPvar * 2 + 1:
e = el_una(OPind, TYnptr, e);
e = el_una(OPind, TYnptr, e);
break;
case OPvar * 2 + 0:
case OPrelconst * 2 + 1:
e = el_una(OPind, TYnptr, e);
break;
case OPrelconst * 2 + 0:
break;
default:
assert(0);
break;
}
e = el_una(OPaddr, TYnptr, e);
e = doptelem(e, GOALvalue | GOALflags);
e = el_una(OPind, TYnptr, e);
e = el_bin(OPcallns, TYnptr, e, e);
e = el_una(OPind, TYnptr, e);
With the above code DMD and for this example:
extern (C) int main (int i, char**)
{
auto foo = bar;
return 0;
}
DMD generates the following:
pushq %rbp
movq %rsp, %rbp
movq _bar(%rip), %rax
movq _main(%rax), %rdi
callq *_bar(%rip)
movl _main(%rax), %ecx
xorl %eax, %eax
popq %rbp
retq
Basically I have no idea what I’m doing and I don’t really understand how these el_* functions are working. Anyone could give me some help with this?
[1] https://github.com/D-Programming-Language/dmd/blob/master/src/backend/el.c#L1259-L1263
--
/Jacob Carlborg
More information about the dmd-internals
mailing list