vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I'm building a shared library which has some global objects. I'm building these with g++ 4.1.1 on an AIX 5.3. This was working alright with the the constructors of the global objects being called correctly. I recently made a change in the build script to use the gcc -pthread option since I was planning on adding some threading to the shared library (no code changes made yet). However with this build file change however, none of the constructors for the global objects are getting called. Remove this and it works again. I'm at a loss trying to understand whats going on and stuck. I've gone thru http://www.ibm.com/developerworks/ai...ry/au-gnu.html and doing pretty much what it suggests. I've also tried explicitly using the AIX's linker's option to specify _GLOBAL__DT as the init routine also - but that does not help either. Any pointers will be much appreciated. |
| ||||
| Turns out its an AIX bug: http://www.ibm.com/developerworks/fo...hreadID=119546 <from the original post> There is a bug in /usr/include/sys/thread.h of AIX oslevel 5.3.0.0, which does not appear in AIX 5.2 an earlier. Look at declaration of type 'thread_creds_t', actually being a variable-definition rather than a type-declaration, due to the missing keyword 'typedef'. <br /> /* Kernel view of thread credemtials structure (size-invariant) */<br / > struct thread_credentials {<br /> uint flags; /* Control structure data */<br /> cred_ext_t cred; /* Credentials to be modified */<br /> int reserved[9]; /* reserved fields for future */<br /> } thread_creds_t;<br /> This causes some very strange gcc-behaviour: When there is more than one global constructor in a c++ project, then only one global object gets constructed. The clue is that gcc seems to create only one global-constructor-entry per object file, giving it the mangled name of the first global object in the source. So all object files having sys/thread.h compiled in, contain a global- constructor-entry of the same name, so only one of them gets collected (by gcc's collect2), and therefore only one is executed at program- startup. As the type 'thread_creds_t' is introduced first with AIX 5.3, there is a simple workaround: Just define thread_creds_t to nothing, i.e. 'gcc -Dthread_creds_t=' <end copy> |