It seems to me that when linking on AIX an executable (via g++/collect2/ld) from a *.a archive, 'collect2' fetches every constructors and destructors from the archive, not only the ones actually linked into the executable.
Example main program:
Code:
/* collect2_main.cc */
#include <cstdio>
int main ()
{
fprintf (stderr, "Main program nothing special\n");
fflush (stderr);
}
Example program to put into a *.a library:
Code:
/* collect2_bait.cc */
#include <cstdio>
class HibaProvokalo {
public:
HibaProvokalo ();
};
HibaProvokalo::HibaProvokalo ()
{
fprintf (stderr, "HibaProvokalo: Why am I called?\n");
fflush (stderr);
}
HibaProvokalo hp;
Linkage:
Code:
g++ -c -o collect2_bait.o collect2_bait.cc
ar crs collect2_bait.a collect2_bait.o
g++ -c -o collect2_main.o collect2_main.cc
g++ -Wl,-debug -o collect2_prob_a collect2_main.o collect2_bait.a
./collect2_prob_a
HibaProvokalo: Why am I called?
Main program nothing special
Note: I detected this problem when I couldn't build mysql-5.5.38 on AIX 6.1 with g++ 4.6.4