From patchwork Sat Aug 30 19:19:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Cercueil X-Patchwork-Id: 119213 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C34B63858D29 for ; Sat, 30 Aug 2025 19:19:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C34B63858D29 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=crapouillou.net header.i=@crapouillou.net header.a=rsa-sha256 header.s=mail header.b=UxdJE++q X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from aposti.net (aposti.net [185.119.170.32]) by sourceware.org (Postfix) with ESMTPS id 2BBA03858D29 for ; Sat, 30 Aug 2025 19:19:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2BBA03858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=crapouillou.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=crapouillou.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2BBA03858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=185.119.170.32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756581557; cv=none; b=alpJX1WYC5WinCdtsb2DhX8ZPcDyIpX56r/fSftYrK16QvAPiV4FwMSVDgjAQT9jd09G6lqLZ6L9Ixd1l77+irNVLQ5KMP/yE+veyliMI463kDPUzsxBlbDPZ8QskrPJFmaEhI2Hytr1UrkK19iPVZC4H+qHVG68eEPIYIT0iY4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1756581557; c=relaxed/simple; bh=2NJqhAr7wpZxOE3/d35B5wgBcS6SYLnxiQKdhREK47I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=I9jpkVR/MRR4ipp/WLpppL4+LVtActniUAW1Gs07m/jja76CiiA3wIWkQ2jXdWvVfNx+4Sh+5uD+UvQ9TaEMj+CeMvksVQbPHhvgS0qiadbYmFXdk2BhTI4QOM7Z35yK823el8bdM6W0xPBLjiDzdD5wa+wW9GMNlmOlpavnzN4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BBA03858D29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1756581555; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=P5y7QY/SkGl+vp4cCrHN0IhBGkl+Dsp/bvOHYS6n87g=; b=UxdJE++qOplEzeh6u2UEL9Fx37GUUjEB3eed1Mu7YC0I01e/NeaK9IN+9ycIbj35QA8m7f JYcVqM+a3oqOL/+mC3/KlgEzuh+XKldLd5xursapcxKMg8QJLDASDRL02ielKn/mPwohFv Eo7xcKsEV0ksz2qf3Rfcb+5AaYIXFI4= From: Paul Cercueil To: newlib@sourceware.org Cc: Paul Cercueil Subject: [PATCH] newlib: Simplify errno access Date: Sat, 30 Aug 2025 21:19:08 +0200 Message-ID: <20250830191908.450705-1-paul@crapouillou.net> MIME-Version: 1.0 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org I see no reason why every single errno access (read or write) should trigger a function call to just return an offset into the reent struct. This seems to have been needed in the past, but it does not seem to be needed anymore. Drop the __errno() function, and set the 'errno' macro to point to the corresponding offset into the _reent struct. Signed-off-by: Paul Cercueil --- newlib/libc/errno/errno.c | 12 ------------ newlib/libc/include/sys/errno.h | 6 ++---- newlib/libc/machine/cris/sys/errno.h | 6 ++---- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/newlib/libc/errno/errno.c b/newlib/libc/errno/errno.c index 384b07f2c..22e8087dc 100644 --- a/newlib/libc/errno/errno.c +++ b/newlib/libc/errno/errno.c @@ -7,16 +7,4 @@ #ifdef _REENT_THREAD_LOCAL _Thread_local int _tls_errno; -#else /* !_REENT_THREAD_LOCAL */ - -#ifndef _REENT_ONLY - -int * -__errno () -{ - return &_REENT_ERRNO(_REENT); -} - -#endif - #endif /* _REENT_THREAD_LOCAL */ diff --git a/newlib/libc/include/sys/errno.h b/newlib/libc/include/sys/errno.h index 7199db0d2..a9610eb78 100644 --- a/newlib/libc/include/sys/errno.h +++ b/newlib/libc/include/sys/errno.h @@ -1,6 +1,5 @@ /* errno is not a global variable, because that would make using it - non-reentrant. Instead, its address is returned by the function - __errno. */ + non-reentrant. Instead, it is an offset into the _reent struct. */ #ifndef _SYS_ERRNO_H_ #ifdef __cplusplus @@ -15,8 +14,7 @@ extern "C" { #else /* _REENT_THREAD_LOCAL */ #ifndef _REENT_ONLY -#define errno (*__errno()) -extern int *__errno (void); +#define errno _REENT_ERRNO(_REENT) #endif #endif /* _REENT_THREAD_LOCAL */ diff --git a/newlib/libc/machine/cris/sys/errno.h b/newlib/libc/machine/cris/sys/errno.h index c8113ed73..ffd5c529d 100644 --- a/newlib/libc/machine/cris/sys/errno.h +++ b/newlib/libc/machine/cris/sys/errno.h @@ -3,8 +3,7 @@ be those of the Linux/CRIS kernel. */ /* errno is not a global variable, because that would make using it - non-reentrant. Instead, its address is returned by the function - __errno. */ + non-reentrant. Instead, it is an offset into the _reent struct. */ #ifndef _SYS_ERRNO_H_ #ifdef __cplusplus @@ -15,8 +14,7 @@ extern "C" { #include #ifndef _REENT_ONLY -#define errno (*__errno()) -extern int *__errno (void); +#define errno _REENT_ERRNO(_REENT) #endif /* Please don't use these variables directly.