tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [PATCH] libpthread NOLOAD removal



On Sun, Feb 17, 2013 at 04:54:53AM +0100, Emmanuel Dreyfus wrote:
> Here is my llatest patch for libpthread NOLOAD removal. It implements
> minimal mutex, condvar and rwlock operations in libc thread stubs, so
> that theses objects can be handled by both libc and libpthread after
> libpthread has been loaded by dlopen.

It is still the wrong approach. Attached is a preliminary patch for
devel/glib2 to fix the pthread usage. Primary issue with the patch is
testing on other platforms and moving the condattr support into libc to
complement the existing CV logic. It should also be decided whether we
shouldn't just provide pthread_join and pthread_detach in libc.

Joerg
Index: devel/glib2/distinfo
==================================================================
--- devel/glib2/distinfo
+++ devel/glib2/distinfo
@@ -34,7 +34,10 @@
 SHA1 (patch-ck) = 324116cc6fb8dbce8ce8d20f5b237fc469a55cd2
 SHA1 (patch-cl) = eb00468c5c5c70dd41803a2a263204686959a415
 SHA1 (patch-cm) = 7f14ab327d021537714f876fbfbd4b0350d98a6e
 SHA1 (patch-cn) = 611ad0a210fda4b22d7efbffe6a8e0db8ee92b05
 SHA1 (patch-gio_gresource-tool.c) = 4eb7c9df25e9ac3e977edf3be8fb977a6fb39182
+SHA1 (patch-glib_Makefile.am) = 3a3f958701285d1f46ab920389d11361f5b6fa32
+SHA1 (patch-glib_Makefile.in) = 40d89b2c9086aada643c4bac44674ac5691ec1be
 SHA1 (patch-glib_goption.c) = 323297aa328b85493f156792b4baa0cb04fa82ad
+SHA1 (patch-glib_gthread-posix.c) = 3aedb19f964932adb9fd1fc5ce2922bd85f38a9c
 SHA1 (patch-glib_tests_include.c) = 95f7d34e6e03849316bbfac1541eec4582b92ffc

ADDED    devel/glib2/patches/patch-glib_Makefile.am
Index: devel/glib2/patches/patch-glib_Makefile.am
==================================================================
--- devel/glib2/patches/patch-glib_Makefile.am
+++ devel/glib2/patches/patch-glib_Makefile.am
@@ -0,0 +1,13 @@
+$NetBSD$
+
+--- glib/Makefile.am.orig      2012-11-26 16:52:48.000000000 +0000
++++ glib/Makefile.am
+@@ -375,7 +375,7 @@ pcre_lib = pcre/libpcre.la
+ pcre_inc =
+ endif
+ 
+-libglib_2_0_la_LIBADD = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ 
@PLATFORMDEP@ @ICONV_LIBS@ @G_LIBS_EXTRA@ $(pcre_lib) $(G_THREAD_LIBS_EXTRA) 
$(G_THREAD_LIBS_FOR_GTHREAD)
++libglib_2_0_la_LIBADD = libcharset/libcharset.la $(printf_la) @GIO@ @GSPAWN@ 
@PLATFORMDEP@ @ICONV_LIBS@ @G_LIBS_EXTRA@ $(pcre_lib)
+ libglib_2_0_la_DEPENDENCIES = libcharset/libcharset.la $(printf_la) @GIO@ 
@GSPAWN@ @PLATFORMDEP@ $(glib_win32_res) $(glib_def)
+ 
+ libglib_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \

ADDED    devel/glib2/patches/patch-glib_Makefile.in
Index: devel/glib2/patches/patch-glib_Makefile.in
==================================================================
--- devel/glib2/patches/patch-glib_Makefile.in
+++ devel/glib2/patches/patch-glib_Makefile.in
@@ -0,0 +1,12 @@
+$NetBSD$
+
+--- glib/Makefile.in.orig      2013-02-18 13:15:52.000000000 +0000
++++ glib/Makefile.in
+@@ -759,7 +759,6 @@ glibsubinclude_HEADERS = \
+ @USE_SYSTEM_PCRE_TRUE@pcre_inc = $(PCRE_CFLAGS)
+ libglib_2_0_la_LIBADD = libcharset/libcharset.la $(printf_la) @GIO@ \
+       @GSPAWN@ @PLATFORMDEP@ @ICONV_LIBS@ @G_LIBS_EXTRA@ $(pcre_lib) \
+-      $(G_THREAD_LIBS_EXTRA) $(G_THREAD_LIBS_FOR_GTHREAD) \
+       $(am__append_7)
+ libglib_2_0_la_DEPENDENCIES = libcharset/libcharset.la $(printf_la) @GIO@ 
@GSPAWN@ @PLATFORMDEP@ $(glib_win32_res) $(glib_def)
+ libglib_2_0_la_LDFLAGS = $(GLIB_LINK_FLAGS) \

ADDED    devel/glib2/patches/patch-glib_gthread-posix.c
Index: devel/glib2/patches/patch-glib_gthread-posix.c
==================================================================
--- devel/glib2/patches/patch-glib_gthread-posix.c
+++ devel/glib2/patches/patch-glib_gthread-posix.c
@@ -0,0 +1,84 @@
+$NetBSD$
+
+--- glib/gthread-posix.c.orig  2013-02-18 11:46:30.000000000 +0000
++++ glib/gthread-posix.c
+@@ -67,6 +67,15 @@
+ #include <sys/prctl.h>
+ #endif
+ 
++int   pthread_join(pthread_t, void **) __attribute__((__weak__));
++int   pthread_detach(pthread_t) __attribute__((__weak__));
++int   pthread_attr_init(pthread_attr_t *) __attribute__((__weak__));
++int   pthread_attr_destroy(pthread_attr_t *) __attribute__((__weak__));
++int   pthread_attr_setstacksize(pthread_attr_t *, size_t) 
__attribute__((__weak__));
++int   pthread_condattr_init(pthread_condattr_t *) __attribute__((__weak__));
++int     pthread_condattr_setclock(pthread_condattr_t *, clockid_t) 
__attribute__((__weak__));
++int   pthread_condattr_destroy(pthread_condattr_t *) 
__attribute__((__weak__));
++
+ static void
+ g_thread_abort (gint         status,
+                 const gchar *function)
+@@ -633,23 +642,30 @@ g_rw_lock_reader_unlock (GRWLock *rw_loc
+ static pthread_cond_t *
+ g_cond_impl_new (void)
+ {
+-  pthread_condattr_t attr;
++  pthread_condattr_t *attrp;
+   pthread_cond_t *cond;
+   gint status;
+ 
+-  pthread_condattr_init (&attr);
+-#if defined (HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined (CLOCK_MONOTONIC)
+-  pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
+-#endif
+-
+   cond = malloc (sizeof (pthread_cond_t));
+   if G_UNLIKELY (cond == NULL)
+     g_thread_abort (errno, "malloc");
+ 
+-  if G_UNLIKELY ((status = pthread_cond_init (cond, &attr)) != 0)
++  if (pthread_condattr_init) {
++    pthread_condattr_t attr;
++    attrp = &attr;
++    pthread_condattr_init (&attr);
++#if defined (HAVE_PTHREAD_CONDATTR_SETCLOCK) && defined (CLOCK_MONOTONIC)
++    pthread_condattr_setclock (&attr, CLOCK_MONOTONIC);
++#endif
++  } else {
++    attrp = NULL;
++  }
++
++  if G_UNLIKELY ((status = pthread_cond_init (cond, attrp)) != 0)
+     g_thread_abort (status, "pthread_cond_init");
+ 
+-  pthread_condattr_destroy (&attr);
++  if (attrp)
++    pthread_condattr_destroy (attrp);
+ 
+   return cond;
+ }
+@@ -1090,6 +1106,10 @@ g_system_thread_free (GRealThread *threa
+   g_slice_free (GThreadPosix, pt);
+ }
+ 
++__attribute__((__weak__))
++int   pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *),
++          void *);
++
+ GRealThread *
+ g_system_thread_new (GThreadFunc   thread_func,
+                      gulong        stack_size,
+@@ -1099,6 +1119,13 @@ g_system_thread_new (GThreadFunc   threa
+   pthread_attr_t attr;
+   gint ret;
+ 
++  if (pthread_create == NULL) {
++      g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN, 
++                   "Threading not supported due to missing -lpthread");
++      g_slice_free (GThreadPosix, thread);
++      return NULL;
++  }
++
+   thread = g_slice_new0 (GThreadPosix);
+ 
+   posix_check_cmd (pthread_attr_init (&attr));



Home | Main Index | Thread Index | Old Index