c++cunixnm

How to know the visibility of a symbol in an object file


The visibility (from __ attribute __(visibility("...")) and -fvisibility) of a symbol can be known from a so file

nm -C lib.so

t is hidden, T is exported(i.e. default). But how to get this information from an object file directly?

nm -C lib.o

Will always print T for non C-static symbols whatever the visibility is.


Solution

  • The visibility is different from whether the symbol is local or global (which is what the lower-case/upper-case letters describe). A hidden symbol still can have external linkage, i.e. it is not limited to a translation unit.

    I don't think nm has an option to show visibility, but you can use either

    objdump -Ct lib.o
    

    which will show an attribute .hidden if the symbol is hidden or

    readelf -s lib.o
    

    which has a column for the visibility (DEFAULT/HIDDEN).