From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 054393951843 for ; Sun, 9 May 2021 21:42:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 054393951843 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-482-c2-NQrwbOTmjlCepzdnZyQ-1; Sun, 09 May 2021 17:42:17 -0400 X-MC-Unique: c2-NQrwbOTmjlCepzdnZyQ-1 Received: by mail-qk1-f199.google.com with SMTP id g2-20020a37b6020000b02902ea40e87ecbso10126287qkf.14 for ; Sun, 09 May 2021 14:42:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:organization :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=GOT/b8NKdbWnDc04714vWpMZZ3Pz7vWa5T28xlVo8CM=; b=Y54UCYpTJ8iKMOtXxC7nF5kYxlzk0UvG53Z5vsoOCGYCdHkSyM/W/OAKDIg82nslQZ FrtaoJZ7X75ngbIdN0wZ60QLC8pQo6PBfzPAmDyRGYEbZamA2suc30B9aXP+F6BMhtE8 Yb7853cGFlAnmw/alX4nwCyAJRqPq54FoqHd5Rt9JZLR7Ftsiwe4hqpkB6m2yPlC1pRD Rw65hXzpFuwzKFkpS1ibRxGOxiCMQwjkvCssgVIzwdRvIEEKh6XJhuRux16IL7k59Ou4 slswSF7mYtFuEcF8r1V/oxr1/TEjI5XiQpcMq8+k2VIHtRMqBiaOf/2oZa6M0V0T0TAw nXig== X-Gm-Message-State: AOAM533aNp8KgabgszHWNumS2NAVffXuzmHHIVBtht/BvrnQ+XkQYYTr 6pd4rFRzgelcKQgG2LEIIYgYbvHCOmTXCty9fzV7h3U8Gvpv0MfwRzCiYWN9gbdE+0LSaCzSEMU epJ2qDjvwo4bOZOcB/dPEJadfyf4pez7Yr6yJ4kqBSPfP6RlM5yjP6UHFp+/Dy2BVBbek4Q== X-Received: by 2002:a05:620a:7ec:: with SMTP id k12mr20272471qkk.170.1620596536180; Sun, 09 May 2021 14:42:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrT7lDyfBLLuvL5h1M6bH3qMRyLWCBGQZp+npo7XSNp6RkNZKeTp+JPDXaj6EgnUaemUPxWA== X-Received: by 2002:a05:620a:7ec:: with SMTP id k12mr20272461qkk.170.1620596535904; Sun, 09 May 2021 14:42:15 -0700 (PDT) Received: from [192.168.1.16] (198-84-214-74.cpe.teksavvy.com. [198.84.214.74]) by smtp.gmail.com with ESMTPSA id 7sm5609364qkd.20.2021.05.09.14.42.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 09 May 2021 14:42:15 -0700 (PDT) Subject: Re: [PATCH 07/13] elf: Introduce __tls_pre_init_tp To: Florian Weimer , libc-alpha@sourceware.org References: <34f3a445c6c083b135bef0e147ebf994082bcb42.1620323953.git.fweimer@redhat.com> From: Carlos O'Donell Organization: Red Hat Message-ID: <70c8a2aa-6c1a-6dd7-638a-40da2941233b@redhat.com> Date: Sun, 9 May 2021 17:42:14 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <34f3a445c6c083b135bef0e147ebf994082bcb42.1620323953.git.fweimer@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 May 2021 21:42:20 -0000 On 5/6/21 2:10 PM, Florian Weimer via Libc-alpha wrote: > This is an early variant of __tls_init_tp, primarily for initializing > thread-related elements of _rtld_global/GL. > > Some existing initialization code not needed for NPTL is moved into > the generic version of this function. LGTM. Tested on x86_64 and i686 without regression. Tested-by: Carlos O'Donell Reviewed-by: Carlos O'Donell > --- > csu/libc-tls.c | 2 ++ > elf/dl-mutex.c | 2 +- > elf/dl-tls_init_tp.c | 29 ++++++++++++++++++++++++++ > elf/rtld.c | 38 +---------------------------------- > sysdeps/generic/ldsodefs.h | 4 ++++ > sysdeps/nptl/dl-tls_init_tp.c | 25 +++++++++++++++++++++-- > 6 files changed, 60 insertions(+), 40 deletions(-) > > diff --git a/csu/libc-tls.c b/csu/libc-tls.c > index 22f8e4838d..5515204863 100644 > --- a/csu/libc-tls.c > +++ b/csu/libc-tls.c > @@ -114,6 +114,8 @@ __libc_setup_tls (void) > > struct link_map *main_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded; > > + __tls_pre_init_tp (); > + > /* Look through the TLS segment if there is any. */ > if (_dl_phdr != NULL) > for (phdr = _dl_phdr; phdr < &_dl_phdr[_dl_phnum]; ++phdr) > diff --git a/elf/dl-mutex.c b/elf/dl-mutex.c > index 2cd9d49c2e..ae1d8a84f0 100644 > --- a/elf/dl-mutex.c > +++ b/elf/dl-mutex.c > @@ -16,4 +16,4 @@ > License along with the GNU C Library; if not, see > . */ > > -/* The generic version initialization happpens in dl_main. */ > +/* Initialization happens in __tls_pre_init_tp in dl-tls_init_tp.c. */ > diff --git a/elf/dl-tls_init_tp.c b/elf/dl-tls_init_tp.c > index 728cd84c00..d84adc992c 100644 > --- a/elf/dl-tls_init_tp.c > +++ b/elf/dl-tls_init_tp.c > @@ -18,6 +18,35 @@ > > #include > > +#if defined SHARED && defined _LIBC_REENTRANT \ > + && defined __rtld_lock_default_lock_recursive > +static void > +rtld_lock_default_lock_recursive (void *lock) > +{ > + __rtld_lock_default_lock_recursive (lock); > +} > + > +static void > +rtld_lock_default_unlock_recursive (void *lock) > +{ > + __rtld_lock_default_unlock_recursive (lock); > +} > +#endif > + > +void > +__tls_pre_init_tp (void) > +{ > +#if !THREAD_GSCOPE_IN_TCB > + GL(dl_init_static_tls) = &_dl_nothread_init_static_tls; OK. > +#endif > + > +#if defined SHARED && defined _LIBC_REENTRANT \ > + && defined __rtld_lock_default_lock_recursive > + GL(dl_rtld_lock_recursive) = rtld_lock_default_lock_recursive; > + GL(dl_rtld_unlock_recursive) = rtld_lock_default_unlock_recursive; > +#endif > +} > + > void > __tls_init_tp (void) > { > diff --git a/elf/rtld.c b/elf/rtld.c > index a359167f8a..1255d5cc7d 100644 > --- a/elf/rtld.c > +++ b/elf/rtld.c > @@ -843,30 +843,6 @@ ERROR: ld.so: object '%s' from %s cannot be preloaded (%s): ignored.\n", > return 0; > } > > -#if defined SHARED && defined _LIBC_REENTRANT \ > - && defined __rtld_lock_default_lock_recursive > -static void > -rtld_lock_default_lock_recursive (void *lock) > -{ > - __rtld_lock_default_lock_recursive (lock); > -} > - > -static void > -rtld_lock_default_unlock_recursive (void *lock) > -{ > - __rtld_lock_default_unlock_recursive (lock); > -} > -#endif > -#if PTHREAD_IN_LIBC > -/* Dummy implementation. See __rtld_mutex_init. */ > -static int > -rtld_mutex_dummy (pthread_mutex_t *lock) > -{ > - return 0; > -} > -#endif > - > - > static void > security_init (void) > { > @@ -1147,19 +1123,7 @@ dl_main (const ElfW(Phdr) *phdr, > struct dl_main_state state; > dl_main_state_init (&state); > > -#if !THREAD_GSCOPE_IN_TCB > - GL(dl_init_static_tls) = &_dl_nothread_init_static_tls; > -#endif > - > -#if defined SHARED && defined _LIBC_REENTRANT \ > - && defined __rtld_lock_default_lock_recursive > - GL(dl_rtld_lock_recursive) = rtld_lock_default_lock_recursive; > - GL(dl_rtld_unlock_recursive) = rtld_lock_default_unlock_recursive; > -#endif > -#if PTHREAD_IN_LIBC > - ___rtld_mutex_lock = rtld_mutex_dummy; > - ___rtld_mutex_unlock = rtld_mutex_dummy; > -#endif > + __tls_pre_init_tp (); > > /* The explicit initialization here is cheaper than processing the reloc > in the _rtld_local definition's initializer. */ > diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h > index 6d590d1335..ee851ac789 100644 > --- a/sysdeps/generic/ldsodefs.h > +++ b/sysdeps/generic/ldsodefs.h > @@ -1165,6 +1165,10 @@ extern void _dl_determine_tlsoffset (void) attribute_hidden; > number of audit modules are loaded. */ > void _dl_tls_static_surplus_init (size_t naudit) attribute_hidden; > > +/* This function is called very early from dl_main to set up TLS and > + other thread-related data structures. */ > +void __tls_pre_init_tp (void) attribute_hidden; > + > /* This function is called after processor-specific initialization of > the TCB and thread pointer via TLS_INIT_TP, to complete very early > initialization of the thread library. */ > diff --git a/sysdeps/nptl/dl-tls_init_tp.c b/sysdeps/nptl/dl-tls_init_tp.c > index 05d2b6cfcc..cb29222727 100644 > --- a/sysdeps/nptl/dl-tls_init_tp.c > +++ b/sysdeps/nptl/dl-tls_init_tp.c > @@ -27,12 +27,33 @@ bool __nptl_set_robust_list_avail __attribute__ ((nocommon)); > rtld_hidden_data_def (__nptl_set_robust_list_avail) > #endif > > +#ifdef SHARED > +/* Dummy implementation. See __rtld_mutex_init. */ > +static int > +rtld_mutex_dummy (pthread_mutex_t *lock) > +{ > + return 0; > +} > +#endif > + > void > -__tls_init_tp (void) > +__tls_pre_init_tp (void) > { > - /* Set up thread stack list management. */ > + /* The list data structures are not consistent until > + initialized. */ > INIT_LIST_HEAD (&GL (dl_stack_used)); > INIT_LIST_HEAD (&GL (dl_stack_user)); > + > +#ifdef SHARED > + ___rtld_mutex_lock = rtld_mutex_dummy; > + ___rtld_mutex_unlock = rtld_mutex_dummy; > +#endif > +} > + > +void > +__tls_init_tp (void) > +{ > + /* Set up thread stack list management. */ > list_add (&THREAD_SELF->list, &GL (dl_stack_user)); > > /* Early initialization of the TCB. */ > -- Cheers, Carlos.