From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id 3B22D385BF93 for ; Fri, 18 Feb 2022 16:21:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3B22D385BF93 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy06.your-server.de ([78.46.172.3]) by dedi548.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92.3) (envelope-from ) id 1nL60Z-0006g9-Gt for newlib@sourceware.org; Fri, 18 Feb 2022 17:21:23 +0100 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nL60Z-000XYA-EM for newlib@sourceware.org; Fri, 18 Feb 2022 17:21:23 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 2E41F48007D for ; Fri, 18 Feb 2022 17:21:23 +0100 (CET) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id AOG6i8GKhvEH for ; Fri, 18 Feb 2022 17:21:22 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 799FC4800CC for ; Fri, 18 Feb 2022 17:21:22 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id OHQPCB1eRMso for ; Fri, 18 Feb 2022 17:21:22 +0100 (CET) Received: from [10.10.171.10] (unknown [10.10.171.10]) by mail.embedded-brains.de (Postfix) with ESMTPSA id 3C61248007D for ; Fri, 18 Feb 2022 17:21:22 +0100 (CET) Message-ID: Date: Fri, 18 Feb 2022 17:21:21 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH v2 1/1] Make __sdidinit unused Content-Language: en-US To: newlib@sourceware.org References: <20220218094525.8394-1-matthew.joyce@embedded-brains.de> <20220218094525.8394-2-matthew.joyce@embedded-brains.de> From: Sebastian Huber In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.5/26457/Fri Feb 18 10:25:22 2022) X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, NICE_REPLY_A, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Feb 2022 16:21:27 -0000 Hello Corinna, On 18/02/2022 13:41, Corinna Vinschen wrote: > Hi Matt, >=20 > On Feb 18 10:45, Matthew Joyce wrote: >> Remove dependency on __sdidinit member of struct _reent to check >> object initialization. Like __sdidinit, the __cleanup member of >> struct _reent is initialized in the __sinit() function. Checking >> initialization against __cleanup serves the same purpose and will >> reduce overhead in the __sfp() function in a follow up patch. >=20 > The patch looks right now. But. >=20 > What exactly are you going to do in __sfp? The reason I'm asking is > that it's absolutely not clear yet which purpose this change serves. > Looking at this patch, I only see that, rather than using an available > flag, a pointer is now set to an invalid value -1, which looks more > dangerous than what we did before. >=20 > Care to explain or, even better, send the patch you have in mind? this is related to our attempt to use individual thread-local storage=20 objects instead of the monolithic struct _reent: https://sourceware.org/pipermail/newlib/2022/018855.html It turned out that this is not possible while _GLOBAL_REENT exists.=20 Getting rid of struct _reent members with similar functionality helps to=20 refactor the code. Instead of using -1 as a magic value a safer option would be to assign a=20 dummy function which does nothing: diff --git a/winsup/cygwin/cygtls.cc b/winsup/cygwin/cygtls.cc index 6ce1202ef..c8352adf9 100644 --- a/winsup/cygwin/cygtls.cc +++ b/winsup/cygwin/cygtls.cc @@ -60,9 +60,8 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *,=20 void *)) local_clib._stdin =3D _GLOBAL_REENT->_stdin; local_clib._stdout =3D _GLOBAL_REENT->_stdout; local_clib._stderr =3D _GLOBAL_REENT->_stderr; - local_clib.__cleanup =3D (void (*) (struct _reent *)) - (_GLOBAL_REENT->__cleanup - ? (void *) -1 : NULL); + if (_GLOBAL_REENT->__cleanup) + local_clib.__cleanup =3D _cygtls::cleanup_early; local_clib.__sglue._niobs =3D 3; local_clib.__sglue._iobs =3D &_GLOBAL_REENT->__sf[0]; } @@ -150,6 +149,12 @@ _cygtls::remove (DWORD wait) } } +void +_cygtls::cleanup_early (struct _reent *) +{ + /* Do nothing */ +} + #ifdef __x86_64__ void san::leave () { diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index a2e3676fc..c2c4141bf 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -272,6 +272,7 @@ public: will_wait_for_signal =3D false; } void handle_SIGCONT (); + static void cleanup_early(struct _reent *); private: void __reg3 call2 (DWORD (*) (void *, void *), void *, void *); void remove_pending_sigs (); diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc index 7f26c6304..e757c47ec 100644 --- a/winsup/cygwin/dcrt0.cc +++ b/winsup/cygwin/dcrt0.cc @@ -829,8 +829,8 @@ main_thread_sinit () wrong spot. The input or output buffer will be NULLed and nothing= is read or written in the first stdio function call in the main threa= d. - To fix this issue we set __cleanup to -1 here. */ - _REENT->__cleanup =3D (void (*) (struct _reent *)) -1; + To fix this issue we set __cleanup to _cygtls::cleanup_early here. = */ + _REENT->__cleanup =3D _cygtls::cleanup_early; } /* Take over from libc's crt0.o and start the application. Note the diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc index 21b2dbe46..b7da4d0c7 100644 --- a/winsup/cygwin/thread.cc +++ b/winsup/cygwin/thread.cc @@ -564,7 +564,7 @@ pthread::exit (void *value_ptr) mutex.unlock (); } - if (_my_tls.local_clib.__cleanup =3D=3D (void (*) (struct _reent *)) -= 1) + if (_my_tls.local_clib.__cleanup =3D=3D _cygtls::cleanup_early) _my_tls.local_clib.__cleanup =3D NULL; _reclaim_reent (_REENT); --=20 embedded brains GmbH Herr Sebastian HUBER Dornierstr. 4 82178 Puchheim Germany email: sebastian.huber@embedded-brains.de phone: +49-89-18 94 741 - 16 fax: +49-89-18 94 741 - 08 Registergericht: Amtsgericht M=C3=BCnchen Registernummer: HRB 157899 Vertretungsberechtigte Gesch=C3=A4ftsf=C3=BChrer: Peter Rasmussen, Thomas= D=C3=B6rfler Unsere Datenschutzerkl=C3=A4rung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/