[4/4] htl: move pthread_self into libc

Message ID 20221029120030.1448-5-gfleury@disroot.org
State Superseded
Headers
Series move some htl symbol into libc |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

Guy-Fleury Iteriteka Oct. 29, 2022, noon UTC
  ---
 htl/Makefile                              | 3 +--
 htl/Versions                              | 7 +++----
 htl/forward.c                             | 4 ----
 htl/pt-initialize.c                       | 1 -
 sysdeps/htl/pthread-functions.h           | 2 --
 sysdeps/mach/hurd/i386/libc.abilist       | 1 +
 sysdeps/mach/hurd/i386/libpthread.abilist | 1 -
 7 files changed, 5 insertions(+), 14 deletions(-)
  

Comments

Samuel Thibault Oct. 30, 2022, 9:51 p.m. UTC | #1
Hello,

Florian, could you help us with making sure we are not screwing up with
the functions moves, since you have the experience with nptl?

Guy-Fleury Iteriteka via Libc-alpha, le sam. 29 oct. 2022 13:00:29 +0100, a ecrit:
> --- a/htl/Versions
> +++ b/htl/Versions
> @@ -83,7 +83,7 @@ libpthread {
>      pthread_condattr_getpshared; pthread_condattr_init;
>      pthread_condattr_setclock; pthread_condattr_setpshared;
>  
> -    pthread_create; pthread_detach; pthread_equal; pthread_exit;
> +    pthread_create; pthread_detach; pthread_exit;
>  
>      pthread_getattr_np;
>  

AIUI, we need to add it with the same symbol version in libc?

There is currently a 2.21 version in libc that was added with the
forwarding support, the symbol currently in libpthread is 2.12, so we'd
have to add that version into libc?

Guy-Fleury Iteriteka via Libc-alpha, le sam. 29 oct. 2022 13:00:30 +0100, a ecrit:
> diff --git a/htl/Versions b/htl/Versions
> index 1ef8a6d0..59070181 100644
> --- a/htl/Versions
> +++ b/htl/Versions
> @@ -25,7 +25,9 @@ libc {
>    GLIBC_2.32 {
>      thrd_current; thrd_equal; thrd_sleep; thrd_yield;
>    }
> -
> +  GLIBC_2.36 {
> +    __pthread_self;
> +  }
>    GLIBC_PRIVATE {
>      __libc_alloca_cutoff;
>      __libc_pthread_init;
> @@ -119,9 +121,6 @@ libpthread {
>      pthread_rwlockattr_destroy; pthread_rwlockattr_getpshared;
>      pthread_rwlockattr_init; pthread_rwlockattr_setpshared;
>  
> -    pthread_self;
> -    __pthread_self;
> -
>      pthread_setcancelstate; pthread_setcanceltype;
>      pthread_setconcurrency; pthread_setschedparam;
>      pthread_setschedprio; pthread_setspecific;

And similarly here.

Samuel
  
Florian Weimer Oct. 31, 2022, 7:24 a.m. UTC | #2
* Guy-Fleury Iteriteka via Libc-alpha:

> diff --git a/htl/Versions b/htl/Versions
> index 1ef8a6d0..59070181 100644
> --- a/htl/Versions
> +++ b/htl/Versions
> @@ -25,7 +25,9 @@ libc {
>    GLIBC_2.32 {
>      thrd_current; thrd_equal; thrd_sleep; thrd_yield;
>    }
> -
> +  GLIBC_2.36 {
> +    __pthread_self;
> +  }

This needs to be GLIBC_2.37 now.  I think it also needs to be
pthread_self (the public symbol).

> diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist
> index 26552958..bfa47282 100644
> --- a/sysdeps/mach/hurd/i386/libc.abilist
> +++ b/sysdeps/mach/hurd/i386/libc.abilist
> @@ -29,6 +29,7 @@ GLIBC_2.11 mkostemps64 F
>  GLIBC_2.11 mkstemps F
>  GLIBC_2.11 mkstemps64 F
>  GLIBC_2.12 pthread_equal F
> +GLIBC_2.12 pthread_self F
>  GLIBC_2.13 __fentry__ F
>  GLIBC_2.14 syncfs F
>  GLIBC_2.15 __fdelt_chk F

“GLIBC_2.37 pthread_self” needs to show up there, in addition to the
GLIBC_2.12 version.

What's missing from this change is the construct for setting the
symbol versions, something like:

versioned_symbol (libc, __pthread_self, pthread_self, GLIBC_2_37);
#if OTHER_SHLIB_COMPAT (librt, GLIBC_2_12, GLIBC_2_37)
compat_symbol (libc, __pthread_self, pthread_self, GLIBC_2_12);
#endif

This sets the new symbol version explicitly and provides the old
version as a compatibility symbol.

It may be necessary to introduce a hidden prototype for
__pthread_self, to avoid check-localplt warnings.  You may have to use
libc_hidden_ver and a different name in the C function definition to
work around some symbol management limitations.  Another approach
could use an inline function for pthread_self or __pthread_self, so
that glibc-internal use of the symbol goes away completely.

Use of a __thread variable for ___pthread_self is problematic because
it interferes with dlmopen.  If you use THREAD_GETMEM instead, I
believe you can do away with the conditional check in pthread_self.
  
Guy-Fleury Iteriteka Nov. 1, 2022, 7:19 p.m. UTC | #3
Thanks I will retry this ween'k end

On October 31, 2022 9:24:59 AM GMT+02:00, Florian Weimer <fw@deneb.enyo.de> wrote:
>* Guy-Fleury Iteriteka via Libc-alpha:
>
>> diff --git a/htl/Versions b/htl/Versions
>> index 1ef8a6d0..59070181 100644
>> --- a/htl/Versions
>> +++ b/htl/Versions
>> @@ -25,7 +25,9 @@ libc {
>>    GLIBC_2.32 {
>>      thrd_current; thrd_equal; thrd_sleep; thrd_yield;
>>    }
>> -
>> +  GLIBC_2.36 {
>> +    __pthread_self;
>> +  }
>
>This needs to be GLIBC_2.37 now.  I think it also needs to be
>pthread_self (the public symbol).
>
>> diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist
>> index 26552958..bfa47282 100644
>> --- a/sysdeps/mach/hurd/i386/libc.abilist
>> +++ b/sysdeps/mach/hurd/i386/libc.abilist
>> @@ -29,6 +29,7 @@ GLIBC_2.11 mkostemps64 F
>>  GLIBC_2.11 mkstemps F
>>  GLIBC_2.11 mkstemps64 F
>>  GLIBC_2.12 pthread_equal F
>> +GLIBC_2.12 pthread_self F
>>  GLIBC_2.13 __fentry__ F
>>  GLIBC_2.14 syncfs F
>>  GLIBC_2.15 __fdelt_chk F
>
>“GLIBC_2.37 pthread_self” needs to show up there, in addition to the
>GLIBC_2.12 version.
>
>What's missing from this change is the construct for setting the
>symbol versions, something like:
>
>versioned_symbol (libc, __pthread_self, pthread_self, GLIBC_2_37);
>#if OTHER_SHLIB_COMPAT (librt, GLIBC_2_12, GLIBC_2_37)
>compat_symbol (libc, __pthread_self, pthread_self, GLIBC_2_12);
>#endif
>
>This sets the new symbol version explicitly and provides the old
>version as a compatibility symbol.
>
>It may be necessary to introduce a hidden prototype for
>__pthread_self, to avoid check-localplt warnings.  You may have to use
>libc_hidden_ver and a different name in the C function definition to
>work around some symbol management limitations.  Another approach
>could use an inline function for pthread_self or __pthread_self, so
>that glibc-internal use of the symbol goes away completely.
>
>Use of a __thread variable for ___pthread_self is problematic because
>it interferes with dlmopen.  If you use THREAD_GETMEM instead, I
>believe you can do away with the conditional check in pthread_self.
  

Patch

diff --git a/htl/Makefile b/htl/Makefile
index a7b013ec..57bb22a2 100644
--- a/htl/Makefile
+++ b/htl/Makefile
@@ -51,7 +51,6 @@  libpthread-routines := pt-attr pt-attr-destroy pt-attr-getdetachstate	    \
 	pt-exit								    \
 	pt-initialize							    \
 	pt-join								    \
-	pt-self								    \
 	pt-sigmask							    \
 	pt-spin-inlines							    \
 	pt-cleanup							    \
@@ -164,7 +163,7 @@  headers :=				\
 distribute :=
 
 routines := forward libc_pthread_init alloca_cutoff htlfreeres pt-total \
-	    pt-dep-self pt-equal
+	    pt-dep-self pt-equal pt-self
 shared-only-routines = forward
 
 extra-libs := libpthread
diff --git a/htl/Versions b/htl/Versions
index 1ef8a6d0..59070181 100644
--- a/htl/Versions
+++ b/htl/Versions
@@ -25,7 +25,9 @@  libc {
   GLIBC_2.32 {
     thrd_current; thrd_equal; thrd_sleep; thrd_yield;
   }
-
+  GLIBC_2.36 {
+    __pthread_self;
+  }
   GLIBC_PRIVATE {
     __libc_alloca_cutoff;
     __libc_pthread_init;
@@ -119,9 +121,6 @@  libpthread {
     pthread_rwlockattr_destroy; pthread_rwlockattr_getpshared;
     pthread_rwlockattr_init; pthread_rwlockattr_setpshared;
 
-    pthread_self;
-    __pthread_self;
-
     pthread_setcancelstate; pthread_setcanceltype;
     pthread_setconcurrency; pthread_setschedparam;
     pthread_setschedprio; pthread_setspecific;
diff --git a/htl/forward.c b/htl/forward.c
index d0f775a2..41985f14 100644
--- a/htl/forward.c
+++ b/htl/forward.c
@@ -126,10 +126,6 @@  FORWARD (pthread_mutex_lock, (pthread_mutex_t *mutex), (mutex), 0)
 
 FORWARD (pthread_mutex_unlock, (pthread_mutex_t *mutex), (mutex), 0)
 
-
-FORWARD2 (pthread_self, pthread_t, (void), (), return 0)
-
-
 FORWARD (__pthread_setcancelstate, (int state, int *oldstate),
 	 (state, oldstate), 0)
 strong_alias (__pthread_setcancelstate, pthread_setcancelstate);
diff --git a/htl/pt-initialize.c b/htl/pt-initialize.c
index 1d948c40..225736fe 100644
--- a/htl/pt-initialize.c
+++ b/htl/pt-initialize.c
@@ -55,7 +55,6 @@  static const struct pthread_functions pthread_functions = {
   .ptr_pthread_mutex_lock = __pthread_mutex_lock,
   .ptr_pthread_mutex_trylock = __pthread_mutex_trylock,
   .ptr_pthread_mutex_unlock = __pthread_mutex_unlock,
-  .ptr_pthread_self = __pthread_self,
   .ptr___pthread_setcancelstate = __pthread_setcancelstate,
   .ptr_pthread_setcanceltype = __pthread_setcanceltype,
   .ptr___pthread_get_cleanup_stack = __pthread_get_cleanup_stack,
diff --git a/sysdeps/htl/pthread-functions.h b/sysdeps/htl/pthread-functions.h
index 095a61e6..4d9896ea 100644
--- a/sysdeps/htl/pthread-functions.h
+++ b/sysdeps/htl/pthread-functions.h
@@ -55,7 +55,6 @@  int _pthread_mutex_init (pthread_mutex_t *,
 int __pthread_mutex_lock (pthread_mutex_t *);
 int __pthread_mutex_trylock (pthread_mutex_t *);
 int __pthread_mutex_unlock (pthread_mutex_t *);
-pthread_t __pthread_self (void);
 int __pthread_setcancelstate (int, int *);
 int __pthread_setcanceltype (int, int *);
 struct __pthread_cancelation_handler **__pthread_get_cleanup_stack (void);
@@ -110,7 +109,6 @@  struct pthread_functions
   int (*ptr_pthread_mutex_lock) (pthread_mutex_t *);
   int (*ptr_pthread_mutex_trylock) (pthread_mutex_t *);
   int (*ptr_pthread_mutex_unlock) (pthread_mutex_t *);
-  pthread_t (*ptr_pthread_self) (void);
   int (*ptr___pthread_setcancelstate) (int, int *);
   int (*ptr_pthread_setcanceltype) (int, int *);
   struct __pthread_cancelation_handler **(*ptr___pthread_get_cleanup_stack) (void);
diff --git a/sysdeps/mach/hurd/i386/libc.abilist b/sysdeps/mach/hurd/i386/libc.abilist
index 26552958..bfa47282 100644
--- a/sysdeps/mach/hurd/i386/libc.abilist
+++ b/sysdeps/mach/hurd/i386/libc.abilist
@@ -29,6 +29,7 @@  GLIBC_2.11 mkostemps64 F
 GLIBC_2.11 mkstemps F
 GLIBC_2.11 mkstemps64 F
 GLIBC_2.12 pthread_equal F
+GLIBC_2.12 pthread_self F
 GLIBC_2.13 __fentry__ F
 GLIBC_2.14 syncfs F
 GLIBC_2.15 __fdelt_chk F
diff --git a/sysdeps/mach/hurd/i386/libpthread.abilist b/sysdeps/mach/hurd/i386/libpthread.abilist
index 84f2643b..d15ba070 100644
--- a/sysdeps/mach/hurd/i386/libpthread.abilist
+++ b/sysdeps/mach/hurd/i386/libpthread.abilist
@@ -108,7 +108,6 @@  GLIBC_2.12 pthread_rwlockattr_destroy F
 GLIBC_2.12 pthread_rwlockattr_getpshared F
 GLIBC_2.12 pthread_rwlockattr_init F
 GLIBC_2.12 pthread_rwlockattr_setpshared F
-GLIBC_2.12 pthread_self F
 GLIBC_2.12 pthread_setcancelstate F
 GLIBC_2.12 pthread_setcanceltype F
 GLIBC_2.12 pthread_setconcurrency F