[dmd-internals] Help with dl_* functions in DMD

Martin Nowak via dmd-internals dmd-internals at puremagic.com
Tue Dec 29 03:14:19 PST 2015


On Monday, 28 December 2015 at 12:29:41 UTC, Jacob Carlborg wrote:
>> On 27 dec 2015, at 22:33, Martin Nowak via dmd-internals 
>> <dmd-internals at puremagic.com> wrote:
>> 
>> What do you want to achieve?
>
> My overall goal is to implement native TLS on OS X in DMD. For 
> this particular question I was trying to figure out how to get 
> DMD to generate same assembly as the corresponding D code, when 
> a TLS variable is accessed, using the el_* functions.
>
> auto foo = *bar.thunk(&bar);

If you point us to some documentation of the native TLS, we might 
be able to help guide you a bit better.

> It looks like the lowering for a TLS variable access to a call 
> to ___tls_get_addr occurs in el_picvar for OS X.

That's b/c our emulated TLS is simply a function call, no linker 
recognition and dedicated relocations are involved. Look at the 
native TLS implementation for linux, it works very differently, 
and I'd expect OSX' implementation to be somewhat similar.

>> They simply construct an IR tree, no magic here.
>
>
> You make it sound so easy :). I guess my main problem is that 
> I’m reading the assembly that Clang outputs then I have no idea 
> how to get DMD to generate the same assembly.

Well it is fairly easy, 
https://en.wikipedia.org/wiki/Binary_expression_tree, but it's 
still quite difficult to construct the correct IR tree. As Daniel 
said, try to print your tree, there is some helper function 
(el_print or so).
As I said earlier, when you're relying on a specific sequence of 
instructions, you have to implement it in the codegen, not the IR 
construction.



More information about the dmd-internals mailing list