Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#7559 closed Bugs (fixed)

gcc-compatible symbol visibility not supported for clang

Reported by: James Walker <jamesw@…> Owned by: John Maddock
Milestone: To Be Determined Component: config
Version: Boost Development Trunk Severity: Problem
Keywords: Cc: jonathan.jones@…

Description

boost/config/compiler/gcc.hpp defines BOOST_SYMBOL_VISIBLE and BOOST_SYMBOL_EXPORT to be attribute((visibility("default"))) when not running under Windows. But boost/config/compiler/clang.hpp does not define these symbols. This creates compatibility problems on OS X when linking binaries built with gcc to binaries built with clang. Since clang is used as a replacement for gcc, I would expect that BOOST_SYMBOL_VISIBLE and BOOST_SYMBOL_EXPORT should be defined in the same way for clang.

Change History (10)

comment:1 by Jonathan Jones <jonathan.jones@…>, 10 years ago

Cc: jonathan.jones@… added

comment:2 by James Walker <jamesw@…>, 10 years ago

Oops, the underscores in __attribute__ were taken as WikiFormatting.

comment:3 by Michel Morin, 10 years ago

(In [81052]) Adding BOOST_SYMBOL_VISIBLE macro; refs #7559

in reply to:  3 ; comment:4 by James Walker <jamesw@…>, 10 years ago

Replying to michel:

(In [81052]) Adding BOOST_SYMBOL_VISIBLE macro; refs #7559

Is there a reason for not also defining BOOST_SYMBOL_EXPORT?

in reply to:  4 comment:5 by Michel Morin, 10 years ago

Is there a reason for not also defining BOOST_SYMBOL_EXPORT?

I'll add BOOST_SYMBOL_EXPORT and BOOST_SYMBOL_IMPORT after collecting information about clang on the Windows platform. It will be done in a few days, I think.

comment:6 by Mathias Gaunard, 10 years ago

on the Windows platform clang uses the code path in platform/win32.hpp. clang supports both __attribute__ and __declspec.

What I'd recommend is to put in compiler/clang.hpp the following

#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32))
#define BOOST_SYMBOL_EXPORT __attribute__((__visibility__("default")))
#define BOOST_SYMBOL_IMPORT
#define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default")))
#endif
Last edited 10 years ago by Mathias Gaunard (previous) (diff)

comment:7 by John Maddock, 10 years ago

Just a note to say I'm aware of this issue, but as I'm not a Clang user I'd really like for someone to provide a patch that I can just blindly go ahead and apply...

Thanks, John Maddock.

comment:8 by Michel Morin, 10 years ago

I was planning to add the following

//
// Dynamic shared object (DSO) and dynamic-link library (DLL) support
//
#if (defined(_WIN32) || defined(__WIN32__) || defined(WIN32)) && !defined(__CYGWIN__)
     // All Win32 development environments, including 64-bit Windows and MinGW, define 
     // _WIN32 or one of its variant spellings. Note that Cygwin is a POSIX environment,
     // so does not define _WIN32 or its variants.
#  define BOOST_HAS_DECLSPEC
#else
#  define BOOST_SYMBOL_EXPORT __attribute__((__visibility__("default")))
#  define BOOST_SYMBOL_IMPORT
#endif
#define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default")))

But I'd like to defer the support for the Windows platform, since there are some subtleties on that platform. I'm going to add BOOST_SYMBOL_EXPORT and BOOST_SYMBOL_IMPORT macros only on other platforms (i.e. the #else branch) for the meantime.

The #if condition in the above code is copied from config/compiler/gcc.hpp. John, do you know why !defined(__CYGWIN__) is needed? It looks verbose, since _WIN32 or its variants are not defined on cygwin.

Also, would it be nice to define BOOST_SYMBOL_IMPORT only on non-Windows platform , as mentioned by Mathias?

Last edited 10 years ago by Michel Morin (previous) (diff)

comment:9 by Michel Morin, 10 years ago

Resolution: fixed
Status: newclosed

(In [81068]) Adding BOOST_SYMBOL_EXPORT and BOOST_SYMBOL_IMPORT; fixes #7559

comment:10 by Michel Morin, 10 years ago

I chose to use Mathias' code

#if !defined(_WIN32) && !defined(__WIN32__) && !defined(WIN32)
#  define BOOST_SYMBOL_EXPORT __attribute__((__visibility__("default")))
#  define BOOST_SYMBOL_IMPORT
#  define BOOST_SYMBOL_VISIBLE __attribute__((__visibility__("default")))
#endif

rather than copying the code from config/compiler/gcc.hpp.

Note: See TracTickets for help on using tickets.