From patchwork Wed Feb 1 21:08:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 64121 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 1E7C1385B530 for ; Wed, 1 Feb 2023 21:09:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E7C1385B530 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675285768; bh=wp3RLoM5yGq1d/GzR9/P+4WlIeXxWrPSijvtnk9HjG4=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gA8ZpXcwtSc1HqX4S+UTHGkCJ0122tWK+iltg1qPR7CmtDE8RJ3z2p1veDfjeJeGR /Au27sDn34M2qHFO3a6OW94JskZ0EDMwLanLgQt+8QZoqfzi+4snj1a2HJqVSZIJjV 70OUxS+RQX5ZXxStkERgMMU6nAVX8k7s7Mh1qRkg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id A16AA38582A3 for ; Wed, 1 Feb 2023 21:08:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A16AA38582A3 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-670-BqW5uoQsMMSMZXi-iU5oWw-1; Wed, 01 Feb 2023 16:08:54 -0500 X-MC-Unique: BqW5uoQsMMSMZXi-iU5oWw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DBA1E80D08D; Wed, 1 Feb 2023 21:08:53 +0000 (UTC) Received: from localhost (unknown [10.33.36.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1E4E53A0; Wed, 1 Feb 2023 21:08:53 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix build failures for avr Date: Wed, 1 Feb 2023 21:08:53 +0000 Message-Id: <20230201210853.2445267-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.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_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested x86_64-linux, built on avr and msp430-elf. This should be backported to the branches where avr fails to build with --enable-libstdcxx due to these problems. -- >8 -- The abr-libc does not define EOVERFLOW, which means that std::errc::value_too_large is not defined, and so cannot be compiled. Define value_too_large for avr with a value that does not clash with any that is defined in . This is a kluge to fix bootstrap for avr; it can be removed after PR libstdc++/104883 is resolved. The avr-libc fails to meet the C and POSIX requirements that each error macro has a distinct integral value, and is usable in #if directives. Add a special case for avr to system_error.cc so that only the valid errors are recognized. Also disable the errno checks in std::filesystem::remove_all that assume a meaningful value for errno. On avr-libc exists but does not define the POSIX functions needed by std::filesystem, so _GLIBCXX_HAVE_UNISTD_H is not sufficient to check for basic POSIX APIs. Check !defined __AVR__ as well as _GLIBCXX_HAVE_UNISTD_H before using those functions. This is a kluge and we should really have a specific macro that says the required functions are available. libstdc++-v3/ChangeLog: * config/os/generic/error_constants.h (errc::value_too_large) [__AVR__]: Define. * src/c++11/system_error.cc (system_category::default_error_condition) [__AVR__]: Only match recognize values equal to EDOM, ERANGE, ENOSYS and EINTR. * src/c++17/fs_ops.cc (fs::current_path) [__AVR__]: Do not check for ENOENT etc. in switch. (fs::remove_all) [__AVR__]: Likewise. * src/filesystem/ops-common.h [__AVR__]: Do not use POSIX open, close etc. --- libstdc++-v3/config/os/generic/error_constants.h | 2 ++ libstdc++-v3/src/c++11/system_error.cc | 9 +++++++++ libstdc++-v3/src/c++17/fs_ops.cc | 6 +++++- libstdc++-v3/src/filesystem/ops-common.h | 2 +- 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/config/os/generic/error_constants.h b/libstdc++-v3/config/os/generic/error_constants.h index 4d900414494..ba2795352bc 100644 --- a/libstdc++-v3/config/os/generic/error_constants.h +++ b/libstdc++-v3/config/os/generic/error_constants.h @@ -167,6 +167,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #ifdef EOVERFLOW value_too_large = EOVERFLOW, +#elif defined __AVR__ + value_too_large = 999, #endif wrong_protocol_type = EPROTOTYPE diff --git a/libstdc++-v3/src/c++11/system_error.cc b/libstdc++-v3/src/c++11/system_error.cc index 6e7c0ac0c26..748eee94168 100644 --- a/libstdc++-v3/src/c++11/system_error.cc +++ b/libstdc++-v3/src/c++11/system_error.cc @@ -251,6 +251,15 @@ namespace X (WRITE_PROTECT, EROFS); #undef X +#elif defined __AVR__ + // avr-libc only defines a few distinct error numbers. Most + // constants are not usable in #if directives and have the same value. + case EDOM: + case ERANGE: + case ENOSYS: + case EINTR: + case 0: + return std::error_condition(ev, generic_category_instance.obj); #else // List of errno macros from [cerrno.syn]. // C11 only defines EDOM, EILSEQ and ERANGE, the rest are from POSIX. diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc index b49bf4a6b20..c94d260632f 100644 --- a/libstdc++-v3/src/c++17/fs_ops.cc +++ b/libstdc++-v3/src/c++17/fs_ops.cc @@ -736,7 +736,7 @@ fs::path fs::current_path(error_code& ec) { path p; -#ifdef _GLIBCXX_HAVE_UNISTD_H +#if defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__ #if defined __GLIBC__ || defined _GLIBCXX_FILESYSTEM_IS_WINDOWS if (char_ptr cwd = char_ptr{posix::getcwd(nullptr, 0)}) { @@ -1302,6 +1302,7 @@ fs::remove_all(const path& p) } // Directory is empty now, will remove it below. break; +#ifndef __AVR__ case ENOENT: // Our work here is done. return 0; @@ -1309,6 +1310,7 @@ fs::remove_all(const path& p) case ELOOP: // Not a directory, will remove below. break; +#endif default: // An error occurred. _GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot remove all", p, ec)); @@ -1339,6 +1341,7 @@ fs::remove_all(const path& p, error_code& ec) } // Directory is empty now, will remove it below. break; +#ifndef __AVR__ case ENOENT: // Our work here is done. ec.clear(); @@ -1347,6 +1350,7 @@ fs::remove_all(const path& p, error_code& ec) case ELOOP: // Not a directory, will remove below. break; +#endif default: // An error occurred. return -1; diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h index b0d49dd4d4f..02c75be09d2 100644 --- a/libstdc++-v3/src/filesystem/ops-common.h +++ b/libstdc++-v3/src/filesystem/ops-common.h @@ -167,7 +167,7 @@ namespace __gnu_posix return ret; } using char_type = wchar_t; -#elif defined _GLIBCXX_HAVE_UNISTD_H +#elif defined _GLIBCXX_HAVE_UNISTD_H && ! defined __AVR__ using ::open; using ::close; # ifdef _GLIBCXX_HAVE_SYS_STAT_H