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.133.124]) by sourceware.org (Postfix) with ESMTPS id 3F7093858D3C for ; Tue, 4 Oct 2022 16:51:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F7093858D3C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664902274; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=ZRjrabpLllbK70k+MR4xbF6jaKhtD2s3r4LVKqiH31Y=; b=aryqkmH9VBUvParVIsGJZC3eZ0p7EE9HRZUtmrY14ZoVd/KScz9CHliRZYYItEVY2KK7ci hV4vtHi5uxWMko8puj2xzYvjIg/N8ghFByvW9k9jZ4jGYf/J5y8h3BAh9uREHSnr7NsWS2 vIpxz/qi7O54j9KuF2I4dJgpg/D9dIc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-650-16sBeBJGMHaOBzEG5EMJ0Q-1; Tue, 04 Oct 2022 12:51:10 -0400 X-MC-Unique: 16sBeBJGMHaOBzEG5EMJ0Q-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5612C2999B37; Tue, 4 Oct 2022 16:51:10 +0000 (UTC) Received: from localhost (unknown [10.33.36.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AF231121314; Tue, 4 Oct 2022 16:51:09 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [RFC] libstdc++: Generate error_constants.h from [PR104883] Date: Tue, 4 Oct 2022 17:51:09 +0100 Message-Id: <20221004165109.559028-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,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 List-Id: 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 +// . + +/** @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" <) +#include +#endif +#include +#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