[gnutls-devel] [PATCH] Define _gnutls_file_mutex in gnutls_global.c instead of in verify-tofu.c

Martin Storsjo martin at martin.st
Mon Jan 21 15:00:10 CET 2013

This fixes issues with linking the tools on OS X if not building
shared libraries.

Currently, if building with --disable-shared on OS X, the build
fails with:
  CCLD   gnutls-serv
Undefined symbols for architecture x86_64:
  "__gnutls_file_mutex", referenced from:
      _gnutls_global_deinit in libgnutls.a(gnutls_global.o)
      _gnutls_global_init in libgnutls.a(gnutls_global.o)
ld: symbol(s) not found for architecture x86_64

It seems that the linker fails to pull in verify-tofu.o to satisfy
the undefined reference to _gnutls_file_mutex.o in gnutls_global.o
unless gnutls_global.o (or any other object file in the link) also
calls functions that pulls in verify-tofu.o. Since gnutls_global.o
always is linked in, but verify-tofu.o can be left out unless someone
calls the functions in it, defining the mutex in gnutls_global.c makes
sense and simplifies the dependencies.
 lib/gnutls_global.c |    2 +-
 lib/verify-tofu.c   |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c
index 295e620..1959bd3 100644
--- a/lib/gnutls_global.c
+++ b/lib/gnutls_global.c
@@ -42,7 +42,7 @@
 /* created by asn1c */
 extern const ASN1_ARRAY_TYPE gnutls_asn1_tab[];
 extern const ASN1_ARRAY_TYPE pkix_asn1_tab[];
-extern void *_gnutls_file_mutex;
+void *_gnutls_file_mutex;
 ASN1_TYPE _gnutls_pkix1_asn;
 ASN1_TYPE _gnutls_gnutls_asn;
diff --git a/lib/verify-tofu.c b/lib/verify-tofu.c
index 3592395..4c19c90 100644
--- a/lib/verify-tofu.c
+++ b/lib/verify-tofu.c
@@ -60,7 +60,7 @@ int store_pubkey(const char* db_name, const char* host,
 static int find_config_file(char* file, size_t max_size);
 #define MAX_FILENAME 512
-void *_gnutls_file_mutex;
+extern void *_gnutls_file_mutex;
 struct gnutls_tdb_int default_tdb = {

More information about the Gnutls-devel mailing list