[CMake] How to use a generated linker map with a shared library?

Paul Smith paul at mad-scientist.net
Tue Jan 17 13:20:23 EST 2017


On Mon, 2017-01-16 at 09:07 -0700, clinton at elemtech.com wrote:
> > Yes, thanks for that info.  My situation is that I need to force ALL 
> > symbols to be private, even those from external static shared libraries 
> > that I'm linking in (whose symbols have global visibility by default).
> 
> Have you tried the "--exclude-libs ALL" linker option?  Using that
> should hide symbols from static libraries.

Yes, I looked at this.  I can't quite figure out what algorithm it uses
though.  It gives me _almost_ the same results as my linker script with
"local: *;", but not quite:

With the linker script if I use:

  nm libfoo.so | grep ' [A-TV-Z] '

I see only and exactly the symbols I marked as global in my code, and
nothing else as global.

If I use --exclude-libs=ALL then I see the symbols I marked as global
and _almost_ all the other symbols are local, but there some
exceptions; for example:

0000000001f925a0 A __bss_start
0000000001f925a0 A _edata
0000000001fc0f4f A _end
000000000098c648 T _fini
000000000015b1b8 T _init

In addition, some C++ templated symbols (very complex) are public as
"W" (global weak symbols).  I don't know why.

I wonder whether _fini and _init need to be exported in order to
properly handle global ctor/dtor when the library is loaded/unloaded?
 Hm.  I may need to do some experimentation here.

I don't see any point in the static data symbols being public.


More information about the CMake mailing list