This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, collect2] AIX depth-first shared object initializers

The System V ABI specifies that the initialization functions are
called in depth-first dependence order. The AIX runtime loader does
not impose that ordering and generally initializes shared objects in
breadth-first order.  Yeah.  Moving on.

The attached patch enhances collect2 to initialize shared libraries in
depth-first dependency order.  The patch accomplishes this by adding
new special global init and fini symbols for AIX named GLOBAL__AIXI
and GLOBAL__AIXD.  The historical GLOBAL__FI and GLOBAL_FD symbols
remain and are initialized as usual for backward compatibility and

If the GLOBAL__AIXI and GLOBAL__AIXD symbols are found in a dependent
shared object while linking a shared object, those constructors are
added to the initializer list of the shared object being processed and
assigned highest priority. When an executable and shared objects with
this functionality are run and its initializers are invoked, the
initializer first will call the initializers of dependent shared
objects, which will call initializers of its dependent objects, etc.
The normal guard against multiple invocations prevents repeated
invocation from dependent invocations and from the normal AIX shared
object initializer mechanism.

The initializers of a shared object created without the new
functionality will be invoked with the normal mechanism and the
default AIX order.  And the backward compatible GCC shared object
symbols are provided if a shared object created with the new
functionality is linked by an older version of collect2 -- the
dependence ordering is not utilized and the previous, AIX loader-based
initialization mechanism is utilized.

Executables and shared objects built and linked with dependencies on
shared objects providing the new symbols will not function with an
older shared objects in which those symbols are missing. In other
words, if a user mixes versions of libraries, things will break, as
one would expect.

Andrew Dixie and I have been building and using GCC with this feature
for over six months.  Are the collect2 changes okay?

Thanks, David

2013-11-20  David Edelsohn  <>
                 Andrew Dixie  <>


        * config/rs6000/aixinitfini.c: New file.
        * config/rs6000/t-aix-cxa (LIB2ADD_ST): Add aixinitfini.c.
        * config/rs6000/libgcc-aix-cxa.ver (GCC_4.9): Add libgcc initfini


        * config/rs6000/aix.h (COLLECT_SHARED_INIT_FUNC): Define.

        * collect2.c (aix_shared_initname): Declare.
        (aix_shared_fininame): Declare.
        (symkind): Add SYM_AIXI and SYM_AIXD.
        (scanfilter_masks): Add SCAN_AIXI and SCAN_AIXD.
        (struct names special): Add GLOBAL__AIXI_ and GLOBAL__AIXD_.
        (aixlazy_flag): Parse.
        (extract_init_priority): SYM_AIXI and SYM_AIXD have highest priority.
        (scan_prog_file, COFF): Handle SYM_AIXI and SYM_AIXD.

Attachment: aixinitfini.txt
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]