Boost logo

Boost :

Subject: Re: [boost] [config] GCC symbol visibility across shared libraries
From: Jürgen Hunold (juergen.hunold_at_[hidden])
Date: 2010-05-20 14:57:11


On Thursday, 20. May 2010 17:36:54 you wrote:
> Beman Dawes wrote:

>> We aren't proposing any change to that; I think both Jürgen and I were
>> trying to make fairly minimal changes to current Boost practice and
>> headers.

Right. I wanted to take as small steps as possible and don't risk to break
anything.

> The #ifdef BOOST_HAS_DECLSPEC surrounds everything, but would be false for
> GCC, right?

Therefore I replace those checks with BOOST_SYMBOL_EXPORT.

> I'd suggest that the BOOST_HAS_DECLSPEC check be managed by the config
> system so that BOOST_SYMBOL_EXPORT and BOOST_SYMBOL_IMPORT are defined
> appropriately (compressed into one place here):
>
> #define BOOST_SYMBOL_EXPORT
> #define BOOST_SYMBOL_IMPORT
> #define BOOST_SYMBOL_VISIBLE
>
> #ifdef BOOST_HAS_DECLSPEC
> # undef BOOST_SYMBOL_EXPORT
> # define BOOST_SYMBOL_EXPORT __declspec(dllexport)
> # undef BOOST_SYMBOL_IMPORT
> # define BOOST_SYMBOL_IMPORT __declspec(dllimport)
> #elif defined BOOST_HAS_VISIBILITY
> # undef BOOST_SYMBOL_VISIBLE
> # define BOOST_SYMBOL_VISIBLE __attribute__(visibility("default"))
> # ifdef BOOST_DEFAULT_VISIBILITY_IS_HIDDEN
> # undef BOOST_SYMBOL_EXPORT
> # define BOOST_SYMBOL_EXPORT BOOST_SYMBOL_VISIBLE
> # endif
> #endif
>
>
> BOOST_HAS_VISIBILITY would be undefined for most compilers, but would be
> defined for GCC (when __GNUC__ is defined, perhaps after some particular
> release, but I don't know when it was introduced).

I had the same idea, but decided to take small steps.
First, get visibility in with a minimal diff, then add support to Boost.Build
and then refactor. It is __GNUC_ > 4, by the way ;-))

> BOOST_DEFAULT_VISIBILITY_IS_HIDDEN must be defined for GCC, when __GNUC__
> >= 4, but only if using -fvisiblity=hidden. I haven't found a way to
> detect that, so I guess it has to be assumed or defined via the command
> line.

No. Visibility can always be explicitly specified. So no
BOOST_DEFAULT_VISIBILITY_IS_HIDDEN macro is needed.
I would simply always #define BOOST_SYMBOL_EXPORT/IMPORT to the correct values.

> Then, each library would use this instead:
>
> #define BOOST_WHATEVER_DECL
> #if defined BOOST_ALL_DYN_LINK || defined BOOST_WHATEVER_DYN_LINK
> # undef BOOST_WHATEVER_DECL
> # ifdef BOOST_WHATEVER_SOURCE
> # define BOOST_WHATEVER_DECL BOOST_SYMBOL_EXPORT
> # else
> # define BOOST_WHATEVER_DECL BOOST_SYMBOL_IMPORT
> # endif
> #endif
>
> Defining BOOST_WHATEVER_SOURCE in each library source file is rather
> awkward, but it does work. (I prefer to define that in the build command
> line via makefile or whatever. You can't forget it then.)

Well, most (all) libraries already have it the source. It is just a matter of
taste. And msvc will tell you very fast that you have no exported symbols...

> While the change I've shown is pervasive, the result is much simpler and
> cleaner for each library.

Yes, that is the goal. But I still prefer to do small steps.

Yours,

Jürgen

-- 
* Dipl.-Math. Jürgen Hunold       ! Ingenieurgesellschaft für 
* voice: ++49 511 262926 57       ! Verkehrs- und Eisenbahnwesen mbH  
* fax  : ++49 511 262926 99       ! Lister Straße 15
* juergen.hunold_at_[hidden]        ! www.ivembh.de
* 
* Geschäftsführer:                ! Sitz des Unternehmens: Hannover
* Prof. Dr.-Ing. Thomas Siefer    ! Amtsgericht Hannover, HRB 56965
* PD Dr.-Ing. Alfons Radtke       !

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