[PATCH 1/4] misc: Optimize internal usage of __libc_single_threaded
Florian Weimer
fweimer@redhat.com
Wed Jun 8 17:44:58 GMT 2022
* Adhemerval Zanella via Libc-alpha:
> diff --git a/elf/libc_early_init.c b/elf/libc_early_init.c
> index 3c4a19cf6b..18966900c4 100644
> --- a/elf/libc_early_init.c
> +++ b/elf/libc_early_init.c
> @@ -16,7 +16,9 @@
> License along with the GNU C Library; if not, see
> <https://www.gnu.org/licenses/>. */
>
> +#include <assert.h>
> #include <ctype.h>
> +#include <dlfcn.h>
> #include <elision-conf.h>
> #include <libc-early-init.h>
> #include <libc-internal.h>
> @@ -38,6 +40,13 @@ __libc_early_init (_Bool initial)
> __libc_single_threaded = initial;
>
> #ifdef SHARED
> + /* _libc_single_thread can be accessed through copy relocations, so it
> + requires to update the external copy. */
> + __libc_external_single_threaded = ___dlsym (RTLD_DEFAULT,
> + "__libc_single_threaded");
> + assert (__libc_external_single_threaded != NULL);
> + *__libc_external_single_threaded = initial;
> +
> __libc_initial = initial;
> #endif
Typo in the comment: [_]_libc_single_thread.
You must use __libc_dlsym, to avoid clobbering dlerror. No need to add
___dlsym.
Is it necessary to cache the address?
> diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
> index e7a099acb7..5633d01c62 100644
> --- a/nptl/pthread_create.c
> +++ b/nptl/pthread_create.c
> @@ -627,7 +627,11 @@ __pthread_create_2_1 (pthread_t *newthread, const pthread_attr_t *attr,
> if (__libc_single_threaded)
> {
> late_init ();
> - __libc_single_threaded = 0;
> + __libc_single_threaded =
> +#ifdef SHARED
> + *__libc_external_single_threaded =
> +#endif
> + 0;
> }
>
> const struct pthread_attr *iattr = (struct pthread_attr *) attr;
I think you can call __libc_dlsym here.
Thanks,
Florian
More information about the Libc-alpha
mailing list