From: Carlos O'Donell <carlos@redhat.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
libc-alpha@sourceware.org
Subject: Re: [PATCH v5 07/13] string: Use tls-internal on strerror_l
Date: Thu, 2 Jul 2020 15:48:42 -0400 [thread overview]
Message-ID: <b89052ef-b653-c1ca-c2ce-4c8ccd65e060@redhat.com> (raw)
In-Reply-To: <20200619134352.297146-7-adhemerval.zanella@linaro.org>
On 6/19/20 9:43 AM, Adhemerval Zanella wrote:
> The buffer allocation uses the same strategy of strsignal.
>
> Checked on x86-64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu,
> and s390x-linux-gnu.
OK for master.
No regressions on x86_64 and i686.
Tested-by: Carlos O'Donell <carlos@redhat.com>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> include/string.h | 3 ---
> malloc/thread-freeres.c | 1 -
> string/strerror_l.c | 21 +++++------------
> sysdeps/generic/tls-internal-struct.h | 1 +
> sysdeps/generic/tls-internal.h | 1 +
> sysdeps/mach/strerror_l.c | 32 +++++++++-----------------
> sysdeps/unix/sysv/linux/tls-internal.h | 1 +
> 7 files changed, 20 insertions(+), 40 deletions(-)
>
> diff --git a/include/string.h b/include/string.h
> index 3a33327cc0..ce01ad8254 100644
> --- a/include/string.h
> +++ b/include/string.h
> @@ -53,9 +53,6 @@ extern char *__strerror_r (int __errnum, char *__buf, size_t __buflen);
>
> extern char *__strerror_l (int __errnum, locale_t __loc);
>
> -/* Called as part of the thread shutdown sequence. */
> -void __strerror_thread_freeres (void) attribute_hidden;
> -
OK.
> /* Get _STRING_ARCH_unaligned. */
> #include <string_private.h>
> #endif
> diff --git a/malloc/thread-freeres.c b/malloc/thread-freeres.c
> index 3408bdbefd..eb29d53310 100644
> --- a/malloc/thread-freeres.c
> +++ b/malloc/thread-freeres.c
> @@ -32,7 +32,6 @@ __libc_thread_freeres (void)
> {
> call_function_static_weak (__rpc_thread_destroy);
> call_function_static_weak (__res_thread_freeres);
> - call_function_static_weak (__strerror_thread_freeres);
OK.
> __glibc_tls_internal_free ();
>
> /* This should come last because it shuts down malloc for this
> diff --git a/string/strerror_l.c b/string/strerror_l.c
> index 017bd14b99..a203e9e80b 100644
> --- a/string/strerror_l.c
> +++ b/string/strerror_l.c
> @@ -18,11 +18,8 @@
> #include <libintl.h>
> #include <locale.h>
> #include <stdio.h>
> -#include <stdlib.h>
> #include <string.h>
> -#include <errno.h>
> -
> -static __thread char *last_value;
> +#include <tls-internal.h>
>
>
> static const char *
> @@ -43,12 +40,13 @@ __strerror_l (int errnum, locale_t loc)
> char *err = (char *) __get_errlist (errnum);
> if (__glibc_unlikely (err == NULL))
> {
> - free (last_value);
> - if (__asprintf (&last_value, "%s%d",
> + struct tls_internal_t *tls_internal = __glibc_tls_internal ();
> + free (tls_internal->strerror_l_buf);
> + if (__asprintf (&tls_internal->strerror_l_buf, "%s%d",
> translate ("Unknown error ", loc), errnum) == -1)
> - last_value = NULL;
> + tls_internal->strerror_l_buf = NULL;
>
> - err = last_value;
> + err = tls_internal->strerror_l_buf;
OK.
> }
> else
> err = (char *) translate (err, loc);
> @@ -58,10 +56,3 @@ __strerror_l (int errnum, locale_t loc)
> }
> weak_alias (__strerror_l, strerror_l)
> libc_hidden_def (__strerror_l)
> -
> -void
> -__strerror_thread_freeres (void)
> -{
> - free (last_value);
> -}
> -text_set_element (__libc_subfreeres, __strerror_thread_freeres);
OK.
> diff --git a/sysdeps/generic/tls-internal-struct.h b/sysdeps/generic/tls-internal-struct.h
> index 33a9079ee9..156e722bd8 100644
> --- a/sysdeps/generic/tls-internal-struct.h
> +++ b/sysdeps/generic/tls-internal-struct.h
> @@ -22,6 +22,7 @@
> struct tls_internal_t
> {
> char *strsignal_buf;
> + char *strerror_l_buf;
> };
>
> #endif
> diff --git a/sysdeps/generic/tls-internal.h b/sysdeps/generic/tls-internal.h
> index 1f6a117d76..b4b03b4ecf 100644
> --- a/sysdeps/generic/tls-internal.h
> +++ b/sysdeps/generic/tls-internal.h
> @@ -34,6 +34,7 @@ static inline void
> __glibc_tls_internal_free (void)
> {
> free (__tls_internal.strsignal_buf);
> + free (__tls_internal.strerror_l_buf);
OK. Perfect! Use the same framework.
> }
>
> #endif
> diff --git a/sysdeps/mach/strerror_l.c b/sysdeps/mach/strerror_l.c
> index b6c9fdbe80..72b857f4a0 100644
> --- a/sysdeps/mach/strerror_l.c
> +++ b/sysdeps/mach/strerror_l.c
> @@ -23,11 +23,7 @@
> #include <string.h>
> #include <mach/error.h>
> #include <errorlib.h>
> -#include <sys/param.h>
> -#include <libc-symbols.h>
> -
> -
> -static __thread char *last_value;
> +#include <tls-internal.h>
>
>
> static const char *
> @@ -58,13 +54,14 @@ __strerror_l (int errnum, locale_t loc)
>
> if (system > err_max_system || ! __mach_error_systems[system].bad_sub)
> {
> - free (last_value);
> - if (__asprintf (&last_value, "%s%X",
> + struct tls_internal_t *tls_internal = __glibc_tls_internal ();
> + free (tls_internal->strerror_l_buf);
> + if (__asprintf (&tls_internal->strerror_l_buf, "%s%X",
> translate ("Error in unknown error system: ", loc),
> errnum) == -1)
> - last_value = NULL;
> + tls_internal->strerror_l_buf = NULL;
>
> - return last_value;
> + return tls_internal->strerror_l_buf;
> }
>
> es = &__mach_error_systems[system];
> @@ -74,25 +71,18 @@ __strerror_l (int errnum, locale_t loc)
>
> if (code >= es->subsystem[sub].max_code)
> {
> - free (last_value);
> - if (__asprintf (&last_value, "%s%s %d",
> + struct tls_internal_t *tls_internal = __glibc_tls_internal ();
> + free (tls_internal->strerror_l_buf);
> + if (__asprintf (&tls_internal->strerror_l_buf, "%s%s %d",
> translate ("Unknown error ", loc),
> translate (es->subsystem[sub].subsys_name, loc),
> errnum) == -1)
> - last_value = NULL;
> + tls_internal->strerror_l_buf = NULL;
>
> - return last_value;
> + return tls_internal->strerror_l_buf;
> }
>
> return (char *) translate (es->subsystem[sub].codes[code], loc);
> }
> weak_alias (__strerror_l, strerror_l)
> libc_hidden_def (__strerror_l)
> -
> -/* This is called when a thread is exiting to free the last_value string. */
> -void
> -__strerror_thread_freeres (void)
> -{
> - free (last_value);
> -}
> -text_set_element (__libc_subfreeres, __strerror_thread_freeres);
OK.
> diff --git a/sysdeps/unix/sysv/linux/tls-internal.h b/sysdeps/unix/sysv/linux/tls-internal.h
> index 5d712abd4a..d07f4b680d 100644
> --- a/sysdeps/unix/sysv/linux/tls-internal.h
> +++ b/sysdeps/unix/sysv/linux/tls-internal.h
> @@ -32,6 +32,7 @@ static inline void
> __glibc_tls_internal_free (void)
> {
> free (THREAD_SELF->tls_state.strsignal_buf);
> + free (THREAD_SELF->tls_state.strerror_l_buf);
OK.
> }
>
> #endif
>
--
Cheers,
Carlos.
next prev parent reply other threads:[~2020-07-02 19:48 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-19 13:43 [PATCH v5 01/13] signal: Add signum-{generic,arch}.h Adhemerval Zanella
2020-06-19 13:43 ` [PATCH v5 02/13] signal: Move sys_siglist to a compat symbol Adhemerval Zanella
2020-07-02 18:32 ` Carlos O'Donell
2020-07-03 17:58 ` Adhemerval Zanella
2020-06-19 13:43 ` [PATCH v5 03/13] signal: Move sys_errlist " Adhemerval Zanella
2020-07-02 18:48 ` Carlos O'Donell
2020-07-03 19:17 ` Adhemerval Zanella
2020-06-19 13:43 ` [PATCH v5 04/13] linux: Fix __NSIG_WORDS and add __NSIG_BYTES Adhemerval Zanella
2020-07-02 19:08 ` Carlos O'Donell
2020-07-03 19:23 ` Adhemerval Zanella
2020-06-19 13:43 ` [PATCH v5 05/13] string: Remove old TLS usage on strsignal Adhemerval Zanella
2020-07-02 19:32 ` Carlos O'Donell
2020-07-03 19:26 ` Adhemerval Zanella
2020-06-19 13:43 ` [PATCH v5 06/13] string: Implement strerror in terms of strerror_l Adhemerval Zanella
2020-07-02 19:44 ` Carlos O'Donell
2020-07-03 19:53 ` Adhemerval Zanella
2020-06-19 13:43 ` [PATCH v5 07/13] string: Use tls-internal on strerror_l Adhemerval Zanella
2020-07-02 19:48 ` Carlos O'Donell [this message]
2020-06-19 13:43 ` [PATCH v5 08/13] string: Simplify strerror_r Adhemerval Zanella
2020-07-02 19:51 ` Carlos O'Donell
2020-06-19 13:43 ` [PATCH v5 09/13] string: Add strsignal test Adhemerval Zanella
2020-07-02 19:55 ` Carlos O'Donell
2020-07-02 20:01 ` Carlos O'Donell
2020-07-03 20:06 ` Adhemerval Zanella
2020-06-19 13:43 ` [PATCH v5 10/13] string: Add strerror, strerror_r, and strerror_l test Adhemerval Zanella
2020-07-02 20:02 ` Carlos O'Donell
2020-06-19 13:43 ` [PATCH v5 11/13] string: Add strerror_l on test-strerror-errno Adhemerval Zanella
2020-07-02 20:05 ` Carlos O'Donell
2020-06-19 13:43 ` [PATCH v5 12/13] string: Add sigabbrev_np and sigdescr_np Adhemerval Zanella
2020-07-02 21:13 ` Carlos O'Donell
2020-07-03 20:23 ` Adhemerval Zanella
[not found] ` <VI1PR08MB532546AD22FA628741788C5BFF670@VI1PR08MB5325.eurprd08.prod.outlook.com>
2020-07-08 11:18 ` Tamar Christina
2020-07-08 11:36 ` Florian Weimer
2020-07-08 11:48 ` Tamar Christina
2020-07-08 11:52 ` Florian Weimer
2020-07-08 12:16 ` Tamar Christina
2020-07-08 12:23 ` Adhemerval Zanella
2020-06-19 13:43 ` [PATCH v5 13/13] string: Add strerrorname and strerrordesc Adhemerval Zanella
2020-07-02 21:43 ` Carlos O'Donell
2020-07-03 21:01 ` Adhemerval Zanella
2020-07-03 21:19 ` Carlos O'Donell
2020-07-03 22:34 ` Adhemerval Zanella
2020-07-06 12:43 ` Carlos O'Donell
2020-07-06 13:57 ` [PATCH v6] string: Add strerrorname_np and strerrordesc_np Adhemerval Zanella
2020-07-06 14:04 ` Andreas Schwab
2020-07-06 14:06 ` Adhemerval Zanella
2020-07-06 15:07 ` Carlos O'Donell
2020-07-02 18:26 ` [PATCH v5 01/13] signal: Add signum-{generic,arch}.h Carlos O'Donell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b89052ef-b653-c1ca-c2ce-4c8ccd65e060@redhat.com \
--to=carlos@redhat.com \
--cc=adhemerval.zanella@linaro.org \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).