Tired of maintaining symbol export lists for your shared libraries? The XL C/C++ V13.1 compiler introduces a new feature to control symbol visibility via in-source #pragma statements, or compile option. Instead of manually creating and editing an export symbol list with the -qexpfile option or CreateExportList tool, simply add an __attribute__((visibility("<value>"))) pragma to your function declaration to control the symbol visibility.
On AIX, the symbol visibility setting is now kept in an internal XCOFF field in the object file, so no external list or text file is necessary to pass to the linker! You must, however, ensure that your AIX system has an updated linker that supports the new visibility fields. The linker APARs needed are:
IV18856: SYMBOL VISIBILITY APPLIES TO AIX 6100-08
IV19424: SYMBOL VISIBILITY APPLIES TO AIX 7100-02
The end result to the dynamic symbol entries in the loader section is the same as if you used the old export list method, so shared libraries are still compatible with each other. Here is a quick example showing the #pragma functionality:
$ instfix -ik IV19424 ( or IV18856 )
All filesets for IV19424 were found.
$ cat test.c
int __attribute__((visibility("hidden"))) func()
return func() + 4;
$ xlc -c test.c
$ xlc -qmkshrobj test.o -o shr.o
$ dump -Tv shr.o
***Loader Symbol Table Information***
[Index] Value Scn IMEX Sclass Type IMPid Name
 0x20000200 .data EXP DS SECdef [noIMid] func2
The func() symbol is now hidden to the loader, but can still be called internally by func2().
For more information on the feature and it's compatibility with GCC's visibility push/pop functionality, check out the V13.1 documentation here:
Using visibility attributes (IBM extension)
Questions/comments about the feature? Contact us on the C/C++ Forum or @ibm_compilers on Twitter.