All of lore.kernel.org
 help / color / mirror / Atom feed
* Shared library symbol visibility
@ 2013-12-30 17:56 Noah Watkins
  2013-12-30 23:22 ` Josh Durgin
  0 siblings, 1 reply; 2+ messages in thread
From: Noah Watkins @ 2013-12-30 17:56 UTC (permalink / raw)
  To: ceph-devel@vger.kernel.org, James Harper, Alan Somers

It looks like we may be outgrowing the use of export-symbols-regex and
friends to control symbol visibility for published shared libraries.
On Linux, ld seems to be quite content linking against hidden symbols,
but at least on OSX with Clang it seems the visibility is strictly
enforced.

For instance, librados exports only the prefix "rados_", but that
regex hides everything in the C++ interface. Unfortunately,
export-symbols-regex doesn't play nice with C++ name mangling.

Large projects that I've been looking at for examples (chromium, v8,
Java) seem to use a different approach based on the compiler flag
"-fvisibility=hidden" that hides everything by default and uses
explicit exporting.

These are the basics, and there are variants that work on Windows for
DLL's as well with more macro magic.

#define CEPH_EXPORT __attribute__((__visibility__("default")))

  class CEPH_EXPORT ObjectOperation {
    public:
      ObjectOperation();
      virtual ~ObjectOperation();
      ...

There is a sample branch up with this approach at:

   http://github.com/ceph/ceph port/visibility

More info

https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html
http://gcc.gnu.org/wiki/Visibility

- Noah

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Shared library symbol visibility
  2013-12-30 17:56 Shared library symbol visibility Noah Watkins
@ 2013-12-30 23:22 ` Josh Durgin
  0 siblings, 0 replies; 2+ messages in thread
From: Josh Durgin @ 2013-12-30 23:22 UTC (permalink / raw)
  To: Noah Watkins, ceph-devel@vger.kernel.org, James Harper,
	Alan Somers

On 12/30/2013 09:56 AM, Noah Watkins wrote:
> It looks like we may be outgrowing the use of export-symbols-regex and
> friends to control symbol visibility for published shared libraries.
> On Linux, ld seems to be quite content linking against hidden symbols,
> but at least on OSX with Clang it seems the visibility is strictly
> enforced.
>
> For instance, librados exports only the prefix "rados_", but that
> regex hides everything in the C++ interface. Unfortunately,
> export-symbols-regex doesn't play nice with C++ name mangling.
>
> Large projects that I've been looking at for examples (chromium, v8,
> Java) seem to use a different approach based on the compiler flag
> "-fvisibility=hidden" that hides everything by default and uses
> explicit exporting.
>
> These are the basics, and there are variants that work on Windows for
> DLL's as well with more macro magic.
>
> #define CEPH_EXPORT __attribute__((__visibility__("default")))
>
>    class CEPH_EXPORT ObjectOperation {
>      public:
>        ObjectOperation();
>        virtual ~ObjectOperation();
>        ...
>
> There is a sample branch up with this approach at:
>
>     http://github.com/ceph/ceph port/visibility
>
> More info
>
> https://www.gnu.org/software/gnulib/manual/html_node/Exported-Symbols-of-Shared-Libraries.html
> http://gcc.gnu.org/wiki/Visibility

This is great! It serves as a good reminder when you're touching public
interfaces as well. It may be annoying to add it to everything
initially, but it seems quite nice once it's in place!

Josh

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-12-30 23:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-30 17:56 Shared library symbol visibility Noah Watkins
2013-12-30 23:22 ` Josh Durgin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.