[PATCH v10 2/4] Add rseq extensible ABI support
Florian Weimer
fweimer@redhat.com
Mon Jul 1 08:32:18 GMT 2024
* Michael Jeanson:
> diff --git a/csu/libc-tls.c b/csu/libc-tls.c
> index b7682bdf43..f73d0e1c52 100644
> --- a/csu/libc-tls.c
> +++ b/csu/libc-tls.c
> @@ -110,6 +124,7 @@ __libc_setup_tls (void)
> size_t filesz = 0;
> void *initimage = NULL;
> size_t align = 0;
> + size_t tls_blocks_size = 0;
> size_t max_align = TCB_ALIGNMENT;
> size_t tcb_offset;
> const ElfW(Phdr) *phdr;
> @@ -135,22 +150,79 @@ __libc_setup_tls (void)
> /* Calculate the size of the static TLS surplus, with 0 auditors. */
> _dl_tls_static_surplus_init (0);
>
> + /* Even when disabled by tunable, an rseq area will be allocated to allow
> + application code to test the registration status with 'rseq->cpud_id >= 0'.
> + Default to the rseq ABI minimum size and alignment, this will ensure we
> + don't use more TLS than necessary. */
> + size_t rseq_alloc_size = TLS_DL_RSEQ_MIN_SIZE;
> + size_t rseq_align = TLS_DL_RSEQ_MIN_ALIGN;
> + bool do_rseq = true;
> + do_rseq = TUNABLE_GET_FULL (glibc, pthread, rseq, int, NULL);
This breaks the Hurd build because it does not have rseq at all.
> diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
> index 50f58a60e3..c8bd39ddcf 100644
> --- a/sysdeps/generic/ldsodefs.h
> +++ b/sysdeps/generic/ldsodefs.h
> @@ -610,6 +610,18 @@ struct rtld_global_ro
> See comments in elf/dl-tls.c where it is initialized. */
> EXTERN size_t _dl_tls_static_surplus;
>
> + /* Size of the features present in the rseq area. */
> + EXTERN size_t _dl_tls_rseq_feature_size;
> +
> + /* Alignment requirement of the rseq area. */
> + EXTERN size_t _dl_tls_rseq_align;
> +
> + /* Size of the rseq area allocated in the static TLS block. */
> + EXTERN size_t _dl_tls_rseq_alloc_size;
> +
> + /* Offset of the rseq area from the thread pointer. */
> + EXTERN ptrdiff_t _dl_tls_rseq_offset;
> +
Why is it necessary to duplicate these variables? Is not a duplicate
and I assume it looks like the it's now used for TLS allocation on new
threads, which means it's needed. Is it necessary to add it to GLRO?
The __rtld_static_init changes would only be needed if support
pthread_create from the inner libc after static dlopen, but that's not
really the case today.
> diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h
> index 48eebc1e16..4123072274 100644
> --- a/sysdeps/unix/sysv/linux/rseq-internal.h
> +++ b/sysdeps/unix/sysv/linux/rseq-internal.h
> @@ -24,6 +24,24 @@
> #include <stdbool.h>
> #include <stdio.h>
> #include <sys/rseq.h>
> +#include <thread_pointer.h>
> +#include <ldsodefs.h>
> +
> +/* rseq area registered with the kernel. Use a custom definition
> + here to isolate from kernel struct rseq changes. The
> + implementation of sched_getcpu needs acccess to the cpu_id field;
> + the other fields are unused and not included here. */
> +struct rseq_area
> +{
> + uint32_t cpu_id_start;
> + uint32_t cpu_id;
> +};
> +
> +static inline struct rseq_area *
> +rseq_get_area(void)
> +{
> + return (struct rseq_area *) ((char *) __thread_pointer() + GLRO (dl_tls_rseq_offset));
> +}
>
> #ifdef RSEQ_SIG
Line is longer than 79 characters. The new inline function must be in
the #ifdef RSEQ_SIG block because __thread_pointer is currently only
available on targets with RSEQ_SIG. It's missing on SPARC, for example.
Thanks,
Florian
More information about the Libc-alpha
mailing list