[zeromq-dev] [PATCH] DSO symbol visibility

Martin Lucina mato at kotelna.sk
Thu Nov 25 15:15:06 CET 2010


Hi,

I've made a *draft* patch which introduces proper symbol visibility in the
libzmq.so DSO, at least on systems with GCC >= 4.0.

I've tried the least invasive approach code-wise, so what I've done is:

1) Added -fvisibility=hidden to LIBZMQ_EXTRA_CXXFLAGS if using GCC/G++.
This causes all symbols in objects compiled with those flags to have hidden
visibility by default.

2) In zmq.cpp (definitions), zmq.h and zmq_utils.h I have added the
appropriate prologue/epilogue to set the symbol visibility for all
functions declared or defined in those files back to "default" (i.e.
normal). This ensures that the API is exported correctly.

3) In order to hide OpenPGM's symbols I also added -fvisibility=hidden to
LIBZMQ_EXTRA_CFLAGS, again only when GCC/G++ is in use. I also defined
-DPGM_GNUC_INTERNAL to nothing; this ensures that the -fvisibility setting
is used for everything if present.

The above looks like it should all work, but has the following known
problems:

a) It'll fail on GCC < 4.0. For this I need to write an autoconf test that
will check if -fvisibility is actually supported by the compiler and if
not, just not use it. The parts in the actual source code can check against
__GNUC_MAJOR__.

Has anyone ever done anything like this with autoconf? How to check if the
compiler supports some flag is not obvious... Help with auto-kung-fu
appreciated :-)

b) It *should* work on Windows; there we already use __declspec() so for
the sake of sanity I guess we should not touch -fvisibility at all?

Comments please... I'd like to get this in master ASAP, that will mean we
can bump the ABI version in the soname to 1.0.0 and actually claim real ABI
stability for 2.1.x.

I guess another step would be explicit symbol versioning but I don't yet
fully understand the implications of that (a good guide is Drepper's paper:
http://www.akkadia.org/drepper/dsohowto.pdf) so it can wait.

Cheers,

-mato

-------------- next part --------------
A non-text attachment was scrubbed...
Name: dso-visibility-draft.patch
Type: text/x-diff
Size: 3436 bytes
Desc: not available
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20101125/71ad52c7/attachment.patch>


More information about the zeromq-dev mailing list