The gcc documentation (gcc 4.4) states:
`init_priority (PRIORITY) '
In standard C ++, objects defined in the namespace area are guaranteed to be initialized in the order strictly corresponding to the order of their definition in a given translation unit. There are no guarantees for initialization between translation units. However, GNU C ++ allows users to control the initialization order of objects defined in the namespace area with the init_priority attribute by setting a relative PRIORITY, the constant integral expression is currently limited from 101 to 65535 inclusive. Lower numbers indicate higher priority.
Nowhere is there any indication of how this applies to libraries, especially shared libraries. I would expect the static libraries (libxyz.a) to work the same way as individual object files in this regard, since they are just a collection of object files, and the wording of the documentation assumes that it works through translation units (i.e. .With another object files).
However, shared libraries are actually executable files in their own right --- within this shared library, initialization is performed in the specified order, but shared libraries are generally initialized in the order specified by the dynamic loader, i.e. liba. therefore, it loads before or after libb.so based on the bootloaderโs ordering criteria, and the init_priority attribute cannot affect this ordering.
source share