From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id B057D3858C30; Thu, 2 Feb 2023 09:34:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B057D3858C30 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675330486; bh=URNdswxANqihLwdlnUEVQmzIva8zFvp8QejDTU1vKts=; h=From:To:Subject:Date:From; b=oAz8HKzZxfEi2H6EK9/dSaDmQLbKPHQBPeOl7Alvazc5LLwH273B8vzMUeTeL3HCf spwGKLbwW1pRIWtWZsTpJlOJSXi4dESW9jI3rOzaxLdfrWGst2XzWpzsNw8N3nG8L7 COaX4Gd2mB4PsxfGKcg0v4hS1abUBYQI3Yd0jzFg= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-9099] libstdc++: Fix build failures for avr X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 953c3c68f8940d03bfded87dc79635451e1892b0 X-Git-Newrev: aa18735f7aa99b40c56b3e3aacb1b28cb805bb90 Message-Id: <20230202093446.B057D3858C30@sourceware.org> Date: Thu, 2 Feb 2023 09:34:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:aa18735f7aa99b40c56b3e3aacb1b28cb805bb90 commit r12-9099-gaa18735f7aa99b40c56b3e3aacb1b28cb805bb90 Author: Jonathan Wakely Date: Tue Jan 31 22:16:31 2023 +0000 libstdc++: Fix build failures for avr 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. (cherry picked from commit 2d2e163d12f64a5e68f9e0381751ed9d5d6d3617) Diff: --- 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 8e22cf7c917..35f504ba6ce 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 7b1a5a20637..f2b645caa6f 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 435368fa5c5..8e612334613 100644 --- a/libstdc++-v3/src/c++17/fs_ops.cc +++ b/libstdc++-v3/src/c++17/fs_ops.cc @@ -735,7 +735,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)}) { @@ -1301,6 +1301,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; @@ -1308,6 +1309,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)); @@ -1338,6 +1340,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(); @@ -1346,6 +1349,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 978e8724154..edada8cd258 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