D on Windows Phone

bitwise via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 1 08:03:58 PDT 2015


On Wed, 01 Jul 2015 08:23:18 -0400, Jacob Carlborg <doob at me.com> wrote:

> On 01/07/15 10:06, Dan Olson wrote:
>
>> The private APIs being called by osx_tls.c like
>> dyld_enumerate_tlv_storage() are overriden for iOS by using [1].  I can
>> change all dyld prefixes in theadLocalVariable.c to something else and
>> remove all code not needed.
>
> Right, I forgot that you have implemented those functions yourself. But  
> removing the "dyld" prefix might be a good idea.
>
>> That would leave a call to private API
>> dyld_register_image_state_change_handler() in threadLocalVariables.c,
>> but it looks to me like it could be rewritten to use
>> _dyld_register_func_for_add_image().  Tried it and seems to work.
>
> _dyld_register_func_for_add_image won't work for dynamic libraries.  
> There's no API to unregister the callback. So, if  
> _dyld_register_func_for_add_image is called from a dynamic library then  
> the library is unloaded. The next call to any of the "dl" functions,  
> i.e. "dlopen" will crash.
>
> dyld_register_image_state_change_handler works because it pins the  
> dynamic library, if I recall correctly. It won't unload it.
>
> _dyld_register_func_for_add_image is already used by druntime, perhaps  
> it doesn't matter. I think bitwise is working on adding support for  
> dynamic libraries on OS X. On Linux the compiler is generating a  
> function that behave as the C function with the attribute  
> __attribute__((constructor)). Perhaps that can be used.
>
> Otherwise perhaps look at the implementation of
> dyld_register_image_state_change_handler and see if you can manually pin  
> the dynamic library.
>

I think apple recently added support to iOS for shared libraries as  
"embedded binaries", but you still can't dynamically load code. So for  
iOS, the above shouldn't matter.

Section 2.5, 2.7
https://developer.apple.com/app-store/review/guidelines/


> I think bitwise is working on adding support for dynamic libraries on OS  
> X.

Indeed, trying ;)

I've got it partially working. My druntime supports multiple images now  
and I've got druntime building as a shared library.

Now, I'm working on implementing something like Martin's _dso_registry  
approach for registering the images. The part I'm having a hard time with  
is getting my loader code into the object files. Basically, I need to put  
a small function into each object file as a local comdat symbol. This is a  
lot more difficult than it first seemed. Martin has done this through  
manually writing assembly byte codes and whatnot to the object-file. I'm  
still hoping I will find a simpler way of doing this. I'm reading over the  
Apple Mach-O docs right now(thoroughly this time). Once I understand the  
object file format properly I'll give it a try. Martin's busy with the  
release right now though, so he doesn't have time to help.

   Bit


More information about the Digitalmars-d mailing list