From: <vac...@us...> - 2010-03-10 18:24:55
|
Revision: 173 http://xmlwrapp.svn.sourceforge.net/xmlwrapp/?rev=173&view=rev Author: vaclavslavik Date: 2010-03-10 18:24:44 +0000 (Wed, 10 Mar 2010) Log Message: ----------- Add support for ELF symbols visibility. The libraries are now built so that only public API symbols are exported into shared library. This means fewer symbols to resolve at runtime and smaller risk of any symbols conflicts. Modified Paths: -------------- trunk/bootstrap trunk/configure.ac trunk/include/Makefile.am trunk/include/xmlwrapp/_cbfo.h trunk/include/xmlwrapp/attributes.h trunk/include/xmlwrapp/document.h trunk/include/xmlwrapp/event_parser.h trunk/include/xmlwrapp/exception.h trunk/include/xmlwrapp/init.h trunk/include/xmlwrapp/node.h trunk/include/xmlwrapp/nodes_view.h trunk/include/xmlwrapp/tree_parser.h trunk/include/xsltwrapp/init.h trunk/include/xsltwrapp/stylesheet.h trunk/src/Makefile.am trunk/src/libxml/utility.cxx Added Paths: ----------- trunk/admin/visibility.m4 trunk/include/xmlwrapp/export.h Added: trunk/admin/visibility.m4 =================================================================== --- trunk/admin/visibility.m4 (rev 0) +++ trunk/admin/visibility.m4 2010-03-10 18:24:44 UTC (rev 173) @@ -0,0 +1,132 @@ +dnl visibility.m4 serial 1 (gettext-0.15) +dnl Copyright (C) 2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +dnl From Bruno Haible. + +dnl Modified for use in wxWidgets by Vaclav Slavik: +dnl - don't define HAVE_VISIBILITY (=0) if not supported +dnl - use -fvisibility-inlines-hidden too +dnl - test in C++ mode + +dnl Tests whether the compiler supports the command-line option +dnl -fvisibility=hidden and the function and variable attributes +dnl __attribute__((__visibility__("hidden"))) and +dnl __attribute__((__visibility__("default"))). +dnl Does *not* test for __visibility__("protected") - which has tricky +dnl semantics (see the 'vismain' test in glibc) and does not exist e.g. on +dnl MacOS X. +dnl Does *not* test for __visibility__("internal") - which has processor +dnl dependent semantics. +dnl Does *not* test for #pragma GCC visibility push(hidden) - which is +dnl "really only recommended for legacy code". +dnl Set the variable CFLAG_VISIBILITY. +dnl Defines and sets the variable HAVE_VISIBILITY. + +AC_DEFUN([XMLWRAPP_VISIBILITY], +[ + AC_REQUIRE([AC_PROG_CC]) + if test -n "$GCC"; then + CFLAGS_VISIBILITY="-fvisibility=hidden" + CXXFLAGS_VISIBILITY="-fvisibility=hidden -fvisibility-inlines-hidden" + AC_MSG_CHECKING([for symbols visibility support]) + AC_CACHE_VAL(wx_cv_cc_visibility, [ + wx_save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY" + AC_LANG_PUSH(C++) + AC_TRY_COMPILE( + [ + /* we need gcc >= 4.0, older versions with visibility support + didn't have class visibility: */ + #if defined(__GNUC__) && __GNUC__ < 4 + error this gcc is too old; + #endif + + /* visibility only makes sense for ELF shared libs: */ + #if !defined(__ELF__) && !defined(__APPLE__) + error this platform has no visibility; + #endif + + extern __attribute__((__visibility__("hidden"))) int hiddenvar; + extern __attribute__((__visibility__("default"))) int exportedvar; + extern __attribute__((__visibility__("hidden"))) int hiddenfunc (void); + extern __attribute__((__visibility__("default"))) int exportedfunc (void); + class __attribute__((__visibility__("default"))) Foo { + Foo() {} + }; + ], + [], + wx_cv_cc_visibility=yes, + wx_cv_cc_visibility=no) + AC_LANG_POP() + CXXFLAGS="$wx_save_CXXFLAGS"]) + AC_MSG_RESULT([$wx_cv_cc_visibility]) + if test $wx_cv_cc_visibility = yes; then + dnl we do have basic visibility support, now check if we can use it: + dnl + dnl Debian/Ubuntu's gcc 4.1 is affected: + dnl https://bugs.launchpad.net/ubuntu/+source/gcc-4.1/+bug/109262 + AC_MSG_CHECKING([for broken libstdc++ visibility]) + AC_CACHE_VAL(wx_cv_cc_broken_libstdcxx_visibility, [ + wx_save_CXXFLAGS="$CXXFLAGS" + wx_save_LDFLAGS="$LDFLAGS" + CXXFLAGS="$CXXFLAGS $CXXFLAGS_VISIBILITY" + LDFLAGS="$LDFLAGS -shared -fPIC" + AC_LANG_PUSH(C++) + AC_TRY_LINK( + [ + #include <string> + ], + [ + std::string s("hello"); + return s.length(); + ], + wx_cv_cc_broken_libstdcxx_visibility=no, + wx_cv_cc_broken_libstdcxx_visibility=yes) + AC_LANG_POP() + CXXFLAGS="$wx_save_CXXFLAGS" + LDFLAGS="$wx_save_LDFLAGS"]) + AC_MSG_RESULT([$wx_cv_cc_broken_libstdcxx_visibility]) + + if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then + AC_MSG_CHECKING([whether we can work around it]) + AC_CACHE_VAL(wx_cv_cc_visibility_workaround, [ + AC_LANG_PUSH(C++) + AC_TRY_LINK( + [ + #pragma GCC visibility push(default) + #include <string> + #pragma GCC visibility pop + ], + [ + std::string s("hello"); + return s.length(); + ], + wx_cv_cc_visibility_workaround=no, + wx_cv_cc_visibility_workaround=yes) + AC_LANG_POP() + ]) + AC_MSG_RESULT([$wx_cv_cc_visibility_workaround]) + + if test $wx_cv_cc_visibility_workaround = no; then + dnl we can't use visibility at all then + wx_cv_cc_visibility=no + fi + fi + fi + + if test $wx_cv_cc_visibility = yes; then + AC_DEFINE([HAVE_VISIBILITY]) + if test $wx_cv_cc_broken_libstdcxx_visibility = yes; then + AC_DEFINE([HAVE_BROKEN_LIBSTDCXX_VISIBILITY]) + fi + else + CFLAGS_VISIBILITY="" + CXXFLAGS_VISIBILITY="" + fi + AC_SUBST([CFLAGS_VISIBILITY]) + AC_SUBST([CXXFLAGS_VISIBILITY]) + fi +]) Modified: trunk/bootstrap =================================================================== --- trunk/bootstrap 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/bootstrap 2010-03-10 18:24:44 UTC (rev 173) @@ -47,7 +47,7 @@ # --copy to allow simultaneous use on windows under mingw and cygwin platforms. # Symlinking of files under mingw does not work out for cygwin and vice-versa. echo "Setting up build system for xmlwrapp:" -echo " - aclocal " && aclocal && \ +echo " - aclocal " && aclocal -I admin && \ echo " - libtoolize " && libtoolize --copy --automake && \ echo " - autoconf " && autoconf && \ echo " - automake " && automake --add-missing --copy --foreign && \ Modified: trunk/configure.ac =================================================================== --- trunk/configure.ac 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/configure.ac 2010-03-10 18:24:44 UTC (rev 173) @@ -95,6 +95,8 @@ CXXFLAGS="$CXXFLAGS -W -Wall -Wcast-align -Wwrite-strings" fi +dnl Check if the compiler supports symbols visibility: +XMLWRAPP_VISIBILITY dnl === Generate output files === Modified: trunk/include/Makefile.am =================================================================== --- trunk/include/Makefile.am 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/Makefile.am 2010-03-10 18:24:44 UTC (rev 173) @@ -6,6 +6,7 @@ xmlwrapp/document.h \ xmlwrapp/event_parser.h \ xmlwrapp/exception.h \ + xmlwrapp/export.h \ xmlwrapp/init.h \ xmlwrapp/node.h \ xmlwrapp/nodes_view.h \ Modified: trunk/include/xmlwrapp/_cbfo.h =================================================================== --- trunk/include/xmlwrapp/_cbfo.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xmlwrapp/_cbfo.h 2010-03-10 18:24:44 UTC (rev 173) @@ -33,6 +33,9 @@ #ifndef _xmlwrapp_cbfo_h_ #define _xmlwrapp_cbfo_h_ +// xmlwrapp includes +#include "xmlwrapp/export.h" + #include <functional> namespace xml @@ -44,7 +47,7 @@ { // helper for xml::node::sort() - struct cbfo_node_compare + struct XMLWRAPP_API cbfo_node_compare : public std::binary_function<xml::node, xml::node, bool> { virtual ~cbfo_node_compare() {} Modified: trunk/include/xmlwrapp/attributes.h =================================================================== --- trunk/include/xmlwrapp/attributes.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xmlwrapp/attributes.h 2010-03-10 18:24:44 UTC (rev 173) @@ -41,6 +41,7 @@ // xmlwrapp includes #include "xmlwrapp/init.h" +#include "xmlwrapp/export.h" // standard includes #include <cstddef> @@ -67,7 +68,7 @@ The iterator classes allow you to access one XML attribute. This is done using the xml::attributes::attr class interface. */ -class attributes +class XMLWRAPP_API attributes { public: /// size type @@ -169,8 +170,8 @@ /// postfix increment (avoid if possible for better performance) iterator operator++(int); - friend bool operator==(const iterator& lhs, const iterator& rhs); - friend bool operator!=(const iterator& lhs, const iterator& rhs); + friend bool XMLWRAPP_API operator==(const iterator& lhs, const iterator& rhs); + friend bool XMLWRAPP_API operator!=(const iterator& lhs, const iterator& rhs); private: impl::ait_impl *pimpl_; @@ -211,8 +212,8 @@ /// postfix increment (avoid if possible better for performance) const_iterator operator++ (int); - friend bool operator== (const const_iterator &lhs, const const_iterator &rhs); - friend bool operator!= (const const_iterator &lhs, const const_iterator &rhs); + friend bool XMLWRAPP_API operator== (const const_iterator &lhs, const const_iterator &rhs); + friend bool XMLWRAPP_API operator!= (const const_iterator &lhs, const const_iterator &rhs); private: impl::ait_impl *pimpl_; Modified: trunk/include/xmlwrapp/document.h =================================================================== --- trunk/include/xmlwrapp/document.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xmlwrapp/document.h 2010-03-10 18:24:44 UTC (rev 173) @@ -42,6 +42,7 @@ // xmlwrapp includes #include "xmlwrapp/init.h" #include "xmlwrapp/node.h" +#include "xmlwrapp/export.h" // standard includes #include <iosfwd> @@ -75,7 +76,7 @@ The xml::document class is used to hold the XML tree and various bits of information about it. */ -class document +class XMLWRAPP_API document { public: /// size type @@ -437,7 +438,7 @@ @param doc The document to insert. @return The stream from the first parameter. */ - friend std::ostream& operator<< (std::ostream &stream, const document &doc); + friend XMLWRAPP_API std::ostream& operator<< (std::ostream &stream, const document &doc); private: impl::doc_impl *pimpl_; Modified: trunk/include/xmlwrapp/event_parser.h =================================================================== --- trunk/include/xmlwrapp/event_parser.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xmlwrapp/event_parser.h 2010-03-10 18:24:44 UTC (rev 173) @@ -41,6 +41,7 @@ // xmlwrapp includes #include "xmlwrapp/init.h" +#include "xmlwrapp/export.h" // standard includes #include <cstddef> @@ -62,7 +63,7 @@ use this class you derive a sub-class from it and override the protected virtual functions. */ -class event_parser +class XMLWRAPP_API event_parser { public: /// a type for holding XML node attributes Modified: trunk/include/xmlwrapp/exception.h =================================================================== --- trunk/include/xmlwrapp/exception.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xmlwrapp/exception.h 2010-03-10 18:24:44 UTC (rev 173) @@ -39,6 +39,9 @@ #ifndef _xmlwrapp_exception_h_ #define _xmlwrapp_exception_h_ +// xmlwrapp includes +#include "xmlwrapp/export.h" + #include <stdexcept> #include <string> @@ -55,7 +58,7 @@ @since 0.7.0 */ -class exception : public std::runtime_error +class XMLWRAPP_API exception : public std::runtime_error { public: explicit exception(const std::string& what) : std::runtime_error(what) Copied: trunk/include/xmlwrapp/export.h (from rev 172, trunk/include/xmlwrapp/exception.h) =================================================================== --- trunk/include/xmlwrapp/export.h (rev 0) +++ trunk/include/xmlwrapp/export.h 2010-03-10 18:24:44 UTC (rev 173) @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2010 Vaclav Slavik <vs...@fa...> + * All Rights Reserved + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of the Author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _xmlwrapp_export_h_ +#define _xmlwrapp_export_h_ + +#ifdef HAVE_VISIBILITY + #define XMLWRAPP_API __attribute__ ((visibility("default"))) + #define XSLTWRAPP_API __attribute__ ((visibility("default"))) +#else + #define XMLWRAPP_API + #define XSLTWRAPP_API +#endif + +#endif // _xmlwrapp_export_h_ Modified: trunk/include/xmlwrapp/init.h =================================================================== --- trunk/include/xmlwrapp/init.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xmlwrapp/init.h 2010-03-10 18:24:44 UTC (rev 173) @@ -39,6 +39,9 @@ #ifndef _xmlwrapp_init_h_ #define _xmlwrapp_init_h_ +// xmlwrapp includes +#include "xmlwrapp/export.h" + /// XML library namespace namespace xml { @@ -57,7 +60,7 @@ use. This is no longer true: user code doesn't have to create any instances, but it @em can create as many instances as it wants. */ -class init +class XMLWRAPP_API init { public: init(); Modified: trunk/include/xmlwrapp/node.h =================================================================== --- trunk/include/xmlwrapp/node.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xmlwrapp/node.h 2010-03-10 18:24:44 UTC (rev 173) @@ -42,6 +42,7 @@ // xmlwrapp includes #include "xmlwrapp/init.h" +#include "xmlwrapp/export.h" // hidden stuff #include "xmlwrapp/_cbfo.h" @@ -82,7 +83,7 @@ ANY operation to the xml::node. If you need the data to stick around a little longer you should put it inside a std::string. */ -class node +class XMLWRAPP_API node { public: /// size type @@ -787,7 +788,7 @@ @param n The node to write to the stream. @return The stream. */ - friend std::ostream& operator<< (std::ostream &stream, const node &n); + friend XMLWRAPP_API std::ostream& operator<< (std::ostream &stream, const node &n); private: impl::node_impl *pimpl_; Modified: trunk/include/xmlwrapp/nodes_view.h =================================================================== --- trunk/include/xmlwrapp/nodes_view.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xmlwrapp/nodes_view.h 2010-03-10 18:24:44 UTC (rev 173) @@ -42,6 +42,7 @@ // xmlwrapp includes #include "xmlwrapp/init.h" +#include "xmlwrapp/export.h" // standard includes #include <iterator> @@ -73,7 +74,7 @@ @see xml::node::elements(), xml::node::elements(const char *) */ -class nodes_view +class XMLWRAPP_API nodes_view { public: nodes_view() : data_begin_(0), advance_func_(0) {} @@ -235,7 +236,7 @@ @since 0.6.0 */ -class const_nodes_view +class XMLWRAPP_API const_nodes_view { public: const_nodes_view() : data_begin_(0), advance_func_(0) {} Modified: trunk/include/xmlwrapp/tree_parser.h =================================================================== --- trunk/include/xmlwrapp/tree_parser.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xmlwrapp/tree_parser.h 2010-03-10 18:24:44 UTC (rev 173) @@ -41,6 +41,7 @@ // xmlwrapp includes #include "xmlwrapp/init.h" +#include "xmlwrapp/export.h" // standard includes #include <cstddef> @@ -64,7 +65,7 @@ After constructing a tree_parser, with either a file to parse or some in memory data to parse, you can walk the tree using the xml::node interface. */ -class tree_parser +class XMLWRAPP_API tree_parser { public: typedef std::size_t size_type; Modified: trunk/include/xsltwrapp/init.h =================================================================== --- trunk/include/xsltwrapp/init.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xsltwrapp/init.h 2010-03-10 18:24:44 UTC (rev 173) @@ -41,6 +41,7 @@ // xmlwrapp includes #include "xmlwrapp/init.h" +#include "xmlwrapp/export.h" /// XSLT library namespace namespace xslt @@ -59,7 +60,7 @@ use. This is no longer true: user code doesn't have to create any instances, but it @em can create as many instances as it wants. */ -class init : public xml::init +class XSLTWRAPP_API init : public xml::init { public: init(); Modified: trunk/include/xsltwrapp/stylesheet.h =================================================================== --- trunk/include/xsltwrapp/stylesheet.h 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/include/xsltwrapp/stylesheet.h 2010-03-10 18:24:44 UTC (rev 173) @@ -42,6 +42,7 @@ // xmlwrapp includes #include "xsltwrapp/init.h" #include "xmlwrapp/document.h" +#include "xmlwrapp/export.h" // standard includes #include <map> @@ -55,7 +56,7 @@ stylesheet. You can use it to load in a stylesheet and then use that stylesheet to transform an XML document to something else. */ -class stylesheet +class XSLTWRAPP_API stylesheet { public: struct pimpl; Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/src/Makefile.am 2010-03-10 18:24:44 UTC (rev 173) @@ -1,5 +1,5 @@ -AM_CPPFLAGS = -I$(top_srcdir)/include +AM_CPPFLAGS = -I$(top_srcdir)/include $(CXXFLAGS_VISIBILITY) if WITH_XSLT lib_LTLIBRARIES = libxmlwrapp.la libxsltwrapp.la Modified: trunk/src/libxml/utility.cxx =================================================================== --- trunk/src/libxml/utility.cxx 2010-03-09 17:33:58 UTC (rev 172) +++ trunk/src/libxml/utility.cxx 2010-03-10 18:24:44 UTC (rev 173) @@ -58,7 +58,8 @@ namespace impl { -void printf2string(std::string& s, const char *message, va_list ap) +// this function is used by libxsltwrapp too, so we must export it +XMLWRAPP_API void printf2string(std::string& s, const char *message, va_list ap) { char buffer[512]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |