libgnutlsxx link problems

View: New views
9 Messages — Rating Filter:   Alert me  

libgnutlsxx link problems

by Boyan Kasarov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,
I am having problems linking against libgnutlsxx.

The test program I used:
( NOTE It requires the helper functions from
http://www.gnu.org/software/gnutls/manual/gnutls.html#Helper-function-for-TCP-connections wrapped in extern "C" )

#include <iostream>
#include <stdexcept>
#include <gnutls/gnutls.h>
#include <gnutls/gnutlsxx.h>
#include <cstring> /* for strlen */

/* A very basic TLS client, with SRP authentication.
 * written by Eduardo Villanueva Che, changed by Boyan Kasarov.
 */

#define MAX_BUF 1024
#define SA struct sockaddr

#define CAFILE "ca.pem"
#define USERNAME "username"
#define PASSWORD "password"
#define MSG "GET / HTTP/1.0\r\n\r\n"

extern "C"
{
    int tcp_connect(void);
    void tcp_close(int sd);
}


int main(void)
{
    int sd = -1;
    gnutls_global_init();

    try
    {
        /* Allow connections to servers that have OpenPGP keys as well.
         */
        gnutls::client_session session;

        /* X509 stuff */
        gnutls::certificate_credentials credentials;

        /* SRP stuff */
        gnutls::srp_client_credentials srp_credentials;

        /* sets the trusted cas file
         */
        credentials.set_x509_trust_file(CAFILE, GNUTLS_X509_FMT_PEM);

        /* enter username and passowrd
         */
        srp_credentials.set_credentials(USERNAME, PASSWORD);

        /* put the x509 credentials to the current session
         */
        session.set_credentials(credentials);

        /* put the srp credentials to the current session
         */
        session.set_credentials(srp_credentials);

        /* Use default priorities */
        session.set_priority ("NORMAL:+SRP:+SRP-RSA:+SRP-DSS:-DHE-RSA",
NULL);

        /* connect to the peer
         */
        sd = tcp_connect();
        session.set_transport_ptr((gnutls_transport_ptr_t) sd);

        /* Perform the TLS handshake
         */
        int ret = session.handshake();
        if (ret < 0)
        {
//             gnutls_perror(ret);
            throw std::runtime_error("Handshake failed");
        }
        else
        {
            std::cout << "- Handshake was completed" << std::endl;
        }

        session.send(MSG, strlen(MSG));
        char buffer[MAX_BUF + 1];
        ret = session.recv(buffer, MAX_BUF);
        if (ret == 0)
        {
            throw std::runtime_error("Peer has closed the TLS
connection");
        }
        else if (ret < 0)
        {
            throw std::runtime_error(gnutls_strerror(ret));
        }

        std::cout << "- Received " << ret << " bytes:" << std::endl;
        std::cout.write(buffer, ret);
        std::cout << std::endl;

        session.bye(GNUTLS_SHUT_RDWR);
    }
    catch (gnutls::exception &ex)
    {
        std::cerr << "Exception caught: " << ex.what() << std::endl;
    }

    if (sd != -1)
        tcp_close(sd);

    gnutls_global_deinit();

    return 0;
}

The problem I have is this:

derex@laptop ~/workspace/gnutls-test $ g++ ./test.cpp -lgnutlsxx
/tmp/cccjLXmv.o: In function `main':
test.cpp:(.text+0x15f): undefined reference to
`gnutls::srp_client_credentials::srp_client_credentials()'
test.cpp:(.text+0x188): undefined reference to
`gnutls::srp_client_credentials::set_credentials(char const*, char
const*)'
test.cpp:(.text+0x721): undefined reference to
`gnutls::srp_client_credentials::~srp_client_credentials()'
test.cpp:(.text+0x74b): undefined reference to
`gnutls::srp_client_credentials::~srp_client_credentials()'
/tmp/cccjLXmv.o:(.gcc_except_table+0xac): undefined reference to
`typeinfo for gnutls::exception'
collect2: ld returned 1 exit status

This errors appears if I use versions from 2.8.3 upto 2.9.4 (snapshot
20091004 from http://daily.josefsson.org/gnutls/ ) , I couldn't find
where gnutls source is , I didn't test versions before 2.8.3

The way I see it the link problem consists of 2 problems:

**** SRP related classes don't get build because of missing ENABLE_SRP
preprocessor flag ( even if srp is enabled from configure ). It can be
fixed by including config.h in lib/gnutlsxx.cpp, here is patch :

diff --git a/lib/gnutlsxx.cpp b/lib/gnutlsxx.cpp
index 83453f0..cdca728 100644
--- a/lib/gnutlsxx.cpp
+++ b/lib/gnutlsxx.cpp
@@ -1,3 +1,7 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
 #include <gnutls/gnutlsxx.h>

 namespace gnutls


**** The second problem is missing typeinfo for some classes, including
gnutls::exception in the example. I used this hack to fix it:

diff --git a/lib/libgnutlsxx.map b/lib/libgnutlsxx.map
index f049df4..62f6c12 100644
--- a/lib/libgnutlsxx.map
+++ b/lib/libgnutlsxx.map
@@ -24,7 +24,11 @@ GNUTLS_1_6
 {
   global:
     extern "C++" {
-      gnutls*;
+      gnutls::*;
   };
+
+  # export typeinfo names and structures
+  _ZTI*;
+
   local: *;
 };

However I think some solution like explained at this url -
http://gcc.gnu.org/wiki/Visibility could be implemented for the C++
bindings.

Boyan Kasarov




_______________________________________________
Gnutls-devel mailing list
Gnutls-devel@...
http://lists.gnu.org/mailman/listinfo/gnutls-devel

Re: libgnutlsxx link problems

by Simon Josefsson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Boyan Kasarov <bkasarov@...> writes:

> Hello,
> I am having problems linking against libgnutlsxx.

Hi.  Thanks for the report!

> This errors appears if I use versions from 2.8.3 upto 2.9.4 (snapshot
> 20091004 from http://daily.josefsson.org/gnutls/ ) , I couldn't find
> where gnutls source is , I didn't test versions before 2.8.3

Source code for all versions are available from:

http://www.gnu.org/software/gnutls/download.html

Version controlled sources are available from:

https://savannah.gnu.org/git/?group=gnutls

> **** SRP related classes don't get build because of missing ENABLE_SRP
> preprocessor flag ( even if srp is enabled from configure ). It can be
> fixed by including config.h in lib/gnutlsxx.cpp, here is patch :

Indeed, thank you it has been pushed.

> **** The second problem is missing typeinfo for some classes, including
> gnutls::exception in the example. I used this hack to fix it:

I used your hack for now...

> However I think some solution like explained at this url -
> http://gcc.gnu.org/wiki/Visibility could be implemented for the C++
> bindings.

...however I agree with this, but don't have time to work on it.
Patches are welcome, but I think you will need to sign a copyright
transfer to the FSF because such a patch would end up being more than a
couple of lines.  Let me know privately if you want to make that happen.

/Simon


_______________________________________________
Gnutls-devel mailing list
Gnutls-devel@...
http://lists.gnu.org/mailman/listinfo/gnutls-devel

Parent Message unknown Re: libgnutlsxx link problems

by Simon Josefsson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Boyan Kasarov <bkasarov@...> writes:

> Here is patch to export the names in more proper way:
>
> diff --git a/lib/libgnutlsxx.map b/lib/libgnutlsxx.map
> index 62f6c12..f61d861 100644
> --- a/lib/libgnutlsxx.map
> +++ b/lib/libgnutlsxx.map
> @@ -24,11 +24,18 @@ GNUTLS_1_6
>  {
>    global:
>      extern "C++" {
> -      gnutls::*;
> -  };
> +      # To specify a class we also need to specify its typeinfo,
> +      # typeinfo name and vtable objects.
> +      # For example for class gnutls::psk_client_credentials,
> +      # we need to declare this 4 lines:
> +      #
> +      # gnutls::psk_client_credentials::*;
> +      # "typeinfo for gnutls::psk_client_credentials";
> +      # "typeinfo name for gnutls::psk_client_credentials";
> +      # "vtable for gnutls::psk_client_credentials";
>  
> -  # export typeinfo names and structures
> -  _ZTI*;
> +      *gnutls::*;
> +  };
>  
>    local: *;
>  };

Applied.

> As you see specifying what to export from version script is somehow not
> flexible for C++, and it does not work well on all platforms, I can
> implement solution like in
> http://www.gnu.org/software/gnulib/manual/gnulib.html#Exported-Symbols-of-Shared-Libraries , the 3th solution.

I think that is the right solution, so it would be great.  The best is
to start use it for the C++ library first and not couple this with doing
the same change for the C library.  So please look into creating a patch
to use it for the C++ library first.

Thanks,
/Simon


_______________________________________________
Gnutls-devel mailing list
Gnutls-devel@...
http://lists.gnu.org/mailman/listinfo/gnutls-devel

Re: libgnutlsxx link problems

by Boyan Kasarov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello,
I am sending two patches to add symbol visibility support.

[PATCH 1/2] Import lib-symbol-visibility from gnulib
[PATCH 2/2] Use lib-symbol-visibility for the C++ library

The first patch is the result of running:
# gnulib-tool --import lib-symbol-visibility
from latest gnulib from git, but I think it also updated some other files, if you have your ways to invoke it, please feel free to do it.

The second patch adds the necessary changes as explained in lib-symbol-visibility manual to add support for libgnutlsxx. I also removed the "local: *;" directive from libgnutlsxx.map, because it is no longer needed to hide symbols using it.

I have tested on freebsd, linux and opensolaris with gcc 4.2, 4.3 and 3.4.

Boyan



_______________________________________________
Gnutls-devel mailing list
Gnutls-devel@...
http://lists.gnu.org/mailman/listinfo/gnutls-devel

[PATCH 1/2] Import lib-symbol-visibility from gnulib

by Boyan Kasarov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

---
 lib/gl/Makefile.am        |   15 ++++-
 lib/gl/m4/gnulib-cache.m4 |    3 +-
 lib/gl/m4/gnulib-comp.m4  |    1 +
 lib/gl/m4/sys_stat_h.m4   |   51 +++++++------
 lib/gl/sys_stat.in.h      |  176 +++++++++++++++++++++++++--------------------
 5 files changed, 143 insertions(+), 103 deletions(-)

diff --git a/lib/gl/Makefile.am b/lib/gl/Makefile.am
index c1e87e2..ce6fce6 100644
--- a/lib/gl/Makefile.am
+++ b/lib/gl/Makefile.am
@@ -9,7 +9,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=liblgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests --lgpl=2 --libtool --macro-prefix=lgl --no-vc-files byteswap c-ctype fseeko func gettext lib-msvc-compat lib-symbol-versions memmem-simple minmax netdb read-file snprintf sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r unistd vasprintf vsnprintf
+# Reproduce by: gnulib-tool --import --dir=. --local-dir=gl/override --lib=liblgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests --lgpl=2 --libtool --macro-prefix=lgl --no-vc-files byteswap c-ctype fseeko func gettext lib-msvc-compat lib-symbol-versions lib-symbol-visibility memmem-simple minmax netdb read-file snprintf sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r unistd vasprintf vsnprintf
 
 AUTOMAKE_OPTIONS = 1.5 gnits
 
@@ -191,6 +191,16 @@ EXTRA_DIST += $(top_srcdir)/build-aux/config.rpath
 
 ## end   gnulib module havelib
 
+## begin gnulib module lib-symbol-visibility
+
+# The value of $(CFLAG_VISIBILITY) needs to be added to the CFLAGS for the
+# compilation of all sources that make up the library. This line here does it
+# only for the gnulib part of it. The developer is responsible for adding
+# $(CFLAG_VISIBILITY) to the Makefile.ams of the other portions of the library.
+AM_CFLAGS += $(CFLAG_VISIBILITY)
+
+## end   gnulib module lib-symbol-visibility
+
 ## begin gnulib module link-warning
 
 LINK_WARNING_H=$(top_srcdir)/build-aux/link-warning.h
@@ -745,6 +755,7 @@ sys/stat.h: sys_stat.in.h
       -e 's|@''GNULIB_MKFIFOAT''@|$(GNULIB_MKFIFOAT)|g' \
       -e 's|@''GNULIB_MKNODAT''@|$(GNULIB_MKNODAT)|g' \
       -e 's|@''GNULIB_STAT''@|$(GNULIB_STAT)|g' \
+      -e 's|@''GNULIB_UTIMENSAT''@|$(GNULIB_UTIMENSAT)|g' \
       -e 's|@''HAVE_FCHMODAT''@|$(HAVE_FCHMODAT)|g' \
       -e 's|@''HAVE_FSTATAT''@|$(HAVE_FSTATAT)|g' \
       -e 's|@''HAVE_FUTIMENS''@|$(HAVE_FUTIMENS)|g' \
@@ -753,12 +764,14 @@ sys/stat.h: sys_stat.in.h
       -e 's|@''HAVE_MKDIRAT''@|$(HAVE_MKDIRAT)|g' \
       -e 's|@''HAVE_MKFIFOAT''@|$(HAVE_MKFIFOAT)|g' \
       -e 's|@''HAVE_MKNODAT''@|$(HAVE_MKNODAT)|g' \
+      -e 's|@''HAVE_UTIMENSAT''@|$(HAVE_UTIMENSAT)|g' \
       -e 's|@''REPLACE_FSTAT''@|$(REPLACE_FSTAT)|g' \
       -e 's|@''REPLACE_FSTATAT''@|$(REPLACE_FSTATAT)|g' \
       -e 's|@''REPLACE_FUTIMENS''@|$(REPLACE_FUTIMENS)|g' \
       -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
       -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
       -e 's|@''REPLACE_STAT''@|$(REPLACE_STAT)|g' \
+      -e 's|@''REPLACE_UTIMENSAT''@|$(REPLACE_UTIMENSAT)|g' \
       -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
       < $(srcdir)/sys_stat.in.h; \
  } > $@-t && \
diff --git a/lib/gl/m4/gnulib-cache.m4 b/lib/gl/m4/gnulib-cache.m4
index de6f4c7..18da12a 100644
--- a/lib/gl/m4/gnulib-cache.m4
+++ b/lib/gl/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --local-dir=gl/override --lib=liblgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests --lgpl=2 --libtool --macro-prefix=lgl --no-vc-files byteswap c-ctype fseeko func gettext lib-msvc-compat lib-symbol-versions memmem-simple minmax netdb read-file snprintf sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r unistd vasprintf vsnprintf
+#   gnulib-tool --import --dir=. --local-dir=gl/override --lib=liblgnu --source-base=gl --m4-base=gl/m4 --doc-base=doc --tests-base=gl/tests --aux-dir=build-aux --with-tests --avoid=alignof-tests --avoid=lseek-tests --lgpl=2 --libtool --macro-prefix=lgl --no-vc-files byteswap c-ctype fseeko func gettext lib-msvc-compat lib-symbol-versions lib-symbol-visibility memmem-simple minmax netdb read-file snprintf sockets socklen stdint strcase strverscmp sys_socket sys_stat time_r unistd vasprintf vsnprintf
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([gl/override])
@@ -27,6 +27,7 @@ gl_MODULES([
   gettext
   lib-msvc-compat
   lib-symbol-versions
+  lib-symbol-visibility
   memmem-simple
   minmax
   netdb
diff --git a/lib/gl/m4/gnulib-comp.m4 b/lib/gl/m4/gnulib-comp.m4
index 9265e44..25d2436 100644
--- a/lib/gl/m4/gnulib-comp.m4
+++ b/lib/gl/m4/gnulib-comp.m4
@@ -57,6 +57,7 @@ AC_DEFUN([lgl_INIT],
   AC_SUBST([LTLIBINTL])
   gl_LD_OUTPUT_DEF
   gl_LD_VERSION_SCRIPT
+  gl_VISIBILITY
   gl_FUNC_LSEEK
   gl_UNISTD_MODULE_INDICATOR([lseek])
   gl_FUNC_MEMCHR
diff --git a/lib/gl/m4/sys_stat_h.m4 b/lib/gl/m4/sys_stat_h.m4
index 6004890..1edf548 100644
--- a/lib/gl/m4/sys_stat_h.m4
+++ b/lib/gl/m4/sys_stat_h.m4
@@ -1,4 +1,4 @@
-# sys_stat_h.m4 serial 18   -*- Autoconf -*-
+# sys_stat_h.m4 serial 19   -*- Autoconf -*-
 dnl Copyright (C) 2006-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -39,28 +39,31 @@ AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR],
 AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR
-  GNULIB_FCHMODAT=0;  AC_SUBST([GNULIB_FCHMODAT])
-  GNULIB_FSTATAT=0;   AC_SUBST([GNULIB_FSTATAT])
-  GNULIB_FUTIMENS=0;  AC_SUBST([GNULIB_FUTIMENS])
-  GNULIB_LCHMOD=0;    AC_SUBST([GNULIB_LCHMOD])
-  GNULIB_LSTAT=0;     AC_SUBST([GNULIB_LSTAT])
-  GNULIB_MKDIRAT=0;   AC_SUBST([GNULIB_MKDIRAT])
-  GNULIB_MKFIFOAT=0;  AC_SUBST([GNULIB_MKFIFOAT])
-  GNULIB_MKNODAT=0;   AC_SUBST([GNULIB_MKNODAT])
-  GNULIB_STAT=0;      AC_SUBST([GNULIB_STAT])
+  GNULIB_FCHMODAT=0;    AC_SUBST([GNULIB_FCHMODAT])
+  GNULIB_FSTATAT=0;     AC_SUBST([GNULIB_FSTATAT])
+  GNULIB_FUTIMENS=0;    AC_SUBST([GNULIB_FUTIMENS])
+  GNULIB_LCHMOD=0;      AC_SUBST([GNULIB_LCHMOD])
+  GNULIB_LSTAT=0;       AC_SUBST([GNULIB_LSTAT])
+  GNULIB_MKDIRAT=0;     AC_SUBST([GNULIB_MKDIRAT])
+  GNULIB_MKFIFOAT=0;    AC_SUBST([GNULIB_MKFIFOAT])
+  GNULIB_MKNODAT=0;     AC_SUBST([GNULIB_MKNODAT])
+  GNULIB_STAT=0;        AC_SUBST([GNULIB_STAT])
+  GNULIB_UTIMENSAT=0;   AC_SUBST([GNULIB_UTIMENSAT])
   dnl Assume proper GNU behavior unless another module says otherwise.
-  HAVE_FCHMODAT=1;    AC_SUBST([HAVE_FCHMODAT])
-  HAVE_FSTATAT=1;     AC_SUBST([HAVE_FSTATAT])
-  HAVE_FUTIMENS=1;    AC_SUBST([HAVE_FUTIMENS])
-  HAVE_LCHMOD=1;      AC_SUBST([HAVE_LCHMOD])
-  HAVE_LSTAT=1;       AC_SUBST([HAVE_LSTAT])
-  HAVE_MKDIRAT=1;     AC_SUBST([HAVE_MKDIRAT])
-  HAVE_MKFIFOAT=1;    AC_SUBST([HAVE_MKFIFOAT])
-  HAVE_MKNODAT=1;     AC_SUBST([HAVE_MKNODAT])
-  REPLACE_FSTAT=0;    AC_SUBST([REPLACE_FSTAT])
-  REPLACE_FSTATAT=0;  AC_SUBST([REPLACE_FSTATAT])
-  REPLACE_FUTIMENS=0; AC_SUBST([REPLACE_FUTIMENS])
-  REPLACE_LSTAT=0;    AC_SUBST([REPLACE_LSTAT])
-  REPLACE_MKDIR=0;    AC_SUBST([REPLACE_MKDIR])
-  REPLACE_STAT=0;     AC_SUBST([REPLACE_STAT])
+  HAVE_FCHMODAT=1;      AC_SUBST([HAVE_FCHMODAT])
+  HAVE_FSTATAT=1;       AC_SUBST([HAVE_FSTATAT])
+  HAVE_FUTIMENS=1;      AC_SUBST([HAVE_FUTIMENS])
+  HAVE_LCHMOD=1;        AC_SUBST([HAVE_LCHMOD])
+  HAVE_LSTAT=1;         AC_SUBST([HAVE_LSTAT])
+  HAVE_MKDIRAT=1;       AC_SUBST([HAVE_MKDIRAT])
+  HAVE_MKFIFOAT=1;      AC_SUBST([HAVE_MKFIFOAT])
+  HAVE_MKNODAT=1;       AC_SUBST([HAVE_MKNODAT])
+  HAVE_UTIMENSAT=1;     AC_SUBST([HAVE_UTIMENSAT])
+  REPLACE_FSTAT=0;      AC_SUBST([REPLACE_FSTAT])
+  REPLACE_FSTATAT=0;    AC_SUBST([REPLACE_FSTATAT])
+  REPLACE_FUTIMENS=0;   AC_SUBST([REPLACE_FUTIMENS])
+  REPLACE_LSTAT=0;      AC_SUBST([REPLACE_LSTAT])
+  REPLACE_MKDIR=0;      AC_SUBST([REPLACE_MKDIR])
+  REPLACE_STAT=0;       AC_SUBST([REPLACE_STAT])
+  REPLACE_UTIMENSAT=0;  AC_SUBST([REPLACE_UTIMENSAT])
 ])
diff --git a/lib/gl/sys_stat.in.h b/lib/gl/sys_stat.in.h
index 298985b..13cfcbf 100644
--- a/lib/gl/sys_stat.in.h
+++ b/lib/gl/sys_stat.in.h
@@ -293,41 +293,6 @@ extern "C" {
 #endif
 
 
-#if @GNULIB_LSTAT@
-# if ! @HAVE_LSTAT@
-/* mingw does not support symlinks, therefore it does not have lstat.  But
-   without links, stat does just fine.  */
-#  define lstat stat
-# elif @REPLACE_LSTAT@
-#  undef lstat
-#  define lstat rpl_lstat
-extern int rpl_lstat (const char *name, struct stat *buf);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef lstat
-# define lstat(p,b) \
-  (GL_LINK_WARNING ("lstat is unportable - " \
-    "use gnulib module lstat for portability"), \
-   lstat (p, b))
-#endif
-
-#if @GNULIB_STAT@
-# if @REPLACE_STAT@
-/* We can't use the object-like #define stat rpl_stat, because of
-   struct stat.  This means that rpl_stat will not be used if the user
-   does (stat)(a,b).  Oh well.  */
-#  undef stat
-#  define stat(name, st) rpl_stat (name, st)
-extern int stat (const char *name, struct stat *buf);
-# endif
-#elif defined GNULIB_POSIXCHECK
-# undef stat
-# define stat(p,b) \
-  (GL_LINK_WARNING ("stat is unportable - " \
-    "use gnulib module stat for portability"), \
-   stat (p, b))
-#endif
-
 #if @GNULIB_FCHMODAT@
 # if !@HAVE_FCHMODAT@
 extern int fchmodat (int fd, char const *file, mode_t mode, int flag);
@@ -341,6 +306,12 @@ extern int fchmodat (int fd, char const *file, mode_t mode, int flag);
 #endif
 
 
+#if @REPLACE_FSTAT@
+# define fstat rpl_fstat
+extern int fstat (int fd, struct stat *buf);
+#endif
+
+
 #if @GNULIB_FSTATAT@
 # if @REPLACE_FSTATAT@
 #  undef fstatat
@@ -375,6 +346,71 @@ extern int futimens (int fd, struct timespec const times[2]);
 #endif
 
 
+#if @GNULIB_LCHMOD@
+/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
+   denotes a symbolic link.  */
+# if !@HAVE_LCHMOD@
+/* The lchmod replacement follows symbolic links.  Callers should take
+   this into account; lchmod should be applied only to arguments that
+   are known to not be symbolic links.  On hosts that lack lchmod,
+   this can lead to race conditions between the check and the
+   invocation of lchmod, but we know of no workarounds that are
+   reliable in general.  You might try requesting support for lchmod
+   from your operating system supplier.  */
+#  define lchmod chmod
+# endif
+# if 0 /* assume already declared */
+extern int lchmod (const char *filename, mode_t mode);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef lchmod
+# define lchmod(f,m) \
+    (GL_LINK_WARNING ("lchmod is unportable - " \
+                      "use gnulib module lchmod for portability"), \
+     lchmod (f, m))
+#endif
+
+
+#if @GNULIB_LSTAT@
+# if ! @HAVE_LSTAT@
+/* mingw does not support symlinks, therefore it does not have lstat.  But
+   without links, stat does just fine.  */
+#  define lstat stat
+# elif @REPLACE_LSTAT@
+#  undef lstat
+#  define lstat rpl_lstat
+extern int rpl_lstat (const char *name, struct stat *buf);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef lstat
+# define lstat(p,b) \
+  (GL_LINK_WARNING ("lstat is unportable - " \
+    "use gnulib module lstat for portability"), \
+   lstat (p, b))
+#endif
+
+
+#if @REPLACE_MKDIR@
+# undef mkdir
+# define mkdir rpl_mkdir
+extern int mkdir (char const *name, mode_t mode);
+#else
+/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
+   Additionally, it declares _mkdir (and depending on compile flags, an
+   alias mkdir), only in the nonstandard <io.h>, which is included above.  */
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+
+static inline int
+rpl_mkdir (char const *name, mode_t mode)
+{
+  return _mkdir (name);
+}
+
+#  define mkdir rpl_mkdir
+# endif
+#endif
+
+
 #if @GNULIB_MKDIRAT@
 # if !@HAVE_MKDIRAT@
 extern int mkdirat (int fd, char const *file, mode_t mode);
@@ -387,6 +423,7 @@ extern int mkdirat (int fd, char const *file, mode_t mode);
      mkdirat (d, n, m))
 #endif
 
+
 #if @GNULIB_MKFIFOAT@
 # if !@HAVE_MKFIFOAT@
 int mkfifoat (int fd, char const *file, mode_t mode);
@@ -399,6 +436,7 @@ int mkfifoat (int fd, char const *file, mode_t mode);
      mkfifoat (d, n, m))
 #endif
 
+
 #if @GNULIB_MKNODAT@
 # if !@HAVE_MKNODAT@
 int mknodat (int fd, char const *file, mode_t mode, dev_t dev);
@@ -411,56 +449,40 @@ int mknodat (int fd, char const *file, mode_t mode, dev_t dev);
      mknodat (f, n, m, d))
 #endif
 
-#if @REPLACE_FSTAT@
-# define fstat rpl_fstat
-extern int fstat (int fd, struct stat *buf);
-#endif
-
-#if @REPLACE_MKDIR@
-# undef mkdir
-# define mkdir rpl_mkdir
-extern int mkdir (char const *name, mode_t mode);
-#else
-/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
-   Additionally, it declares _mkdir (and depending on compile flags, an
-   alias mkdir), only in the nonstandard <io.h>, which is included above.  */
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
 
-static inline int
-rpl_mkdir (char const *name, mode_t mode)
-{
-  return _mkdir (name);
-}
-
-#  define mkdir rpl_mkdir
+#if @GNULIB_STAT@
+# if @REPLACE_STAT@
+/* We can't use the object-like #define stat rpl_stat, because of
+   struct stat.  This means that rpl_stat will not be used if the user
+   does (stat)(a,b).  Oh well.  */
+#  undef stat
+#  define stat(name, st) rpl_stat (name, st)
+extern int stat (const char *name, struct stat *buf);
 # endif
+#elif defined GNULIB_POSIXCHECK
+# undef stat
+# define stat(p,b) \
+  (GL_LINK_WARNING ("stat is unportable - " \
+    "use gnulib module stat for portability"), \
+   stat (p, b))
 #endif
 
 
-/* Declare BSD extensions.  */
-
-#if @GNULIB_LCHMOD@
-/* Change the mode of FILENAME to MODE, without dereferencing it if FILENAME
-   denotes a symbolic link.  */
-# if !@HAVE_LCHMOD@
-/* The lchmod replacement follows symbolic links.  Callers should take
-   this into account; lchmod should be applied only to arguments that
-   are known to not be symbolic links.  On hosts that lack lchmod,
-   this can lead to race conditions between the check and the
-   invocation of lchmod, but we know of no workarounds that are
-   reliable in general.  You might try requesting support for lchmod
-   from your operating system supplier.  */
-#  define lchmod chmod
+#if @GNULIB_UTIMENSAT@
+# if @REPLACE_UTIMENSAT@
+#  undef utimensat
+#  define utimensat rpl_utimensat
 # endif
-# if 0 /* assume already declared */
-extern int lchmod (const char *filename, mode_t mode);
+# if !@HAVE_UTIMENSAT@ || @REPLACE_UTIMENSAT@
+   extern int utimensat (int fd, char const *name,
+                         struct timespec const times[2], int flag);
 # endif
 #elif defined GNULIB_POSIXCHECK
-# undef lchmod
-# define lchmod(f,m) \
-    (GL_LINK_WARNING ("lchmod is unportable - " \
-                      "use gnulib module lchmod for portability"), \
-     lchmod (f, m))
+# undef utimensat
+# define utimensat(d,n,t,f)                          \
+    (GL_LINK_WARNING ("utimensat is not portable - " \
+                      "use gnulib module utimensat for portability"), \
+     utimensat (d, n, t, f))
 #endif
 
 
--
1.6.4.4



_______________________________________________
Gnutls-devel mailing list
Gnutls-devel@...
http://lists.gnu.org/mailman/listinfo/gnutls-devel

[PATCH 2/2] Use lib-symbol-visibility for the C++ library

by Boyan Kasarov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

---
 lib/Makefile.am                |    5 +++-
 lib/includes/gnutls/gnutlsxx.h |   46 ++++++++++++++++++++++++---------------
 lib/libgnutlsxx.map            |    2 -
 3 files changed, 32 insertions(+), 21 deletions(-)

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 350a087..ab4ddb4 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -141,7 +141,10 @@ endif
 # C++ library
 
 if ENABLE_CXX
-libgnutlsxx_la_CPPFLAGS = -I$(top_srcdir)/includes -I$(top_builddir)/includes
+libgnutlsxx_la_CPPFLAGS = -DBUILDING_GNUTLSXX \
+                          $(CFLAG_VISIBILITY) \
+                          -I$(top_srcdir)/includes \
+                          -I$(top_builddir)/includes
 
 AM_CXXFLAGS = -I$(top_srcdir)/includes/
 
diff --git a/lib/includes/gnutls/gnutlsxx.h b/lib/includes/gnutls/gnutlsxx.h
index b3013d2..f331b45 100644
--- a/lib/includes/gnutls/gnutlsxx.h
+++ b/lib/includes/gnutls/gnutlsxx.h
@@ -5,10 +5,20 @@
 #include <vector>
 #include <gnutls/gnutls.h>
 
+#if BUILDING_GNUTLSXX && HAVE_VISIBILITY
+#define GNUTLSXX_DLL_EXPORTED __attribute__((__visibility__("default")))
+#elif BUILDING_GNUTLSXX && defined _MSC_VER
+#define GNUTLSXX_DLL_EXPORTED __declspec(dllexport)
+#elif defined _MSC_VER
+#define GNUTLSXX_DLL_EXPORTED __declspec(dllimport)
+#else
+#define GNUTLSXX_DLL_EXPORTED
+#endif
+
 namespace gnutls
 {
 
-  class noncopyable
+  class GNUTLSXX_DLL_EXPORTED noncopyable
   {
   protected:
     noncopyable ()
@@ -25,7 +35,7 @@ namespace gnutls
   };
 
 
-  class exception:public std::exception
+  class GNUTLSXX_DLL_EXPORTED exception:public std::exception
   {
   public:
     exception (int x);
@@ -36,7 +46,7 @@ namespace gnutls
   };
 
 
-  class dh_params:private noncopyable
+  class GNUTLSXX_DLL_EXPORTED dh_params:private noncopyable
   {
   public:
     dh_params ();
@@ -58,7 +68,7 @@ namespace gnutls
   };
 
 
-  class rsa_params:private noncopyable
+  class GNUTLSXX_DLL_EXPORTED rsa_params:private noncopyable
   {
   public:
     rsa_params ();
@@ -84,7 +94,7 @@ namespace gnutls
       gnutls_rsa_params_t params;
   };
 
-  class session:private noncopyable
+  class GNUTLSXX_DLL_EXPORTED session:private noncopyable
   {
   protected:
     gnutls_session_t s;
@@ -204,7 +214,7 @@ namespace gnutls
   };
 
 // interface for databases
-  class DB:private noncopyable
+  class GNUTLSXX_DLL_EXPORTED DB:private noncopyable
   {
   public:
     virtual ~ DB () = 0;
@@ -215,7 +225,7 @@ namespace gnutls
     virtual bool remove (const gnutls_datum_t & key) = 0;
   };
 
-  class server_session:public session
+  class GNUTLSXX_DLL_EXPORTED server_session:public session
   {
   public:
     server_session ();
@@ -239,7 +249,7 @@ namespace gnutls
     void set_certificate_request (gnutls_certificate_request_t);
   };
 
-  class client_session:public session
+  class GNUTLSXX_DLL_EXPORTED client_session:public session
   {
   public:
     client_session ();
@@ -252,7 +262,7 @@ namespace gnutls
   };
 
 
-  class credentials:private noncopyable
+  class GNUTLSXX_DLL_EXPORTED credentials:private noncopyable
   {
   public:
     virtual ~ credentials ()
@@ -269,7 +279,7 @@ namespace gnutls
     void *cred;
   };
 
-  class certificate_credentials:public credentials
+  class GNUTLSXX_DLL_EXPORTED certificate_credentials:public credentials
   {
   public:
     ~certificate_credentials ();
@@ -314,7 +324,7 @@ namespace gnutls
       gnutls_certificate_credentials_t cred;
   };
 
-  class certificate_server_credentials:public certificate_credentials
+  class GNUTLSXX_DLL_EXPORTED certificate_server_credentials:public certificate_credentials
   {
   public:
     void set_retrieve_function (gnutls_certificate_server_retrieve_function *
@@ -322,7 +332,7 @@ namespace gnutls
     void set_params_function (gnutls_params_function * func);
   };
 
-  class certificate_client_credentials:public certificate_credentials
+  class GNUTLSXX_DLL_EXPORTED certificate_client_credentials:public certificate_credentials
   {
   public:
     void set_retrieve_function (gnutls_certificate_client_retrieve_function *
@@ -332,7 +342,7 @@ namespace gnutls
 
 
 
-  class anon_server_credentials:public credentials
+  class GNUTLSXX_DLL_EXPORTED anon_server_credentials:public credentials
   {
   public:
     anon_server_credentials ();
@@ -343,7 +353,7 @@ namespace gnutls
       gnutls_anon_server_credentials_t cred;
   };
 
-  class anon_client_credentials:public credentials
+  class GNUTLSXX_DLL_EXPORTED anon_client_credentials:public credentials
   {
   public:
     anon_client_credentials ();
@@ -353,7 +363,7 @@ namespace gnutls
   };
 
 
-  class srp_server_credentials:public credentials
+  class GNUTLSXX_DLL_EXPORTED srp_server_credentials:public credentials
   {
   public:
     srp_server_credentials ();
@@ -366,7 +376,7 @@ namespace gnutls
       gnutls_srp_server_credentials_t cred;
   };
 
-  class srp_client_credentials:public credentials
+  class GNUTLSXX_DLL_EXPORTED srp_client_credentials:public credentials
   {
   public:
     srp_client_credentials ();
@@ -379,7 +389,7 @@ namespace gnutls
   };
 
 
-  class psk_server_credentials:public credentials
+  class GNUTLSXX_DLL_EXPORTED psk_server_credentials:public credentials
   {
   public:
     psk_server_credentials ();
@@ -393,7 +403,7 @@ namespace gnutls
       gnutls_psk_server_credentials_t cred;
   };
 
-  class psk_client_credentials:public credentials
+  class GNUTLSXX_DLL_EXPORTED psk_client_credentials:public credentials
   {
   public:
     psk_client_credentials ();
diff --git a/lib/libgnutlsxx.map b/lib/libgnutlsxx.map
index f61d861..8ced950 100644
--- a/lib/libgnutlsxx.map
+++ b/lib/libgnutlsxx.map
@@ -36,6 +36,4 @@ GNUTLS_1_6
 
       *gnutls::*;
   };
-
-  local: *;
 };
--
1.6.4.4



_______________________________________________
Gnutls-devel mailing list
Gnutls-devel@...
http://lists.gnu.org/mailman/listinfo/gnutls-devel

Re: libgnutlsxx link problems

by Simon Josefsson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Boyan Kasarov <bkasarov@...> writes:

> Hello,
> I am sending two patches to add symbol visibility support.
>
> [PATCH 1/2] Import lib-symbol-visibility from gnulib
> [PATCH 2/2] Use lib-symbol-visibility for the C++ library

Thanks!  The patch looks good, so I'll push it once your FSF copyright
papers have arrived (if I didn't send these off-list, please remind me).

> The second patch adds the necessary changes as explained in
> lib-symbol-visibility manual to add support for libgnutlsxx. I also
> removed the "local: *;" directive from libgnutlsxx.map, because it is
> no longer needed to hide symbols using it.

I'm not sure, maybe the 'local: *' is still needed: what if you use a
compiler that doesn't support symbol visibility but supports linker
version scripts?  Then 'local: *' would be useful.  Is there any harm in
keeping it?

/Simon


_______________________________________________
Gnutls-devel mailing list
Gnutls-devel@...
http://lists.gnu.org/mailman/listinfo/gnutls-devel

Re: libgnutlsxx link problems

by Boyan Kasarov :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

On Mon, 2009-10-19 at 12:51 +0200, Simon Josefsson wrote:

> I'm not sure, maybe the 'local: *' is still needed: what if you use a
> compiler that doesn't support symbol visibility but supports linker
> version scripts?  Then 'local: *' would be useful.  Is there any harm in
> keeping it?

I agree, there is no harm to keep the 'local: *;' as long as classes are
specified in the correct way in the script. So feel free to cut the
modification in libgnutlsxx.map from the patch.

Boyan




_______________________________________________
Gnutls-devel mailing list
Gnutls-devel@...
http://lists.gnu.org/mailman/listinfo/gnutls-devel

Re: libgnutlsxx link problems

by Simon Josefsson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Boyan Kasarov <bkasarov@...> writes:

> Hello,
>
> On Mon, 2009-10-19 at 12:51 +0200, Simon Josefsson wrote:
>
>> I'm not sure, maybe the 'local: *' is still needed: what if you use a
>> compiler that doesn't support symbol visibility but supports linker
>> version scripts?  Then 'local: *' would be useful.  Is there any harm in
>> keeping it?
>
> I agree, there is no harm to keep the 'local: *;' as long as classes are
> specified in the correct way in the script. So feel free to cut the
> modification in libgnutlsxx.map from the patch.

Great, thanks.

/Simon


_______________________________________________
Gnutls-devel mailing list
Gnutls-devel@...
http://lists.gnu.org/mailman/listinfo/gnutls-devel