nm & dump in AIX

In Solaris, Linux and HP-UX, I have used nm to see exported symbols in my shared library. So I have started using the same command in AIX also. But, in the command output, all my exported symbols are prefixed with dot [.]. Moreover, there are lot many symbols in ” T ” [Global Text] section of the output. Even, basic string functions like strlen, memcpy are also under ” T “. I thought there might be a bug in my makefiles and tried to fix them. After debugging this for 6 hours, I thought of trying other commands also. Finally I have tried dump [dump -HTv] and I got the output exactly what I have expected. Functions like strlen,memcpy are under undef section. So, in AIX, it is better to use dump for seeing symbols in the shared library. As I dont have free time, I have not investigated why nm was showing symbols in a different manner.

Advertisements

Problems with linking of shared libraries in AIX

    Normally, in Solaris, Linux and other common platforms, shared libraries are represented with .so/.sl suffix. Static libraries are represented with .a suffix in filenames. But in AIX, static libraries have .a suffix and shared libraries can have either .so or .a suffix.

when we try to compile a c file which uses shared library with .so suffix, it wont succeed by default. It gives a compilation error. Additionally we have to pass “-Wl,-brtl” flag to the compiler. “-Wl” is to say that it is a flag to the linker, so “-brtl” is internally passed to the linker [ld]. “-brtl” says that it should consider files with .so suffix also as shared libraries. There is no need to pass this flag when your shared library contains .a suffix. This type of linking is loadtime linking.

When we want to access a shared library at runtime using dlopen & dlsym calls, it is called runtime linking. In this case, we wont get any compilation errors. If the shared library contains .a suffix, we wont get any errors at runtime also. But if the shared library contains .so suffix, we get segmentation fault at runtime. Confusing thing is, it succesfully executes dlopen call, but at the time of dlsym, it exits with segmentation fault. If we give “-Wl-brtl” flag to compiler at compilation time, runtime linking goes fine.