Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Continuing Linux Porting issues



I hate to keep bothering the list with this stuff, but I haven't been able to find documents related to my problem (yet).

So I'm porting a big Linux C++ application that makes heavy use of plug-ins. I've built all the plugins on OSX as .dylib files and am linking them in with either -l in the linker or by calling dlopen the first time each library is used. The application makes heavy use of the factory pattern, most classes are created by a factory class. When a library is loaded it registers all it's classes automatically with the factory (usually during the libraries static init phase), then classes are created by sending requests to the factory.

Anyway, I am having serious problems getting all of this to load and run correctly. I am building everything with a modified Makefile (no Xcode) and using Xcode to debug it. The first problem seems to be that unless I set DYLD_BIND_AT_LAUNCH my program fails the minute it trys to call a static method in one of the key libraries. If I do set the BIND option, it gets a little farther but still does something disturbing.

The layout of the program is something like this.

main -- contains almost nothing, begins by calling functions in libutility, then in libapplication

libfuncs -- contains some low level C data manipulation functions

libport -- contains some C wrappers to make system functions portable

libutility -- contains some C++ utility classes

libapplication -- contains most of the application specific classes, there is one base class in this lib which most other classes built into the library descend from. Each class was built from a seperate .cpp file.

All of this stuff was fully linked without errors, ie: main did -lfuncs -lport -lutility -lapplication
libapplication was built with -lfuncs -lport -lutility and so on.

With DYLD_BIND_AT_LAUNCH turned OFF, the first time I call a static method in libapplication, the application immediately freezes up, even before executing a line of code in libapplication. The debugger shows me about 120 stack frames deep stuck in a mutex waiting on a semaphore. The same pattern of calls repeats about 12 times, this pattern includes calls to:

__dyld_call_module_initializers_for_library
__dyld_call_module_initializers
__dyld_link_in_need_modules
__dyld_bind_lazy_symbol_reference
__dyld_stub_binding_helper_interface

This appears to be doing lazy linking of symbols in the library, but at some point it just gives up and hangs in the mutex, I'm not sure why. I do know that initializing the classes in libapplication will require initializing many classes in the other libraries as well.

If I TURN ON the DYLD_BIND_AT_LAUNCH then the program makes it through the initial startup code, but some of the modules in libapplication never have their static initialization code called, preventing them from registering with the object factory so the program quickly fails because it thinks some of the classes it needs aren't there. Under linux, when this library is loaded, all the initialization code for all the classes in the library are automatically called, under OSX this doesn't seem to happen.

If anyone has any ideas on how to resolve either of these problems it would be REALLY appreciated. This app is so close to working, all these linking problems are getting very frustrating. I've never had this much trouble just getting an app to link before.

Greg Corson
Sony R&D
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.


References: 
 >Re: Porting from Linux, plug-ins that depend on other plug-ins (From: Geoffrey Schmit <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.