Boost logo

Boost :

From: Niall Douglas (s_sourceforge_at_[hidden])
Date: 2021-02-02 14:47:46


On 02/02/2021 14:21, Peter Dimov via Boost wrote:

> It makes sense that everything EXPORTed/IMPORTed needs to also be
> VISIBLE; I can't think of any scenarios in which it doesn't need to be.
> So defining BOOST_SYMBOL_IMPORT to BOOST_SYMBOL_VISIBLE on non-Windows
> seems sensible. Others seem to disagree; I'm not sure what's the
> downside though.

The downside is that extern function symbols from other libraries then
get published.

I seem to be having difficulty communicating this to anyone here, so
here's a godbolt:

https://godbolt.org/z/jv5Y75

The extern functions thirdpartylib_*() are #include'd from a third party
library. This extern + inline linkage is as you might get from in-class
functions in a header-only class.

You can see in the disassembly that:

- thirdpartylib_hidden, which is when -fvisibility=hidden is on, and
THIRDPARTYLIB_DECL is nothing, has hidden visibility.

- thirdpartylib_nothidden, which is when -fvisibility=hidden is on, and
THIRDPARTYLIB_DECL is BOOST_SYMBOL_VISIBLE, has default visibility.

Now do nm -D of that binary:

                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
0000000000201028 B __bss_start
                 w __cxa_finalize
                 w __gmon_start__
0000000000201028 D _edata
0000000000201030 B _end
0000000000000600 T _fini
0000000000000490 T _init
00000000000005c9 T thirdpartylib_nothidden

As you can see, the symbol for thirdpartylib_nothidden has leaked into
the export set for this library. thirdpartylib_nothidden ought not to be
exported from this library, unless it has typeinfo which needs to be
visible.

Meanwhile thirdpartylib_hidden is NOT leaked from the exported symbols
of this library, and is instead local only:

0000000000200e60 d _DYNAMIC
0000000000201000 d _GLOBAL_OFFSET_TABLE_
                 w _ITM_deregisterTMCloneTable
                 w _ITM_registerTMCloneTable
00000000000006f8 r __FRAME_END__
000000000000060c r __GNU_EH_FRAME_HDR
0000000000201028 d __TMC_END__
0000000000201028 B __bss_start
                 w __cxa_finalize
0000000000000570 t __do_global_dtors_aux
0000000000200e58 t __do_global_dtors_aux_fini_array_entry
0000000000201020 d __dso_handle
0000000000200e50 t __frame_dummy_init_array_entry
                 w __gmon_start__
0000000000201028 D _edata
0000000000201030 B _end
0000000000000600 T _fini
0000000000000490 T _init
0000000000201028 b completed.7698
00000000000004e0 t deregister_tm_clones
00000000000005b0 t frame_dummy
0000000000000520 t register_tm_clones
00000000000005d8 t test
00000000000005ba t thirdpartylib_hidden
00000000000005c9 T thirdpartylib_nothidden

There is a small 't' instead of a capital 'T', indicating the symbol is
local only.

Niall


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk