Re: Delayed Framework Loading
Re: Delayed Framework Loading
- Subject: Re: Delayed Framework Loading
- From: Dong Feng <email@hidden>
- Date: Sat, 13 Jun 2009 08:58:21 +0800
2009/6/13 Greg Guerin <email@hidden>:
> Dong Feng wrote:
>
>> __attribute__((constructor))
>> static void MyModuleInitializer()
>> {
>> static initialized = 0;
>> if (!initialized)
>> {
>> // Initialization code.
>> initialized = 1;
>> }
>> }
>>
>> int test_export()
>> {
>> return 112233;
>> }
>>
>> and each time MyModuleInitializer() is invoked at launch time,
>> regardless how late test_export() is invoked.
>
> Maybe you're doing it wrong.
>
> Referring to this gcc reference page:
>
> http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
>
> "The constructor attribute causes the function to be called automatically
> before execution enters main()."
>
> It sounds like it's doing exactly what you told it to do.
>
> -- GG
>
Thanks for the answer. It sounds correct, and I may give up to find a
way to make linker simulate the CFURLCreateWithFileSystemPath().
Actually I have a framework written by others, which does a lot
initialization work at launch time. I wonder the initialization is
done in an __attribute__((constructor)) function but I don't have the
source code.
I can delay the launch-time initialization of that framework by using
CFURLCreateWithFileSystemPath() but the downside is I have to resolve
the addresses of functions I am going to use one by one
programmatically.
The question rose by the first mail is to found a way making the
linker do the function address resolving (i.e. dynamic link)
automatically (as what achieved by link/weak-link the framework
directly) but still get the same lazy-initialization effect as what
achieved by CFURLCreateWithFileSystemPath().
I used to think, although __attribute__((constructor) is claimed to be
invoked before main(), it would be delayed if the whole framework load
can be delayed (as the case of manually load by
CFURLCreateWithFileSystemPath() ) by some linkage flag. I was told on
Vistual C++ the /UNLOAD flag can delay the load of the whole DLL
(including the load of DllMain(), initialization of any static global
object). But it seems there is no way to tell linker do such for me
with a MacOS X framework.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden