public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r11-10578] libstdc++: Fix build failures for avr
Date: Thu, 16 Mar 2023 16:51:12 +0000 (GMT)	[thread overview]
Message-ID: <20230316165112.64EF23858D35@sourceware.org> (raw)

https://gcc.gnu.org/g:c86ac1a463f97554b1df9ef8a3e18573ef115e35

commit r11-10578-gc86ac1a463f97554b1df9ef8a3e18573ef115e35
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jan 31 22:16:31 2023 +0000

    libstdc++: Fix build failures for avr
    
    The avr-libc <errno.h> does not define EOVERFLOW, which means that
    std::errc::value_too_large is not defined, and so <charconv> cannot be
    compiled. Define value_too_large for avr with a value that does not
    clash with any that is defined in <errno.h>. This is a kluge to fix
    bootstrap for avr; it can be removed after PR libstdc++/104883 is
    resolved.
    
    The avr-libc <errno.h> 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 <unistd.h> 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 use
            getcwd.
            * 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           | 12 +++++++++++-
 libstdc++-v3/src/c++17/fs_ops.cc                 |  2 +-
 libstdc++-v3/src/filesystem/ops-common.h         |  2 +-
 4 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/config/os/generic/error_constants.h b/libstdc++-v3/config/os/generic/error_constants.h
index 9d01c16ee27..1d37454ba2e 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 34274387637..2b5010dbb40 100644
--- a/libstdc++-v3/src/c++11/system_error.cc
+++ b/libstdc++-v3/src/c++11/system_error.cc
@@ -93,6 +93,16 @@ namespace
       // and system category otherwise.
       switch (ev)
       {
+#if defined __AVR__
+      // avr-libc only defines a few distinct error numbers. Most <errno.h>
+      // 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.
       // They expand to integer constant expressions with type int,
@@ -339,7 +349,7 @@ namespace
       case EBLAH:
 	return std::error_condition(EINVAL, std::generic_category());
        */
-
+#endif
       default:
 	return std::error_condition(ev, *this);
       }
diff --git a/libstdc++-v3/src/c++17/fs_ops.cc b/libstdc++-v3/src/c++17/fs_ops.cc
index 481b49d20be..4155b4d64b9 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)})
     {
diff --git a/libstdc++-v3/src/filesystem/ops-common.h b/libstdc++-v3/src/filesystem/ops-common.h
index a76a2e6198d..54bafff2a9c 100644
--- a/libstdc++-v3/src/filesystem/ops-common.h
+++ b/libstdc++-v3/src/filesystem/ops-common.h
@@ -128,7 +128,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

                 reply	other threads:[~2023-03-16 16:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230316165112.64EF23858D35@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).