From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 1595C385AE51 for ; Thu, 23 Jun 2022 11:37:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1595C385AE51 Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-649--fBYxWdxNvi9_7Nlj-CEUQ-1; Thu, 23 Jun 2022 07:37:56 -0400 X-MC-Unique: -fBYxWdxNvi9_7Nlj-CEUQ-1 Received: by mail-ej1-f69.google.com with SMTP id q5-20020a17090676c500b00704ffb95131so7802495ejn.8 for ; Thu, 23 Jun 2022 04:37:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=v6/n5nUldZEcSjOHqNhrPLNT8Lad596Pbi3m80P9aXY=; b=mMyV0tMjXKA07AWE9FXJ1wQHbtepaYkDHvP8VGF+DWwEKgDgj26Wzn2w0nt+nxwZQs PxwqfmCGaJGr7PWNKzLjgXr5pjc/is2ygWXxjE/U9osivaWBBhwFEI8DXCou9dGV56ZL RUSDNPRQ3Qxg0gB10SoYuAwyMLHMr5UApZTholBgsAfDdkL9YNhNycOwAhnHMLf/A9mJ cIvkJeA1xIHgymU3urqbP8AWSplFAdr71cNUXd6L0pTOiP46bz7u08m1KPGa5XE8b7/V a6vebTMkgnRGWWXijseW4ImFK7XlhArtU/OyX5XcULJ062ikooP036FXS2c/XbWQC+k0 3HZg== X-Gm-Message-State: AJIora/Ets76YI3vMcWfqLPx7rPdRN5EXk+UCOVenRHWf4mWMnPmMcvk sSva4yV81O70lPqB9Dx3gN4l/z/yURo7vCI4b8KU1jJFcMNIjg8Hk3/U1iG2NBAtAs8VLfrqwMO 897OPxcPQMXTp2TsvxlJNakRpuqNZ0HQ= X-Received: by 2002:aa7:de88:0:b0:435:9a54:168a with SMTP id j8-20020aa7de88000000b004359a54168amr10085687edv.73.1655984275509; Thu, 23 Jun 2022 04:37:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sP8Ni11jC/mzaMxpBZ4mVzwc3g/WWqsaapMk+nawWEbeS2qOhJDMyBoWi3A8Q1vkE5MIi2BY3aHxf70MiVAtg= X-Received: by 2002:aa7:de88:0:b0:435:9a54:168a with SMTP id j8-20020aa7de88000000b004359a54168amr10085674edv.73.1655984275284; Thu, 23 Jun 2022 04:37:55 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Jonathan Wakely Date: Thu, 23 Jun 2022 12:37:44 +0100 Message-ID: Subject: Re: [PATCH] libstdc++-v3: check for openat To: Alexandre Oliva Cc: gcc Patches , "libstdc++" X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Jun 2022 11:37:59 -0000 On Thu, 23 Jun 2022 at 12:08, Alexandre Oliva wrote: > > On Jun 22, 2022, Jonathan Wakely wrote: > > > There are other interactions between AT_CDCWD and ::openat not covered > > by this patch. I this this also needs to check HAVE_OPENAT: > > Here's an updated version, tested with this additional change. Did this improve your test results for directory iterators? In the unlikely even that the target has ::unlinkat but not ::openat this will cause a behaviour regression, because now _Dir::do_unlink will use {AT_FDCWD, "full/path/to/file"} instead of {dirfd(dirp),"file"} but I doubt there are targets that have unlinkat without openat. I'll try to improve this code later as discussed anyway, so this is fine for now. OK for trunk, thanks. > > > libstdc++: check for openat > > From: Alexandre Oliva > > 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. > > > 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. > * src/filesystem/dir.cc (dir_and_pathname): Use dirfd 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 + > libstdc++-v3/src/filesystem/dir.cc | 2 + > 5 files changed, 72 insertions(+), 2 deletions(-) > > 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 > diff --git a/libstdc++-v3/src/filesystem/dir.cc b/libstdc++-v3/src/filesystem/dir.cc > index b451902c4a1b1..e64489162e5ff 100644 > --- a/libstdc++-v3/src/filesystem/dir.cc > +++ b/libstdc++-v3/src/filesystem/dir.cc > @@ -120,7 +120,7 @@ struct fs::_Dir : std::filesystem::_Dir_base > dir_and_pathname() const noexcept > { > const fs::path& p = entry.path(); > -#if _GLIBCXX_HAVE_DIRFD > +#if _GLIBCXX_HAVE_DIRFD && _GLIBCXX_HAVE_OPENAT > return {::dirfd(this->dirp), std::prev(p.end())->c_str()}; > #endif > return {this->fdcwd(), p.c_str()}; > > > -- > Alexandre Oliva, happy hacker https://FSFLA.org/blogs/lxo/ > Free Software Activist GNU Toolchain Engineer > Disinformation flourishes because many people care deeply about injustice > but very few check the facts. Ask me about >