From patchwork Tue Mar 4 18:13:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 870121 Delivered-To: patch@linaro.org Received: by 2002:a05:6000:178f:b0:38f:210b:807b with SMTP id e15csp396247wrg; Tue, 4 Mar 2025 10:14:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU+moEERnPiOWrYJGFCis2OBIUd25wBHu8rPzP5zcK93nKSQGoNP2A/tsJHuwRZdmDm6rTTEw==@linaro.org X-Google-Smtp-Source: AGHT+IF18PmifMlAmGHmhz+N76hLFBYuDeDsNH/FdJJbJ2hEVehbCd0q5eU9VDTzMS8kSVUx8S/t X-Received: by 2002:a05:6102:493:b0:4c1:9610:feec with SMTP id ada2fe7eead31-4c1b3238902mr2507321137.11.1741112055440; Tue, 04 Mar 2025 10:14:15 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1741112055; cv=pass; d=google.com; s=arc-20240605; b=aJbXRhKiJPY8RInjWu9WakweRfa6PKfOjgYg3RTipS+4wubpZyS6Qz4RKYPMJjoONy 4d5YlEh+654ynd1sW+1+/t4ecedJ7jvmtHnIvVceDQ7M/DSkrgoUGl2925+jBmVoIoml YzGgPKbjE9gE8i0ZxGRgFZ3aygJqztQM5AYNgYLLis79DQrBWYmex4vOgyguIfvcg+hE keLk4Cr7pJmssUB7ti8MmIask48PfRAptXPJXe+Tz+/Aru/6dAwapMcUl/dXZ1sN1/l1 UvWVR0bYDu2WgprUkF4bYdnvRyY8u0DRAK9iAPfXWdTt6PIrXPRONOpQ/Y4C+07n4BGM u+ng== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :dkim-filter:arc-filter:dmarc-filter:delivered-to:dkim-filter; bh=dy4nsUQDvNF98LZ0MTbCrP9c/dylmOPwFu6kZ9tjuyY=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=GJclfkoq+snf1hdGX8aNO/JQj/IwE6I0Z02N5fVZ9SgJV4XWNACKJai/DDQ4430/6H p7+h8xvRgHtq7+e5nLKqeOfU61XU2HzjmUUDRRiH9KDVkLkihxaFvHSSFmgZpa+8eXzF 7TC6/dROZWGB0iXLbBPbLPC/Kq+H8xHlXX3i1YZW/dreSBuXQjUt4I8t2QXYqcQG0Bfj 3V9d+/fPhpaPPYYw2admShnASBrmll//klsg2bvdVG7jR/N1p9oPaqx5WGRIRCNuoKMJ 0/tDp5gaKwsQAaQnx+zmfN2hJzLhmdM0ZPx2S5mnJsnGYCAp6pj405FNU+8Q8O9LA7zU VSpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G8OH09f1; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ada2fe7eead31-4c16acf237fsi2101724137.149.2025.03.04.10.14.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 10:14:15 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=G8OH09f1; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EBDC93857C63 for ; Tue, 4 Mar 2025 18:14:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EBDC93857C63 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=G8OH09f1 X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by sourceware.org (Postfix) with ESMTPS id 38B5B3858410 for ; Tue, 4 Mar 2025 18:13:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 38B5B3858410 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 38B5B3858410 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741112033; cv=none; b=TLiCxuytJuroF0pvVTxDAyqLSOA7dq6GcCDfT+o3IK9cuH1KsauUvqcywXRWfpVojdJ8FGI4oLgTabLr436xiN5zB/6WNJ+sDKJhMDBNSHTJBqwzkAXDbTmnoaPHiBfh56fAJEzHgJdiJxKz+PrS9RjRULjYC30bXwGI3nCTP/Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741112033; c=relaxed/simple; bh=CEYkgxVgVUC2iNbDR04DPKg+cLKR2LsN4+YA3UF39dA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=W7e4xhnDxJzpb3dPSR1yqGF2SL8R4i/auyY7eUWGN7j6STZS1AQQjKFRLONdeCUzzy6utXyHHp/e7V6IvYdRZok6Awxpr4aKHk9/1rjBR2/sS7uQRKnFerXuxoMSnn6YhlrAVax0189I4+HEoqZ731kQSgO1apaocJclbDRsm0g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38B5B3858410 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-2235189adaeso1256995ad.0 for ; Tue, 04 Mar 2025 10:13:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741112032; x=1741716832; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=dy4nsUQDvNF98LZ0MTbCrP9c/dylmOPwFu6kZ9tjuyY=; b=G8OH09f1W++d6llLRHm/iLNFGcvNTSEUqDO7t7GAt5EKGj2fyqQv6RTrf/vyiwg0ar He8ozWs1C8njSxquGP7fGj019EyHsuAh2o6WkqRBzHlyhgwKrPxRRmUN8VEa/Q4ThwS1 16lxR6dDLVZ9kDY+zMrfCglzFNEbn0ARM+KG8gTckqCw+FASwAA3rtVDqM8Wefpn05Ob CNLamrsOK/CFXzV/M5kjoXGvPklpZVdbSXgJkSvUwZOr1tZGt7/wsbH7gZVn3kddSbmn sNUqDzdjj4GR802eglypKwjGmmcdN2rhb/GOFh8xUS2Pigvb54PGF24mmCqnhPCDqpWC 2FmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741112032; x=1741716832; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dy4nsUQDvNF98LZ0MTbCrP9c/dylmOPwFu6kZ9tjuyY=; b=YG6nKfYxGR0GBOxP1FsFBLErI5bK5qW59QZHuu8okE6xYgQa3bXpiV4DBMi40kWL5p t4i8TmmzTcQGj0cFYgTqXCnS6ujmsoqV/AxyfgO7Kr5hXh0Kq4a44XRLijHy7I6LkNA4 Uv2jUgJQEqUbxEZdnQ4rqz2U3iKTAP+wV68p+3Cue0OU7NNL+EZ72Jgv+93Hpcse+Jwn PW+VbAlUFZzqNX1FX0qKxrG2iyqrh8PH0r0hCDlRCPM+u+UNdEnzY4RJygK9281KSh8p t5xOU97AQymnahSy/EPiULcVZ20qxVE2k/jYtMFa/c/vND/7Kc29/A+0y33JRk7J4Kni XiwA== X-Gm-Message-State: AOJu0Yw7YzMTs6Cp8MBHwr6NOhfAM7MfSxBCkXCJkrH5ViED/B3xoSya pwNvUQkA6SwMr4wjuHkLXnqkRw58JOxT9kW5bVzaGQ2keAoUhgNXiZW9hjw/f4PXLABkxG0BRMW T X-Gm-Gg: ASbGncu6QB1vsb9vMSe0LRxsQ0Ktof/lZiBUitZMQ2Eai5CFjLatQNr1+X0Fyi3um+9 XCJ+2WB6HGcQ8vhFX7r1hsWJDmunyL/0EXWAFyd4sKvBuxsSYo5zxgamuTr/sw5unJcC6ODWEWq x1Sr9CSzKiHnIpf/AcsnYav0uOdaGgFpOZOOIg0AhrhXdnr9xl3aWqwDvjG34y4KQUKJW1nabYl BZC+ZRARzTsIG2tIsRuunB0ZD8j1K/KKJhslr9L6lq+RVFf6Go1ZvKBlt7PmPJHByJY+O3URkJh 0mJN3FwEvhp08QdDzf51pFVUrEjos1ymzwpzHVWC/AFOdIaX0BTDjZrSWA== X-Received: by 2002:a17:903:fb0:b0:223:607c:1d99 with SMTP id d9443c01a7336-223f1c2ad1bmr2916895ad.0.1741112031695; Tue, 04 Mar 2025 10:13:51 -0800 (PST) Received: from mandiga.. ([2804:1b3:a7c0:904d:d830:5e9a:488f:b153]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-223504dc28esm98101085ad.166.2025.03.04.10.13.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Mar 2025 10:13:51 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] Remove eloop-threshold.h Date: Tue, 4 Mar 2025 15:13:41 -0300 Message-ID: <20250304181347.1407531-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org On both Linux and Hurd the __eloop_threshold() is always a constant (40 and 32 respectively), so there is no need to always call __sysconf (_SC_SYMLOOP_MAX) for Linux case (!SYMLOOP_MAX). To avoid a name clash with gnulib, rename the new file min-eloop-threshold.h. Checked on x86_64-linux-gnu and with a build for x86_64-gnu. --- elf/chroot_canon.c | 5 +- hurd/lookup-retry.c | 6 +- stdlib/canonicalize.c | 6 +- stdlib/tst-canon-bz26341.c | 4 +- sysdeps/generic/eloop-threshold.h | 72 ------------------- sysdeps/generic/min-eloop-threshold.h | 42 +++++++++++ ...loop-threshold.h => min-eloop-threshold.h} | 14 ++-- sysdeps/mach/hurd/sysconf.c | 4 +- 8 files changed, 60 insertions(+), 93 deletions(-) delete mode 100644 sysdeps/generic/eloop-threshold.h create mode 100644 sysdeps/generic/min-eloop-threshold.h rename sysdeps/mach/hurd/{eloop-threshold.h => min-eloop-threshold.h} (83%) diff --git a/elf/chroot_canon.c b/elf/chroot_canon.c index 5db13c22bd..34869f1c05 100644 --- a/elf/chroot_canon.c +++ b/elf/chroot_canon.c @@ -23,8 +23,7 @@ #include #include #include - -#include +#include #include #ifndef PATH_MAX @@ -126,7 +125,7 @@ chroot_canon (const char *chroot, const char *name) char *buf = alloca (PATH_MAX); size_t len; - if (++num_links > __eloop_threshold ()) + if (++num_links > MIN_ELOOP_THRESHOLD) { __set_errno (ELOOP); goto error; diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c index 6b94a10eae..ac8925ec1b 100644 --- a/hurd/lookup-retry.c +++ b/hurd/lookup-retry.c @@ -24,7 +24,7 @@ #include #include #include <_itoa.h> -#include +#include #include /* Translate the error from dir_lookup into the error the user sees. */ @@ -113,7 +113,7 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) /* Fall through. */ case FS_RETRY_NORMAL: - if (nloops++ >= __eloop_threshold ()) + if (nloops++ >= MIN_ELOOP_THRESHOLD) { __mach_port_deallocate (__mach_task_self (), *result); err = ELOOP; @@ -207,7 +207,7 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port) dirport = INIT_PORT_CRDIR; if (*result != MACH_PORT_NULL) __mach_port_deallocate (__mach_task_self (), *result); - if (nloops++ >= __eloop_threshold ()) + if (nloops++ >= MIN_ELOOP_THRESHOLD) { err = ELOOP; goto out; diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c index 528bf49acf..dca6fca5fb 100644 --- a/stdlib/canonicalize.c +++ b/stdlib/canonicalize.c @@ -36,17 +36,19 @@ #include #include -#include #include #include #include #include #ifdef _LIBC +# include # include # define GCC_LINT 1 # define _GL_ATTRIBUTE_PURE __attribute__ ((__pure__)) #else +# include +# define MIN_ELOOP_THRESHOLD __eloop_threshold () # define __canonicalize_file_name canonicalize_file_name # define __realpath realpath # define __strdup strdup @@ -310,7 +312,7 @@ realpath_stk (const char *name, char *resolved, struct realpath_bufs *bufs) } if (0 <= n) { - if (++num_links > __eloop_threshold ()) + if (++num_links > MIN_ELOOP_THRESHOLD) { __set_errno (ELOOP); goto error; diff --git a/stdlib/tst-canon-bz26341.c b/stdlib/tst-canon-bz26341.c index a9b823b21e..b62b2cae44 100644 --- a/stdlib/tst-canon-bz26341.c +++ b/stdlib/tst-canon-bz26341.c @@ -23,7 +23,7 @@ #include #define __sysconf sysconf -#include +#include #include #include #include @@ -54,7 +54,7 @@ create_link (void) /* Create MAXLINKS symbolic links to the temporary filename. On exit, linkname has the last link created. */ char *prevlink = filename; - int maxlinks = __eloop_threshold (); + int maxlinks = MIN_ELOOP_THRESHOLD; for (int i = 0; i < maxlinks; i++) { linkname = xasprintf ("%s%d", filename, i); diff --git a/sysdeps/generic/eloop-threshold.h b/sysdeps/generic/eloop-threshold.h deleted file mode 100644 index 02363689b0..0000000000 --- a/sysdeps/generic/eloop-threshold.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Threshold at which to diagnose ELOOP. Generic version. - Copyright (C) 2012-2025 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - . */ - -#ifndef _ELOOP_THRESHOLD_H -#define _ELOOP_THRESHOLD_H 1 - -#include -#include - -/* POSIX specifies SYMLOOP_MAX as the "Maximum number of symbolic - links that can be reliably traversed in the resolution of a - pathname in the absence of a loop." This makes it a minimum that - we should certainly accept. But it leaves open the possibility - that more might sometimes work--just not "reliably". - - For example, Linux implements a complex policy whereby there is a - small limit on the number of direct symlink traversals (a symlink - to a symlink to a symlink), but larger limit on the total number of - symlink traversals overall. Hence the SYMLOOP_MAX number should be - the small one, but the limit library functions enforce on users - should be the larger one. - - So, we use the larger of the reported SYMLOOP_MAX (if any) and our - own constant MIN_ELOOP_THRESHOLD, below. This constant should be - large enough that it never rules out a file name and directory tree - that the underlying system (i.e. calls to 'open' et al) would - resolve successfully. It should be small enough that actual loops - are detected without a huge number of iterations. */ - -#ifndef MIN_ELOOP_THRESHOLD -# define MIN_ELOOP_THRESHOLD 40 -#endif - -/* Return the maximum number of symlink traversals to permit - before diagnosing ELOOP. */ -static inline unsigned int __attribute__ ((const)) -__eloop_threshold (void) -{ -#ifdef SYMLOOP_MAX - const int symloop_max = SYMLOOP_MAX; -#else - /* The function is marked 'const' even though we use memory and - call a function, because sysconf is required to return the - same value in every call and so it must always be safe to - call __eloop_threshold exactly once and reuse the value. */ - static long int sysconf_symloop_max; - if (sysconf_symloop_max == 0) - sysconf_symloop_max = __sysconf (_SC_SYMLOOP_MAX); - const unsigned int symloop_max = (sysconf_symloop_max <= 0 - ? _POSIX_SYMLOOP_MAX - : sysconf_symloop_max); -#endif - - return MAX (symloop_max, MIN_ELOOP_THRESHOLD); -} - -#endif /* eloop-threshold.h */ diff --git a/sysdeps/generic/min-eloop-threshold.h b/sysdeps/generic/min-eloop-threshold.h new file mode 100644 index 0000000000..2ac12edeef --- /dev/null +++ b/sysdeps/generic/min-eloop-threshold.h @@ -0,0 +1,42 @@ +/* Minimum threshold at which to diagnose ELOOP. Generic version. + Copyright (C) 2012-2025 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _MIN_ELOOP_THRESHOLD_H +#define _MIN_ELOOP_THRESHOLD_H 1 + +/* POSIX specifies SYMLOOP_MAX as the "Maximum number of symbolic + links that can be reliably traversed in the resolution of a + pathname in the absence of a loop." This makes it a minimum that + we should certainly accept. But it leaves open the possibility + that more might sometimes work--just not "reliably". + + For example, Linux implements a complex policy whereby there is a + small limit on the number of direct symlink traversals (a symlink + to a symlink to a symlink), but larger limit on the total number of + symlink traversals overall. Hence the SYMLOOP_MAX number should be + the small one, but the limit library functions enforce on users + should be the larger one. + + This constant should be large enough that it never rules out a file + name and directory tree that the underlying system (i.e. calls to 'open' + et al) would resolve successfully. It should be small enough that + actual loops are detected without a huge number of iterations. */ + +#define MIN_ELOOP_THRESHOLD 40 + +#endif diff --git a/sysdeps/mach/hurd/eloop-threshold.h b/sysdeps/mach/hurd/min-eloop-threshold.h similarity index 83% rename from sysdeps/mach/hurd/eloop-threshold.h rename to sysdeps/mach/hurd/min-eloop-threshold.h index 13842b489d..98ecf49d00 100644 --- a/sysdeps/mach/hurd/eloop-threshold.h +++ b/sysdeps/mach/hurd/min-eloop-threshold.h @@ -1,4 +1,4 @@ -/* Threshold at which to diagnose ELOOP. Hurd version. +/* Minimum threshold at which to diagnose ELOOP. Hurd version. Copyright (C) 2012-2025 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -16,8 +16,8 @@ License along with the GNU C Library; if not, see . */ -#ifndef _ELOOP_THRESHOLD_H -#define _ELOOP_THRESHOLD_H 1 +#ifndef _MIN_ELOOP_THRESHOLD_H +#define _MIN_ELOOP_THRESHOLD_H 1 /* Return the maximum number of symlink traversals to permit before diagnosing ELOOP. @@ -28,10 +28,6 @@ but instead use sysconf and the number can be changed here to affect sysconf's result. */ -static inline unsigned int __attribute__ ((const)) -__eloop_threshold (void) -{ - return 32; -} +#define MIN_ELOOP_THRESHOLD 32 -#endif /* eloop-threshold.h */ +#endif diff --git a/sysdeps/mach/hurd/sysconf.c b/sysdeps/mach/hurd/sysconf.c index cb4899a67b..bf610901f4 100644 --- a/sysdeps/mach/hurd/sysconf.c +++ b/sysdeps/mach/hurd/sysconf.c @@ -19,8 +19,8 @@ #include #include -#include +#include -#define SYMLOOP_MAX (__eloop_threshold ()) +#define SYMLOOP_MAX MIN_ELOOP_THRESHOLD #include