Skip to content
Snippets Groups Projects
Forked from Core Modules / dune-common
4710 commits behind the upstream repository.
  • Steffen Müthing's avatar
    e628bebd
    [Buildsystem] Provide macros for explicitly marking symbols as exported or private · e628bebd
    Steffen Müthing authored
    This patch adds a new header visibility.hh with macros DUNE_EXPORT and DUNE_PRIVATE
    to mark symbols as exported or private at the ABI level.
    
    While we do not explicitly mark any symbols as hidden, there are certain situations
    in which the compiler creates symbols with incorrect linkage, especially for singleton
    accessor methods for templated types and their embedded static variables, which involve
    the creation of weak symbols.
    
    The linker is then unable to merge those weak definitions, causing either a link-time
    failure (when building static libraries) or undefined runtime behaviour (dynamic libraries).
    
    This problem can be avoided by explicitly marking the singleton accessor methods as
    DUNE_EXPORT. For symmetry, there is also a DUNE_PRIVATE macro, but while it works, I don't
    see it used very much in the short term.
    e628bebd
    History
    [Buildsystem] Provide macros for explicitly marking symbols as exported or private
    Steffen Müthing authored
    This patch adds a new header visibility.hh with macros DUNE_EXPORT and DUNE_PRIVATE
    to mark symbols as exported or private at the ABI level.
    
    While we do not explicitly mark any symbols as hidden, there are certain situations
    in which the compiler creates symbols with incorrect linkage, especially for singleton
    accessor methods for templated types and their embedded static variables, which involve
    the creation of weak symbols.
    
    The linker is then unable to merge those weak definitions, causing either a link-time
    failure (when building static libraries) or undefined runtime behaviour (dynamic libraries).
    
    This problem can be avoided by explicitly marking the singleton accessor methods as
    DUNE_EXPORT. For symmetry, there is also a DUNE_PRIVATE macro, but while it works, I don't
    see it used very much in the short term.
visibility.hh 1.38 KiB
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#ifndef DUNE_COMMON_VISIBILITY_HH
#define DUNE_COMMON_VISIBILITY_HH

/** \file
 * \brief Definition of macros controlling symbol visibility at the ABI level.
 */

#ifdef DOXYGEN

//! Export a symbol as part of the public ABI.
/**
 * Mark a class, function or static variable as visible outside the current DSO.
 * For now, this is mostly important for templated global variables and functions
 * that contain static variables.
 */
#define DUNE_EXPORT implementation_defined

//! Mark a symbol as being for internal use within the current DSO only.
/**
 * Mark a class, function or static variable as inaccessible from outside the current DSO.
 * Doing so will decrease the size of the symbol table, but you have to be sure that the
 * symbol will never have to be accessed from another library or the main executable!
 */
#define DUNE_PRIVATE implementation_defined

#else // DOXYGEN

#if __GNUC__ >= 4
// GCC and Clang both define __GNUC__ to 4 and they both support the visibility
// attribute
#define DUNE_EXPORT __attribute__((visibility("default")))
#define DUNE_PRIVATE __attribute__((visibility("hidden")))
#else
// We don't know about the active compiler, so just turn the visibility macros to no-ops.
#define DUNE_EXPORT
#define DUNE_PRIVATE
#endif

#endif // DOXYGEN

#endif // DUNE_COMMON_VISIBILITY