Questions: collect2 rflag + AIX run time linking

David Edelsohn dje@watson.ibm.com
Fri May 2 16:58:00 GMT 2003


>>>>> Michael Lo writes:

Michael> AIX runtime linking not working for C++ when using GCC
Michael> ==========================================
Michael> I build two shared libraries  libbaseMIB.o and logAlarmTrapBase  which
Michael> are  created with -Wl,-G flag and -shared.
Michael> AIX ld does not insist on resolve all symbols when I uses the -G since
Michael> run time linking enabled with -G.  These two libraries depend on each
Michael> other.  I decide to resolve all symbols when building the final
Michael> executables by putting them on the command line (see below). However, I
Michael> got runtime linker errors.

Michael> Why do I get run time link error ?
Michael> Do you know how I can defer symbol resolution until I build the
Michael> executable, create_default_base_mib.

Michael> Can gcc help to build an export list which could be used in the linking
Michael> of create_default_base_mib ?  Could you give me an example on how to
Michael> defer symbol resoultion until link time of executables.
Michael> I could not find any in the web ? Thanks.
Michael> (I did not compile the gcc, so not sure if the COLLECT_EXPORT_LIST macro
Michael> will help in my case when compiling collect2.c?)

	You are discussing multiple, distinct issues.

1) GCC on AIX is working as designed.  Collect2 needs to scan and include
the ctors/dtors before the garbage-collecting linker purges the
references.  This results in increased executable size when linking with
non-shared libraries.  The alternatives are even less pleasant and
user-friendly. 

2) -bexpall and -bautexp do not export all symbols.  Symbols beginning
with an underscrore (_) are not exported.  The C++ ABI prepends an
underscore to symbols, so you manually need to create an export list to
use with the -Wl,-bE:???.exp link option.

To create an export list using

nm -BCpg <objs> | awk '{ if ((($2 == "T") || ($2 == "D") || ($2 == "B")) && (substr($3,1,1) != ".")) { print $3 } }' | sort -u > export_file

David



More information about the Gcc-help mailing list