From patchwork Fri Jun 19 13:43:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 1312929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=sourceware.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=Bx1+3ntf; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49pKmL6TKyz9sSf for ; Fri, 19 Jun 2020 23:44:34 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5993D393C8B2; Fri, 19 Jun 2020 13:44:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5993D393C8B2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1592574251; bh=s1NsXvkyE5mV/8GuzkH7/KorPh4TCXE7ECM2WjZ8ccc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Bx1+3ntfX4+doDg2q9BLZYMj+AcLXSRWketHWGlaVFxOdKK17t+kisD+dcISbTJxv mvEoCjpL5B8Ma7fc309Tv2quEtJaNumfqdEIBJFZKZ2D5aLMDU2yYocmV8KDqO/RUS gFrQ0JS5nJ3KEF3fPqxwJuDqv/kkDrWi+sX2zogs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-qt1-x843.google.com (mail-qt1-x843.google.com [IPv6:2607:f8b0:4864:20::843]) by sourceware.org (Postfix) with ESMTPS id 2410C3938C3B for ; Fri, 19 Jun 2020 13:44:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2410C3938C3B Received: by mail-qt1-x843.google.com with SMTP id w90so7166592qtd.8 for ; Fri, 19 Jun 2020 06:44:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s1NsXvkyE5mV/8GuzkH7/KorPh4TCXE7ECM2WjZ8ccc=; b=qfurEoYce8q07tlUXjomhzptKzK4sAsfLvcUclzzHYhAdmmSHeZPufTbM/UnFihhch QsKQa6O2na1krE8U69+EUYLVlSWh4wzoaWNF4YCMgEJizJwf6aNdi+2EtjJfUiwwWVgr ZAXnksSV6wK/mby3/GuhSgW7numZ8j3xh9RwoE/+afAwFXEE2qhXwZe2Fe0QV3Xl403Y AW/CpHx1Lc1qStLYJzuglEI6gCZGu9hiimqbNWcfXY3qp8JrlUwEkRvsjuobC5KV6owt fYPwdHWyf9wsorcsL8zwjMNUW0xBIUFTl7/hTfw1Aca/NOY7FJbAzAdYMUgG4Cy9r1r5 +/9A== X-Gm-Message-State: AOAM533jmnDcdiTmHuzkNg//u1FYJjLKpUNyzCwtToG0yLEKl9pOBqz6 qRCp+gBnVK7PWT5WafHLEUvDx86J5i8= X-Google-Smtp-Source: ABdhPJxeKaJ1Scu8y2WJO42vXfizbzOPliQWuFvsojhv5Ulh2k8ufibZphUtwTUg6El4mWlMtlNDoA== X-Received: by 2002:aed:235b:: with SMTP id i27mr3304751qtc.356.1592574248430; Fri, 19 Jun 2020 06:44:08 -0700 (PDT) Received: from localhost.localdomain ([177.194.48.209]) by smtp.googlemail.com with ESMTPSA id p203sm6379435qke.132.2020.06.19.06.44.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Jun 2020 06:44:08 -0700 (PDT) To: libc-alpha@sourceware.org Subject: [PATCH v5 07/13] string: Use tls-internal on strerror_l Date: Fri, 19 Jun 2020 10:43:46 -0300 Message-Id: <20200619134352.297146-7-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200619134352.297146-1-adhemerval.zanella@linaro.org> References: <20200619134352.297146-1-adhemerval.zanella@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, 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-Patchwork-Original-From: Adhemerval Zanella via Libc-alpha From: Adhemerval Zanella Reply-To: Adhemerval Zanella Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. Tested-by: Carlos O'Donell Reviewed-by: Carlos O'Donell --- 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; - /* Get _STRING_ARCH_unaligned. */ #include #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); __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 #include #include -#include #include -#include - -static __thread char *last_value; +#include 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; } 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); 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); } #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 #include #include -#include -#include - - -static __thread char *last_value; +#include 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); 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); } #endif