Mark Wielaard ee9019
commit 15330adf7c2471fbaa6a0818db07078d81dbff97
Mark Wielaard ee9019
Author: Bart Van Assche <bvanassche@acm.org>
Mark Wielaard ee9019
Date:   Sat Sep 19 08:08:59 2020 -0700
Mark Wielaard ee9019
Mark Wielaard ee9019
    drd: Port to Fedora 33
Mark Wielaard ee9019
    
Mark Wielaard ee9019
    Apparently on Fedora 33 the POSIX thread functions exist in both libc and
Mark Wielaard ee9019
    libpthread. Hence this patch that intercepts the pthread functions in
Mark Wielaard ee9019
    libc. See also https://bugs.kde.org/show_bug.cgi?id=426144 .
Mark Wielaard ee9019
Mark Wielaard ee9019
diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c
Mark Wielaard ee9019
index 58c45aaec..c2882e5ab 100644
Mark Wielaard ee9019
--- a/drd/drd_pthread_intercepts.c
Mark Wielaard ee9019
+++ b/drd/drd_pthread_intercepts.c
Mark Wielaard ee9019
@@ -174,7 +174,16 @@ static int never_true;
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl            \
Mark Wielaard ee9019
    { return implf argl; }
Mark Wielaard ee9019
 #else
Mark Wielaard ee9019
+/*
Mark Wielaard ee9019
+ * On Linux, intercept both the libc and the libpthread functions. At
Mark Wielaard ee9019
+ * least glibc 2.32.9000 (Fedora 34) has an implementation of all pthread
Mark Wielaard ee9019
+ * functions in both libc and libpthread. Older glibc versions only have an
Mark Wielaard ee9019
+ * implementation of the pthread functions in libpthread.
Mark Wielaard ee9019
+ */
Mark Wielaard ee9019
 #define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl)                    \
Mark Wielaard ee9019
+   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl;           \
Mark Wielaard ee9019
+   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl            \
Mark Wielaard ee9019
+   { return implf argl; }                                               \
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl;     \
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
Mark Wielaard ee9019
    { return implf argl; }
Mark Wielaard ee9019
Mark Wielaard ee9019
commit 3073d03e4b6e76797828b3f466863dbdda76cc7a
Mark Wielaard ee9019
Author: Bart Van Assche <bvanassche@acm.org>
Mark Wielaard ee9019
Date:   Tue Oct 20 19:40:19 2020 -0700
Mark Wielaard ee9019
Mark Wielaard ee9019
    drd: Unbreak the musl build
Mark Wielaard ee9019
    
Mark Wielaard ee9019
    See also https://bugs.kde.org/show_bug.cgi?id=428035.
Mark Wielaard ee9019
    
Mark Wielaard ee9019
    Reported-by: Stacy <stacy.gaikovaia@windriver.com>
Mark Wielaard ee9019
    Fixes: 15330adf7c24 ("drd: Port to Fedora 33")
Mark Wielaard ee9019
Mark Wielaard ee9019
diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c
Mark Wielaard ee9019
index 62c466f50..585aafe22 100644
Mark Wielaard ee9019
--- a/drd/drd_pthread_intercepts.c
Mark Wielaard ee9019
+++ b/drd/drd_pthread_intercepts.c
Mark Wielaard ee9019
@@ -174,6 +174,13 @@ static int never_true;
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl            \
Mark Wielaard ee9019
    { return implf argl; }
Mark Wielaard ee9019
 #else
Mark Wielaard ee9019
+#ifdef MUSL_LIBC
Mark Wielaard ee9019
+/* musl provides a single library that includes pthreads functions. */
Mark Wielaard ee9019
+#define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl)                    \
Mark Wielaard ee9019
+   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl;     \
Mark Wielaard ee9019
+   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
Mark Wielaard ee9019
+   { return implf argl; }
Mark Wielaard ee9019
+#else
Mark Wielaard ee9019
 /*
Mark Wielaard ee9019
  * On Linux, intercept both the libc and the libpthread functions. At
Mark Wielaard ee9019
  * least glibc 2.32.9000 (Fedora 34) has an implementation of all pthread
Mark Wielaard ee9019
@@ -188,6 +195,7 @@ static int never_true;
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
Mark Wielaard ee9019
    { return implf argl; }
Mark Wielaard ee9019
 #endif
Mark Wielaard ee9019
+#endif
Mark Wielaard ee9019
 
Mark Wielaard ee9019
 /**
Mark Wielaard ee9019
  * Macro for generating three Valgrind interception functions: one with the
Mark Wielaard ee9019
diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c
Mark Wielaard ee9019
Mark Wielaard ee9019
index 585aafe22..3d1f90d3b 100644
Mark Wielaard ee9019
--- a/drd/drd_pthread_intercepts.c
Mark Wielaard ee9019
+++ b/drd/drd_pthread_intercepts.c
Mark Wielaard ee9019
@@ -151,7 +151,7 @@ static drd_rtld_guard_fn DRD_(rtld_bind_clear) = NULL;
Mark Wielaard ee9019
  * @param[in] arg_decl Argument declaration list enclosed in parentheses.
Mark Wielaard ee9019
  * @param[in] argl Argument list enclosed in parentheses.
Mark Wielaard ee9019
  */
Mark Wielaard ee9019
-#ifdef VGO_darwin
Mark Wielaard ee9019
+#if defined(VGO_darwin)
Mark Wielaard ee9019
 static int never_true;
Mark Wielaard ee9019
 #define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl)                    \
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl;     \
Mark Wielaard ee9019
@@ -164,29 +164,12 @@ static int never_true;
Mark Wielaard ee9019
 	 fflush(stdout);						\
Mark Wielaard ee9019
       return pth_func_result;						\
Mark Wielaard ee9019
    }
Mark Wielaard ee9019
-#elif defined(VGO_solaris)
Mark Wielaard ee9019
-/* On Solaris, libpthread is just a filter library on top of libc.
Mark Wielaard ee9019
- * Threading and synchronization functions in runtime linker are not
Mark Wielaard ee9019
- * intercepted.
Mark Wielaard ee9019
- */
Mark Wielaard ee9019
+#elif defined(VG_WRAP_THREAD_FUNCTION_LIBC_ONLY)
Mark Wielaard ee9019
 #define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl)                    \
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl;           \
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl            \
Mark Wielaard ee9019
    { return implf argl; }
Mark Wielaard ee9019
-#else
Mark Wielaard ee9019
-#ifdef MUSL_LIBC
Mark Wielaard ee9019
-/* musl provides a single library that includes pthreads functions. */
Mark Wielaard ee9019
-#define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl)                    \
Mark Wielaard ee9019
-   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl;     \
Mark Wielaard ee9019
-   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
Mark Wielaard ee9019
-   { return implf argl; }
Mark Wielaard ee9019
-#else
Mark Wielaard ee9019
-/*
Mark Wielaard ee9019
- * On Linux, intercept both the libc and the libpthread functions. At
Mark Wielaard ee9019
- * least glibc 2.32.9000 (Fedora 34) has an implementation of all pthread
Mark Wielaard ee9019
- * functions in both libc and libpthread. Older glibc versions only have an
Mark Wielaard ee9019
- * implementation of the pthread functions in libpthread.
Mark Wielaard ee9019
- */
Mark Wielaard ee9019
+#elif defined(VG_WRAP_THREAD_FUNCTION_LIBC_AND_LIBPTHREAD)
Mark Wielaard ee9019
 #define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl)                    \
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl;           \
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl            \
Mark Wielaard ee9019
@@ -194,7 +177,8 @@ static int never_true;
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl;     \
Mark Wielaard ee9019
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
Mark Wielaard ee9019
    { return implf argl; }
Mark Wielaard ee9019
-#endif
Mark Wielaard ee9019
+#else
Mark Wielaard ee9019
+#  error "Unknown platform/thread wrapping"
Mark Wielaard ee9019
 #endif
Mark Wielaard ee9019
 
Mark Wielaard ee9019
 /**
Mark Wielaard ee9019
diff --git a/helgrind/hg_intercepts.c b/helgrind/hg_intercepts.c
Mark Wielaard ee9019
index a10c3a4a3..2bc89f8a0 100644
Mark Wielaard ee9019
--- a/helgrind/hg_intercepts.c
Mark Wielaard ee9019
+++ b/helgrind/hg_intercepts.c
Mark Wielaard ee9019
@@ -78,26 +78,37 @@
Mark Wielaard ee9019
 /*----------------------------------------------------------------*/
Mark Wielaard ee9019
 
Mark Wielaard ee9019
 #if defined(VGO_solaris)
Mark Wielaard ee9019
-/* On Solaris, libpthread is just a filter library on top of libc.
Mark Wielaard ee9019
- * Threading and synchronization functions in runtime linker are not
Mark Wielaard ee9019
- * intercepted.
Mark Wielaard ee9019
- */
Mark Wielaard ee9019
-#define PTH_FUNC(ret_ty, f, args...) \
Mark Wielaard ee9019
-   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBC_SONAME,f)(args); \
Mark Wielaard ee9019
-   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBC_SONAME,f)(args)
Mark Wielaard ee9019
-
Mark Wielaard ee9019
 /* pthread_t is typedef'd to 'unsigned int' but in DO_CREQ_* macros
Mark Wielaard ee9019
    sizeof(Word) is expected. */
Mark Wielaard ee9019
 #define CREQ_PTHREAD_T Word
Mark Wielaard ee9019
 #define SEM_ERROR ret
Mark Wielaard ee9019
 #else
Mark Wielaard ee9019
-#define PTH_FUNC(ret_ty, f, args...) \
Mark Wielaard ee9019
-   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME,f)(args); \
Mark Wielaard ee9019
-   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME,f)(args)
Mark Wielaard ee9019
 #define CREQ_PTHREAD_T pthread_t
Mark Wielaard ee9019
 #define SEM_ERROR errno
Mark Wielaard ee9019
 #endif /* VGO_solaris */
Mark Wielaard ee9019
 
Mark Wielaard ee9019
+#define HG_EXPAND(tok) #tok
Mark Wielaard ee9019
+#define HG_STR(tok) HG_EXPAND(tok)
Mark Wielaard ee9019
+#define HG_WEAK_ALIAS(name, aliasname) \
Mark Wielaard ee9019
+  extern __typeof (name) aliasname __attribute__ ((weak, alias(HG_STR(name))))
Mark Wielaard ee9019
+
Mark Wielaard ee9019
+#if defined(VG_WRAP_THREAD_FUNCTION_LIBPTHREAD_ONLY)
Mark Wielaard ee9019
+#define PTH_FUNC(ret_ty, f, args...) \
Mark Wielaard ee9019
+   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME,f)(args); \
Mark Wielaard ee9019
+   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME,f)(args)
Mark Wielaard ee9019
+#elif defined(VG_WRAP_THREAD_FUNCTION_LIBC_AND_LIBPTHREAD)
Mark Wielaard ee9019
+#define PTH_FUNC(ret_ty, f, args...) \
Mark Wielaard ee9019
+   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME,f)(args); \
Mark Wielaard ee9019
+   HG_WEAK_ALIAS(I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME,f), I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBC_SONAME,f)); \
Mark Wielaard ee9019
+   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBPTHREAD_SONAME,f)(args)
Mark Wielaard ee9019
+#elif defined(VG_WRAP_THREAD_FUNCTION_LIBC_ONLY)
Mark Wielaard ee9019
+#define PTH_FUNC(ret_ty, f, args...) \
Mark Wielaard ee9019
+   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBC_SONAME,f)(args); \
Mark Wielaard ee9019
+   ret_ty I_WRAP_SONAME_FNNAME_ZZ(VG_Z_LIBC_SONAME,f)(args)
Mark Wielaard ee9019
+#else
Mark Wielaard ee9019
+#  error "Unknown platform/thread wrapping"
Mark Wielaard ee9019
+#endif
Mark Wielaard ee9019
+
Mark Wielaard ee9019
 // Do a client request.  These are macros rather than a functions so
Mark Wielaard ee9019
 // as to avoid having an extra frame in stack traces.
Mark Wielaard ee9019
 
Mark Wielaard ee9019
diff --git a/include/pub_tool_redir.h b/include/pub_tool_redir.h
Mark Wielaard ee9019
index bd65a44b4..d665afd98 100644
Mark Wielaard ee9019
--- a/include/pub_tool_redir.h
Mark Wielaard ee9019
+++ b/include/pub_tool_redir.h
Mark Wielaard ee9019
@@ -277,11 +277,7 @@
Mark Wielaard ee9019
 /* --- Soname of the pthreads library. --- */
Mark Wielaard ee9019
 
Mark Wielaard ee9019
 #if defined(VGO_linux)
Mark Wielaard ee9019
-# if defined(MUSL_LIBC)
Mark Wielaard ee9019
-#  define  VG_Z_LIBPTHREAD_SONAME  libcZdZa              // libc.*
Mark Wielaard ee9019
-#else
Mark Wielaard ee9019
 #  define  VG_Z_LIBPTHREAD_SONAME  libpthreadZdsoZd0     // libpthread.so.0
Mark Wielaard ee9019
-#endif
Mark Wielaard ee9019
 #elif defined(VGO_darwin)
Mark Wielaard ee9019
 #  define  VG_Z_LIBPTHREAD_SONAME  libSystemZdZaZddylib  // libSystem.*.dylib
Mark Wielaard ee9019
 #elif defined(VGO_solaris)
Mark Wielaard ee9019
@@ -364,6 +360,27 @@
Mark Wielaard ee9019
 
Mark Wielaard ee9019
 Bool VG_(is_soname_ld_so) (const HChar *soname);
Mark Wielaard ee9019
 
Mark Wielaard ee9019
+// Some macros to help decide which libraries (libc or libpthread
Mark Wielaard ee9019
+// or some platform-specific variation of these) should be used
Mark Wielaard ee9019
+// for wrapping pthread/semaphore functions with DRD and Helgrind
Mark Wielaard ee9019
+// The possibilities are a) only in libpthread
Mark Wielaard ee9019
+// b) mabye in both libpthread and libc or c) only in libc
Mark Wielaard ee9019
+// Linux GNU libc is moving from a) to c) (starting with Fedora 33)
Mark Wielaard ee9019
+// Linux MUSL libc is c)
Mark Wielaard ee9019
+// Darwin is a)
Mark Wielaard ee9019
+// Solaris is c)
Mark Wielaard ee9019
+// FreeBSD is b)
Mark Wielaard ee9019
+
Mark Wielaard ee9019
+#if defined(VGO_darwin)
Mark Wielaard ee9019
+#define VG_WRAP_THREAD_FUNCTION_LIBPTHREAD_ONLY
Mark Wielaard ee9019
+#elif defined(VGO_solaris) || (defined(VGO_linux) && defined(MUSL_LIBC))
Mark Wielaard ee9019
+#define VG_WRAP_THREAD_FUNCTION_LIBC_ONLY
Mark Wielaard ee9019
+#elif defined(VGO_linux)
Mark Wielaard ee9019
+#define VG_WRAP_THREAD_FUNCTION_LIBC_AND_LIBPTHREAD
Mark Wielaard ee9019
+#else
Mark Wielaard ee9019
+#  error "Unknown platform"
Mark Wielaard ee9019
+#endif
Mark Wielaard ee9019
+
Mark Wielaard ee9019
 #endif   // __PUB_TOOL_REDIR_H
Mark Wielaard ee9019
 
Mark Wielaard ee9019
 /*--------------------------------------------------------------------*/