From: Jonathan Wakely <jwakely@redhat.com>
To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: [RFC] libstdc++: Generate error_constants.h from <errno.h> [PR104883]
Date: Tue, 4 Oct 2022 17:51:09 +0100 [thread overview]
Message-ID: <20221004165109.559028-1-jwakely@redhat.com> (raw)
Does anybody see any issues with generating the list of error numbers at
build time?
-- >8 --
Instead of having several very similar target-specific headers with
slightly different sets of enumerators, generate the error_constants.h
file as part of the build. This ensures that all enumerators are always
defined, with the value from the corresponding errno macro if present,
or a libstdc++-specific alternative value.
The libstdc++-specific values will be values greater than the positive
integer _GLIBCXX_ERRC_ORIGIN, which defaults to 9999 but can be set in
os_defines.h if a more suitable value exists for the OS (e.g. ELAST
could be used for BSD targets).
libstdc++-v3/ChangeLog:
PR libstdc++/104883
* configure.host (error_constants_dir): Remove.
* include/Makefile.am (error_constants.h): Generate using
make_errc.sh script.
* include/Makefile.in: Regenerate.
* scripts/make_errc.sh: New file.
---
libstdc++-v3/configure.host | 7 --
libstdc++-v3/include/Makefile.am | 6 +-
libstdc++-v3/include/Makefile.in | 6 +-
libstdc++-v3/scripts/make_errc.sh | 165 ++++++++++++++++++++++++++++++
4 files changed, 175 insertions(+), 9 deletions(-)
create mode 100755 libstdc++-v3/scripts/make_errc.sh
diff --git a/libstdc++-v3/configure.host b/libstdc++-v3/configure.host
index ec32980aa0d..6d51c5f6a11 100644
--- a/libstdc++-v3/configure.host
+++ b/libstdc++-v3/configure.host
@@ -56,9 +56,6 @@
# cpu_opt_ext_random path name of random.h containing CPU-specific
# optimizations for extensions
#
-# error_constants_dir location of error_constants.h
-# defaults to os/generic.
-#
# It possibly modifies the following variables:
#
# OPT_LDFLAGS extra flags to pass when linking the library, of
@@ -93,7 +90,6 @@ cpu_defines_dir="cpu/generic"
try_cpu=generic
abi_baseline_subdir_switch=--print-multi-directory
abi_tweaks_dir="cpu/generic"
-error_constants_dir="os/generic"
tmake_file=
# HOST-SPECIFIC OVERRIDES
@@ -247,7 +243,6 @@ case "${host_os}" in
;;
*djgpp*) # leading * picks up "msdosdjgpp"
os_include_dir="os/djgpp"
- error_constants_dir="os/djgpp"
;;
dragonfly*)
os_include_dir="os/bsd/dragonfly"
@@ -274,11 +269,9 @@ case "${host_os}" in
case "$host" in
*-w64-*)
os_include_dir="os/mingw32-w64"
- error_constants_dir="os/mingw32-w64"
;;
*)
os_include_dir="os/mingw32"
- error_constants_dir="os/mingw32"
;;
esac
OPT_LDFLAGS="${OPT_LDFLAGS} \$(lt_host_flags)"
diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am
index 97542524a69..28c5b3c4453 100644
--- a/libstdc++-v3/include/Makefile.am
+++ b/libstdc++-v3/include/Makefile.am
@@ -1033,7 +1033,6 @@ host_headers = \
${glibcxx_srcdir}/$(ATOMIC_WORD_SRCDIR)/atomic_word.h \
${glibcxx_srcdir}/$(ABI_TWEAKS_SRCDIR)/cxxabi_tweaks.h \
${glibcxx_srcdir}/$(CPU_DEFINES_SRCDIR)/cpu_defines.h \
- ${glibcxx_srcdir}/$(ERROR_CONSTANTS_SRCDIR)/error_constants.h \
${glibcxx_srcdir}/include/precompiled/stdc++.h \
${glibcxx_srcdir}/include/precompiled/stdtr1c++.h \
${glibcxx_srcdir}/include/precompiled/extc++.h
@@ -1051,6 +1050,7 @@ host_headers_extra = \
${host_builddir}/c++allocator.h \
${host_builddir}/c++io.h \
${host_builddir}/c++locale.h \
+ ${host_builddir}/error_constants.h \
${host_builddir}/messages_members.h \
${host_builddir}/time_members.h
@@ -1106,6 +1106,7 @@ allstamped = \
# catenation.
allcreated = \
${host_builddir}/c++config.h \
+ ${host_builddir}/error_constants.h \
${host_builddir}/largefile-config.h \
${thread_host_headers} \
${pch_build}
@@ -1404,6 +1405,9 @@ ${host_builddir}/c++config.h: ${CONFIG_HEADER} \
echo "" >> $@ ;\
echo "#endif // _GLIBCXX_CXX_CONFIG_H" >> $@
+${host_builddir}/error_constants.h: ${glibcxx_srcdir}/scripts/make_errc.sh
+ ${glibcxx_srcdir}/scripts/make_errc.sh $@ "${CXXCPP}" ${AM_CPPFLAGS}
+
# Host includes for threads
uppercase = [ABCDEFGHIJKLMNOPQRSTUVWXYZ_]
diff --git a/libstdc++-v3/scripts/make_errc.sh b/libstdc++-v3/scripts/make_errc.sh
new file mode 100755
index 00000000000..4b98abe2bed
--- /dev/null
+++ b/libstdc++-v3/scripts/make_errc.sh
@@ -0,0 +1,165 @@
+#!/bin/sh
+
+[ -z "$1" ] && exit 1
+target=$1
+shift
+CXXCPP="$@"
+
+{
+ dir=`(umask 077 && mktemp -d "$target.XXXXXX") 2>/dev/null` &&
+ test -d "$dir"
+} || {
+ dir=$target.$RANDOM$$
+ (umask 077 && mkdir "$dir")
+} || exit $?
+
+output_h=$dir/output.h
+constants_h=$dir/constants.h
+
+cat > "$output_h" << EOT
+// Definition of std::errc enumeration type -*- C++ -*-
+
+// Copyright The GNU Toolchain Authors.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
+
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+// <http://www.gnu.org/licenses/>.
+
+/** @file bits/errc.h
+ * This is an internal header file, included by other library headers.
+ * Do not attempt to use it directly. @headername{system_error}
+ */
+
+// This is a generated file. Do not edit directly.
+
+#ifndef _GLIBCXX_ERRC_H
+#define _GLIBCXX_ERRC_H 1
+
+#if __cplusplus >= 201103L
+namespace std _GLIBCXX_VISIBILITY(default)
+{
+_GLIBCXX_BEGIN_NAMESPACE_VERSION
+
+ enum class errc
+ {
+EOT
+
+cat > "$constants_h" <<EOT
+#if __has_include (<errno.h>)
+#include <errno.h>
+#endif
+#include <bits/c++config.h>
+#ifndef _GLIBCXX_ERRC_ORIGIN
+# define _GLIBCXX_ERRC_ORIGIN 9999
+#endif
+#line _GLIBCXX_ERRC_ORIGIN
+GLIBCXX ERROR CONSTANTS BELOW HERE
+ address_family_not_supported = EAFNOSUPPORT,
+ address_in_use = EADDRINUSE,
+ address_not_available = EADDRNOTAVAIL,
+ already_connected = EISCONN,
+ argument_out_of_domain = EDOM,
+ bad_address = EFAULT,
+ bad_file_descriptor = EBADF,
+ bad_message = EBADMSG,
+ broken_pipe = EPIPE,
+ connection_aborted = ECONNABORTED,
+ connection_already_in_progress = EALREADY,
+ connection_refused = ECONNREFUSED,
+ connection_reset = ECONNRESET,
+ cross_device_link = EXDEV,
+ destination_address_required = EDESTADDRREQ,
+ device_or_resource_busy = EBUSY,
+ directory_not_empty = ENOTEMPTY,
+ executable_format_error = ENOEXEC,
+ file_exists = EEXIST,
+ file_too_large = EFBIG,
+ filename_too_long = ENAMETOOLONG,
+ function_not_supported = ENOSYS,
+ host_unreachable = EHOSTUNREACH,
+ identifier_removed = EIDRM,
+ illegal_byte_sequence = EILSEQ,
+ inappropriate_io_control_operation = ENOTTY,
+ interrupted = EINTR,
+ invalid_argument = EINVAL,
+ invalid_seek = ESPIPE,
+ io_error = EIO,
+ is_a_directory = EISDIR,
+ message_size = EMSGSIZE,
+ network_down = ENETDOWN,
+ network_reset = ENETRESET,
+ network_unreachable = ENETUNREACH,
+ no_buffer_space = ENOBUFS,
+ no_child_process = ECHILD,
+ no_link = ENOLINK,
+ no_lock_available = ENOLCK,
+ no_message_available = ENODATA,
+ no_message = ENOMSG,
+ no_protocol_option = ENOPROTOOPT,
+ no_space_on_device = ENOSPC,
+ no_stream_resources = ENOSR,
+ no_such_device_or_address = ENXIO,
+ no_such_device = ENODEV,
+ no_such_file_or_directory = ENOENT,
+ no_such_process = ESRCH,
+ not_a_directory = ENOTDIR,
+ not_a_socket = ENOTSOCK,
+ not_a_stream = ENOSTR,
+ not_connected = ENOTCONN,
+ not_enough_memory = ENOMEM,
+ not_supported = ENOTSUP,
+ operation_canceled = ECANCELED,
+ operation_in_progress = EINPROGRESS,
+ operation_not_permitted = EPERM,
+ operation_not_supported = EOPNOTSUPP,
+ operation_would_block = EWOULDBLOCK,
+ owner_dead = EOWNERDEAD,
+ permission_denied = EACCES,
+ protocol_error = EPROTO,
+ protocol_not_supported = EPROTONOSUPPORT,
+ read_only_file_system = EROFS,
+ resource_deadlock_would_occur = EDEADLK,
+ resource_unavailable_try_again = EAGAIN,
+ result_out_of_range = ERANGE,
+ state_not_recoverable = ENOTRECOVERABLE,
+ stream_timeout = ETIME,
+ text_file_busy = ETXTBSY,
+ timed_out = ETIMEDOUT,
+ too_many_files_open_in_system = ENFILE,
+ too_many_files_open = EMFILE,
+ too_many_links = EMLINK,
+ too_many_symbolic_link_levels = ELOOP,
+ value_too_large = EOVERFLOW,
+ wrong_protocol_type = EPROTOTYPE,
+EOT
+
+${CXXCPP} -P -D_POSIX_C_SOURCE=200809L -x c++ "$constants_h" \
+ | sed -e '1,/^GLIBCXX ERROR CONSTANTS BELOW HERE$/d' \
+ >> "$output_h" || exit $?
+
+cat >> "$output_h" << EOT
+ };
+_GLIBCXX_END_NAMESPACE_VERSION
+} // namespace std
+#endif // C++11
+#endif // _GLIBCXX_ERRC_H
+EOT
+
+mv "$output_h" "$target"
+rm -r $dir
--
2.37.3
next reply other threads:[~2022-10-04 16:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-04 16:51 Jonathan Wakely [this message]
2022-10-04 18:05 ` Jonathan Wakely
2022-10-04 18:30 ` Jonathan Wakely
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=20221004165109.559028-1-jwakely@redhat.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@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).