Mailing List Archive

libgpg-error 1.44 fails to build on FreeBSD 11
Hi,

libgpg-error 1.44 fails to build on FreeBSD 11 with:

libtool: link: ranlib .libs/libgpg-error.a
libtool: link: ( cd ".libs" && rm -f "libgpg-error.la" && ln -s "../libgpg-error.la" "libgpg-error.la" )
/bin/sh ../libtool --tag=CC --mode=link cc -O2 -pipe -DLIBICONV_PLUG -fstack-protector-strong -fno-strict-aliasing -Wall -Wpointer-arith -fvisibility=hidden -fstack-protector-strong -L/usr/local/lib -o gpg-error gpg_error-strsource-sym.o gpg_error-strerror-sym.o gpg_error-gpg-error.o libgpg-error.la -L/usr/local/lib -lintl -R/usr/local/lib
libtool: link: cc -O2 -pipe -DLIBICONV_PLUG -fstack-protector-strong -fno-strict-aliasing -Wall -Wpointer-arith -fvisibility=hidden -fstack-protector-strong -o .libs/gpg-error gpg_error-strsource-sym.o gpg_error-strerror-sym.o gpg_error-gpg-error.o -L/usr/local/lib ./.libs/libgpg-error.so -lintl -Wl,-rpath -Wl,/usr/local/lib
./.libs/libgpg-error.so: undefined reference to `pthread_create'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make[4]: stopped in /wrkdirs/usr/ports/security/libgpg-error/work/libgpg-error-1.44/src
*** Error code 1

However, it builds fine on newer FreeBSD versions.

Looks like m4/threadlib.m4 has some special handling for FreeBSD weak
symbol related bug, which in combination with other checks leads to
having PTHREAD_IN_USE_DETECTION_HARD defined, which unlocks the code in
src/posix-lock.c which uses pthread_create(), but doesn't link any
threading libraries. And that's not the case for the newer FreeBSD
versions.

The following patch appears to fix the issue:

diff --git a/src/Makefile.am b/src/Makefile.am
index 34e0476..cfcbe16 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -215,7 +215,7 @@ nodist_libgpg_error_la_SOURCES = gpg-error.h
# without the extra_cppflags because they may include am -idirafter
# which is not supported by the RC compiler.
libgpg_error_la_CPPFLAGS = -DLOCALEDIR=\"$(localedir)\" $(extra_cppflags)
-libgpg_error_la_LIBADD = $(gpg_error_res) $(intllibs) $(socklibs) $(LIBTHREAD)
+libgpg_error_la_LIBADD = $(gpg_error_res) $(intllibs) $(socklibs) $(LIBMULTITHREAD)

gpg_error_SOURCES = strsource-sym.c strerror-sym.c gpg-error.c
gpg_error_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\" \

Not sure that's the right fix though, because with this change on a
newer FreeBSD versions it gets linked with an extra library:

$ ldd ./src/.libs/libgpg-error.so
./src/.libs/libgpg-error.so:
libintl.so.8 => /usr/local/lib/libintl.so.8 (0x2e55e4e7e000)
libthr.so.3 => /lib/libthr.so.3 (0x2e55e5e16000)
libc.so.7 => /lib/libc.so.7 (0x2e55e30fd000)

Which is apparently not required as before the change it was:

$ ldd ./src/.libs/libgpg-error.so
./src/.libs/libgpg-error.so:
libintl.so.8 => /usr/local/lib/libintl.so.8 (0xead5df6c000)
libc.so.7 => /lib/libc.so.7 (0xead5c797000)

Any ideas what would be the right fix?

Thanks,

Roman Bogorodskiy
Re: libgpg-error 1.44 fails to build on FreeBSD 11 [ In reply to ]
Hello,

Thank you for your report.

Roman Bogorodskiy wrote:
> Any ideas what would be the right fix?

For the particular code, libgpg-error uses a code from Gnulib. Since it
was updated in Gnulib, we need to fix. I pushed a change to fix this
issue. Please test (with no change of src/Makefile.am).


core: Fix support of posix-lock for FreeBSD.

* src/posix-lock.c [__FreeBSD__] (use_pthread_p): Use
pthread_key_create to determine if it's linked to lpthread or not.

--

This is from glthread_in_use in gnulib/lib/glthread/threadlib.c.

On FreeBSD, pthread_key_create is there in libc (stub function) as
well as -lpthread (real one), while pthread_create is not available
in libc.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>

diff --git a/src/posix-lock.c b/src/posix-lock.c
index d0fd07a..85ec660 100644
--- a/src/posix-lock.c
+++ b/src/posix-lock.c
@@ -67,6 +67,38 @@
# endif
# endif /*!USE_POSIX_THREADS_WEAK*/
# if PTHREAD_IN_USE_DETECTION_HARD
+# if defined __FreeBSD__ || defined __DragonFly__ /* FreeBSD */
+
+/* Test using pthread_key_create. */
+
+static int
+use_pthread_p (void)
+{
+ static int tested;
+ static int result; /* 1: linked with -lpthread, 0: only with libc */
+
+ if (!tested)
+ {
+ pthread_key_t key;
+ int err = pthread_key_create (&key, NULL);
+
+ if (err == ENOSYS)
+ result = 0;
+ else
+ {
+ result = 1;
+ if (err == 0)
+ pthread_key_delete (key);
+ }
+ tested = 1;
+ }
+ return result;
+}
+
+# else /* Solaris, HP-UX */
+
+/* Test using pthread_create. */
+
/* The function to be executed by a dummy thread. */
static void *
dummy_thread_func (void *arg)
@@ -84,7 +116,7 @@ use_pthread_p (void)
{
pthread_t thread;

- if (pthread_create (&thread, NULL, dummy_thread_func, NULL))
+ if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
result = 0; /* Thread creation failed. */
else
{
@@ -102,6 +134,8 @@ use_pthread_p (void)
}
return result;
}
+# endif /* Solaris, HP-UX */
+
# endif /*PTHREAD_IN_USE_DETECTION_HARD*/
#endif /*USE_POSIX_THREADS*/

--

_______________________________________________
Gnupg-devel mailing list
Gnupg-devel@lists.gnupg.org
https://lists.gnupg.org/mailman/listinfo/gnupg-devel
Re: libgpg-error 1.44 fails to build on FreeBSD 11 [ In reply to ]
NIIBE Yutaka wrote:

> Hello,
>
> Thank you for your report.
>
> Roman Bogorodskiy wrote:
> > Any ideas what would be the right fix?
>
> For the particular code, libgpg-error uses a code from Gnulib. Since it
> was updated in Gnulib, we need to fix. I pushed a change to fix this
> issue. Please test (with no change of src/Makefile.am).
>

Hi,

Thanks for the fix, appears to be working fine.

Roman Bogorodskiy