large executables on AIX, incorrect calling of static constructors

Harco de Hilster harcoh@ATConsultancy.nl
Fri Sep 24 11:18:00 GMT 2004


A few days ago I filed a bug report (Bug c++/17480), which was closed as 
invalid. I would like to get some feedback on this issue.

Executables on AIX compiled with g++ get extremely large. We also 
noticed that we had to add a lot of extra libraries on the link line to 
resolve unexpected unresolved references. All other platforms we port to 
did not exhibit that behavior.

After investigating the issue, I found that collect2 collects references 
to the constructors and destructors of global static objects. Some extra 
code is generated, and linked with the program. Collect2 scans all 
objects and libraries on the link line. The effect is that the normal 
optimalization of the linker cannot be done, because collect2 introduces 
references to code otherwise not used. That explains the large sizes of 
the executables.
It also calls, on program startup, constructors in object modules that 
are not referenced by the original program. In my opinion that is a bug, 
because g++/ld on all other platforms discards those unreferenced object 
modules, and therefor does not call the static con-/destructors.

I've written a collect3 perl script, that performs some of the 
optimalization of the linker, and only collects the con-/destructors of 
object modules actually referenced by the application. The results are 
shown below:

collect2:
$ g++ -o hello hello.cpp
$ ls -l hello
-rwxr-xr-x   1 huminf   staff       3474251 24 Sep 11:42 hello*
$ g++ -o hello hello.cpp -lxercesc.210
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_settype
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_init
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutexattr_destroy
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-317 ERROR: Undefined symbol: _STL::cout
ld: 0711-317 ERROR: Undefined symbol: ._STL::ios_base::Init::~Init 
[in-charge]()
ld: 0711-317 ERROR: Undefined symbol: 
._STL::ios_base::_Loc_init::~_Loc_init [in-charge]()
ld: 0711-317 ERROR: Undefined symbol: 
._STL::ios_base::_Loc_init::_Loc_init[in-charge]()
ld: 0711-317 ERROR: Undefined symbol: 
._STL::ios_base::Init::Init[in-charge]()
ld: 0711-317 ERROR: Undefined symbol: ._STL::ios_base::_M_throw_failure()
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more 
information.
collect2: ld returned 8 exit status
$ g++ -o hello hello.cpp -lxercesc.210 -lstlport_gcc -lpthread
$ ls -l hello
-rwxr-xr-x   1 huminf   staff      10857393 24 Sep 11:44 hello*

collect3:
$ g++ -o hello hello.cpp
$ ls -l hello
-rwxr-xr-x   1 huminf   staff         12122 24 Sep 11:30 hello*
$ ./hello
how big can hello get
$ g++ -o hello hello.cpp -lxercesc.210
$ ls -l hello
-rwxr-xr-x   1 huminf   staff         12122 24 Sep 11:39 hello*

collect3 (http://www.atconsultancy.nl/download/collect3) is a prove of 
concept to show that g++/collect2 on AIX can behave identical to g++/ld 
on other platforms. Tested with gcc-3.3.2, aix5l. I hope the same 
optimalization can be added to collect2. Any feedback is welcome.

Harco

-- 
-----------------+--------------------+-------------------------------
Harco de Hilster  AT Consultancy       Phone:  +31(0)24-3527282      
Unix Consultant   Toernooiveld 104     Fax:    +31(0)24-3527292      
                  6501 BK  Nijmegen    E-mail: harcoh@ATConsultancy.nl
                  The Netherlands                                     
-----------------+--------------------+-------------------------------




More information about the Gcc-bugs mailing list