C/C++ and Fortran

C/C++ and Fortran

Connect, learn, share, and engage with IBM Power.

 View Only

No more symbol export lists with the new visibility attribute feature!

By Archive User posted Fri June 13, 2014 12:41 AM

  

Originally posted by: xlsup_lac


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
     http://www-01.ibm.com/support/docview.wss?uid=isg1IV18856

     IV19424: SYMBOL VISIBILITY APPLIES TO AIX 7100-02
     http://www-01.ibm.com/support/docview.wss?uid=isg1IV19424  

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 5;
     }
     
     int func2()
     {
            return func() + 4;
     }
     $ xlc -c test.c
     $ xlc -qmkshrobj test.o -o shr.o
     $ dump -Tv shr.o
     shr.o:
                            ***Loader Section***
                            ***Loader Symbol Table Information***
     [Index]      Value      Scn     IMEX Sclass   Type           IMPid Name
     [0]     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)
     
http://www-01.ibm.com/support/knowledgecenter/SSGH2K_13.1.0/com.ibm.xlc131.aix.doc/proguide/tvopvisattr.html

Questions/comments about the feature?  Contact us on the C/C++ Forum or @ibm_compilers on Twitter.

0 comments
0 views

Permalink