tags:

views:

52

answers:

2

I'm building a shared library which I dynamically load (using dlopen) into my AIX application using IBM's VisualAge C/C++ compiler. Unfortunately, it appears to be stripping out necessary symbols:

rtld: 0712-002 fatal error: exiting.
rtld: 0712-001 Symbol setVersion__Q2_3CIF17VersionReporterFRCQ2_3std12basic_stringXTcTQ2_3std11char_traitsXTc_TQ2_3std9allocatorXTc__ was referenced
from module ./object/AIX-6.1-ppc/plugins/plugin.so(), but a runtime definition
of the symbol was not found.

Both the shared library and the application which loads the shared library compile/link against the static library which contains the VersionReporter mentioned in the error message.

To link the shared library I'm using these options: -bM:SRE -bnoentry -bexpall To link the application, I'm using this option: -brtl

Is there an option I can use to prevent this symbol from being stripped in the application? I've tried using -nogc as stated in the IBM docs, but that causes the shared library to be in an invalid format or the application to fail to link (depending on which one I use it with).

A: 

I figured this out. The trick is to use an export list so that symbols used in the plugin but not used in the binary aren't stripped out.

# version.exp:
setVersion__Q2_3CIF17VersionReporterFRCQ2_3std12basic_stringXTcTQ2_3std11char_traitsXTc_TQ2_3std9allocatorXTc__

And then when linking the application use: -brtl -bexpfull -bE:version.exp

There's more information here: Developing and Porting C and C++ Applications on AIX.

smountcastle
+1  A: 

Yes. This is not really connected to a particular language or compiler. The same general technique is used for gcc for example. -bI:foo.exp is used to tell the linker that the symbols listed in foo.exp will come from the name at the top. Likewise, -BE:dog.exp is used to tell the linker that the symbols listed in dog.exp are exported and can be used by others.

You can see /bin/ldd and /bin/dump can be used to review these symbols.