Bug 428035 - drd: dont need to intercept duplicate libc definitions if run with musl
Summary: drd: dont need to intercept duplicate libc definitions if run with musl
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: drd (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Stacy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-10-20 20:44 UTC by Stacy
Modified: 2020-10-22 00:34 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stacy 2020-10-20 20:44:52 UTC
SUMMARY
commit #15330adf7c2471fbaa6a0818db07078d81dbff97 (https://sourceware.org/git/?p=valgrind.git;a=commit;h=15330adf7c2471fbaa6a0818db07078d81dbff97) made it such that valgrind intercepts function definitions in both libc and libpthread. This breaks builds compiled with musl libc, as these same function defintions do not exist in musl.

STEPS TO REPRODUCE
1. Make sure you're on a system running musl (ldd --version)
2. attempt to compile valgrind 

OBSERVED RESULT
Compilation fails with
In file included from drd_pthread_intercepts.c:58:
../include/pub_tool_redir.h:228:15: error: redefinition of '_vgw00000ZZ_libcZdZa_pthreadZucreate'
  228 |    VG_CONCAT6(_vgw,00000,ZZ_,_soname,_,_fnname)
      |               ^~~~
../include/pub_tool_redir.h:202:45: note: in definit
ion of macro 'VG_CONCAT6'
  202 | #define VG_CONCAT6(_aa,_bb,_cc,_dd,_ee,_ff) _aa##_bb##_cc##_dd##_ee##_ff
      |                                             ^~~
drd_pthread_intercepts.c:188:11: note: in expansion of macro 'VG_WRAP_FUNCTION_ZZ'
  188 |    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
      |           ^~~~~~~~~~~~~~~~~~~
drd_pthread_intercepts.c:200:4: note: in expansion of macro 'PTH_FUNC'
  200 |    PTH_FUNC(ret_ty, zf, implf, argl_decl, argl);                \
      |    ^~~~~~~~
drd_pthread_intercepts.c:598:1: note: in expansion of macro 'PTH_FUNCS'
  598 | PTH_FUNCS(int, pthreadZucreate, pthread_create_intercept,
      | ^~~~~~~~~
../include/pub_tool_redir.h:228:15: note: previous definition of '_vgw00000ZZ_libcZdZa_pthreadZucreate' was here
  228 |    VG_CONCAT6(_vgw,00000,ZZ_,_soname,_,_fnname)
      |               ^~~~
../include/pub_tool_redir.h:202:45: note: in definition of macro 'VG_CONCAT6'
  202 | #define VG_CONCAT6(_aa,_bb,_cc,_dd,_ee,_ff) _aa##_bb##_cc##_dd##_ee##_ff
      |                                             ^~~
drd_pthread_intercepts.c:185:11: note: in expansion of macro 'VG_WRAP_FUNCTION_ZZ'
  185 |    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl            \
      |           ^~~~~~~~~~~~~~~~~~~
drd_pthread_intercepts.c:200:4: note: in expansion of macro 'PTH_FUNC'
  200 |    PTH_FUNC(ret_ty, zf, implf, argl_decl, argl);                \
      |    ^~~~~~~~
drd_pthread_intercepts.c:598:1: note: in expansion of macro 'PTH_FUNCS'
  598 | PTH_FUNCS(int, pthreadZucreate, pthread_create_intercept,
      | ^~~~~~~~~
../include/pub_tool_redir.h:228:15: error: redefinition of '_vgw00000ZZ_libcZdZa_pthreadZucreateZAZa'
  228 |    VG_CONCAT6(_vgw,00000,ZZ_,_soname,_,_fnname)
      |               ^~~~
../include/pub_tool_redir.h:202:45: note: in definition of macro 'VG_CONCAT6'
  202 | #define VG_CONCAT6(_aa,_bb,_cc,_dd,_ee,_ff) _aa##_bb##_cc##_dd##_ee##_ff
      |                                             ^~~
drd_pthread_intercepts.c:188:11: note: in expansion of macro 'VG_WRAP_FUNCTION_ZZ'
  188 |    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
      |           ^~~~~~~~~~~~~~~~~~~
drd_pthread_intercepts.c:201:4: note: in expansion of macro 'PTH_FUNC'
  201 |    PTH_FUNC(ret_ty, zf ## ZAZa, implf, argl_decl, argl);        \
      |    ^~~~~~~~
etc

EXPECTED RESULT
Compile succeeds 

SOFTWARE/OS VERSIONS
Windows: -
macOS: -
Linux/KDE Plasma: poky linux
(available in About System)
KDE Plasma Version: -
KDE Frameworks Version: -
Qt Version: -

ADDITIONAL INFORMATION
I am happy to submit a patch to the project; alas I am having trouble finding instructions on how to do so.
Comment 1 Bart Van Assche 2020-10-21 02:50:20 UTC
Does the following patch help?


diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c
index 62c466f508ad..585aafe22e41 100644
--- a/drd/drd_pthread_intercepts.c
+++ b/drd/drd_pthread_intercepts.c
@@ -174,6 +174,13 @@ static int never_true;
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl            \
    { return implf argl; }
 #else
+#ifdef MUSL_LIBC
+/* musl provides a single library that includes pthreads functions. */
+#define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl)                    \
+   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl;     \
+   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
+   { return implf argl; }
+#else
 /*
  * On Linux, intercept both the libc and the libpthread functions. At
  * least glibc 2.32.9000 (Fedora 34) has an implementation of all pthread
@@ -188,6 +195,7 @@ static int never_true;
    ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
    { return implf argl; }
 #endif
+#endif
 
 /**
  * Macro for generating three Valgrind interception functions: one with the
Comment 2 Stacy 2020-10-21 14:36:18 UTC
(In reply to Bart Van Assche from comment #1)
> Does the following patch help?
> 
> 
> diff --git a/drd/drd_pthread_intercepts.c b/drd/drd_pthread_intercepts.c
> index 62c466f508ad..585aafe22e41 100644
> --- a/drd/drd_pthread_intercepts.c
> +++ b/drd/drd_pthread_intercepts.c
> @@ -174,6 +174,13 @@ static int never_true;
>     ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBC_SONAME,zf) argl_decl            \
>     { return implf argl; }
>  #else
> +#ifdef MUSL_LIBC
> +/* musl provides a single library that includes pthreads functions. */
> +#define PTH_FUNC(ret_ty, zf, implf, argl_decl, argl)                    \
> +   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl;     \
> +   ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
> +   { return implf argl; }
> +#else
>  /*
>   * On Linux, intercept both the libc and the libpthread functions. At
>   * least glibc 2.32.9000 (Fedora 34) has an implementation of all pthread
> @@ -188,6 +195,7 @@ static int never_true;
>     ret_ty VG_WRAP_FUNCTION_ZZ(VG_Z_LIBPTHREAD_SONAME,zf) argl_decl      \
>     { return implf argl; }
>  #endif
> +#endif
>  
>  /**
>   * Macro for generating three Valgrind interception functions: one with the

Yes it does; thank you.
Comment 3 Bart Van Assche 2020-10-22 00:34:50 UTC
Thanks for confirming!