From patchwork Wed Jun 22 06:41:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1646360 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=wj4bnhtu; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LSYjm4CBdz9sFw for ; Wed, 22 Jun 2022 16:43:07 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D6BC238356A7 for ; Wed, 22 Jun 2022 06:43:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6BC238356A7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1655880184; bh=jqlLnXBIe5IVy3WO8tAyuH69PLI4j5fZJgO/o6EEHs4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wj4bnhtuQmkEtOeHmaSvg3wrWFSJzQHQPRY1AgW2fT6bnC8i0yYPoMVs7Kgdjw7/C BoTs6Cpc8J92ap+j1bFRImK1KZcN/x/LpRLWBhXsAhjLtqeXJDsFXoli7/BsUD/X59 nJn9POuvRz0gJKBVWG5fAC7RTzQ+GU/GFlH6eJ90= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from rock.gnat.com (rock.gnat.com [IPv6:2620:20:4000:0:a9e:1ff:fe9b:1d1]) by sourceware.org (Postfix) with ESMTPS id B1E203835421; Wed, 22 Jun 2022 06:41:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B1E203835421 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7A5A7116101; Wed, 22 Jun 2022 02:41:53 -0400 (EDT) X-Virus-Scanned: Debian amavisd-new at gnat.com Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id QDoPZR2xuDxJ; Wed, 22 Jun 2022 02:41:53 -0400 (EDT) Received: from free.home (tron.gnat.com [IPv6:2620:20:4000:0:46a8:42ff:fe0e:e294]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPS id 415F61160C2; Wed, 22 Jun 2022 02:41:52 -0400 (EDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 25M6ffoJ724334 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 22 Jun 2022 03:41:41 -0300 To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: [PATCH] libstdc++-v3: check for openat Organization: Free thinker, does not speak for AdaCore Date: Wed, 22 Jun 2022 03:41:41 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alexandre Oliva via Gcc-patches From: Alexandre Oliva Reply-To: Alexandre Oliva Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" rtems6.0 has fdopendir, and fcntl.h defines AT_FDCWD and declares openat, but there's no openat in libc. Adjust dir-common.h to not assume ::openat just because of AT_FDCWD. Regstrapped on x86_64-linux-gnu (detects and still uses openat), also tested with a cross to aarch64-rtems6 (detects openat's absence and refrains from using it). Ok to install? PS: This is the last patch in my rtems6.0 patchset, and the only patch for the filesystem-related patchset that was written specifically for a mainline gcc. gcc-11 did not attempt to use openat. This patch enabled filesystem tests to link when testing mainline on aarch64-rtems6.0. Alas, several filesystem tests still failed with it, in ways that AFAICT are not related with the use of openat, or with the other patches I've posted. However, I'm not able to look into the remaining failures right now. for libstdc++-v3/ChangeLog * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for openat. * aclocal.m4, configure, config.h.in: Rebuilt. * src/filesystem/dir-common.h (openat): Use ::openat if _GLIBCXX_HAVE_OPENAT. --- libstdc++-v3/acinclude.m4 | 12 +++++++ libstdc++-v3/config.h.in | 3 ++ libstdc++-v3/configure | 55 ++++++++++++++++++++++++++++++ libstdc++-v3/src/filesystem/dir-common.h | 2 + 4 files changed, 71 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 138bd58d86cb9..e3cc3a8e867d3 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -4772,6 +4772,18 @@ dnl if test $glibcxx_cv_dirfd = yes; then AC_DEFINE(HAVE_DIRFD, 1, [Define if dirfd is available in .]) fi +dnl + AC_CACHE_CHECK([for openat], + glibcxx_cv_openat, [dnl + GCC_TRY_COMPILE_OR_LINK( + [#include ], + [int fd = ::openat(AT_FDCWD, "", 0);], + [glibcxx_cv_openat=yes], + [glibcxx_cv_openat=no]) + ]) + if test $glibcxx_cv_openat = yes; then + AC_DEFINE(HAVE_OPENAT, 1, [Define if openat is available in .]) + fi dnl AC_CACHE_CHECK([for unlinkat], glibcxx_cv_unlinkat, [dnl diff --git a/libstdc++-v3/config.h.in b/libstdc++-v3/config.h.in index f30a8c51c458c..2a3972eef5412 100644 --- a/libstdc++-v3/config.h.in +++ b/libstdc++-v3/config.h.in @@ -292,6 +292,9 @@ /* Define if defines obsolete isnan function. */ #undef HAVE_OBSOLETE_ISNAN +/* Define if openat is available in . */ +#undef HAVE_OPENAT + /* Define if poll is available in . */ #undef HAVE_POLL diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 9b94fd71e4248..eac6039212168 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -77177,6 +77177,61 @@ $as_echo "$glibcxx_cv_dirfd" >&6; } $as_echo "#define HAVE_DIRFD 1" >>confdefs.h + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for openat" >&5 +$as_echo_n "checking for openat... " >&6; } +if ${glibcxx_cv_openat+:} false; then : + $as_echo_n "(cached) " >&6 +else + if test x$gcc_no_link = xyes; then + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +int fd = ::openat(AT_FDCWD, "", 0); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + glibcxx_cv_openat=yes +else + glibcxx_cv_openat=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext +else + if test x$gcc_no_link = xyes; then + as_fn_error $? "Link tests are not allowed after GCC_NO_EXECUTABLES." "$LINENO" 5 +fi +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +int fd = ::openat(AT_FDCWD, "", 0); + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_link "$LINENO"; then : + glibcxx_cv_openat=yes +else + glibcxx_cv_openat=no +fi +rm -f core conftest.err conftest.$ac_objext \ + conftest$ac_exeext conftest.$ac_ext +fi + +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $glibcxx_cv_openat" >&5 +$as_echo "$glibcxx_cv_openat" >&6; } + if test $glibcxx_cv_openat = yes; then + +$as_echo "#define HAVE_OPENAT 1" >>confdefs.h + fi { $as_echo "$as_me:${as_lineno-$LINENO}: checking for unlinkat" >&5 $as_echo_n "checking for unlinkat... " >&6; } diff --git a/libstdc++-v3/src/filesystem/dir-common.h b/libstdc++-v3/src/filesystem/dir-common.h index 365fd527f4d68..669780ea23fe5 100644 --- a/libstdc++-v3/src/filesystem/dir-common.h +++ b/libstdc++-v3/src/filesystem/dir-common.h @@ -199,7 +199,7 @@ struct _Dir_base #endif -#ifdef AT_FDCWD +#if _GLIBCXX_HAVE_OPENAT && defined AT_FDCWD fd = ::openat(fd, pathname, flags); #else // If we cannot use openat, there's no benefit to using posix::open unless