aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/acinclude.m4
AgeCommit message (Collapse)AuthorFilesLines
2024-07-31libstdc++: Handle encodings in localized chrono formatting [PR109162]Jonathan Wakely1-1/+1
This implements the C++23 paper P2419R2 (Clarify handling of encodings in localized formatting of chrono types). The requirement is that when the literal encoding is "a Unicode encoding form" and the formatting locale uses a different encoding, any locale-specific strings such as "août" for std::chrono::August should be converted to the literal encoding. Using the recently-added std::locale::encoding() function we can check the locale's encoding and then use iconv if a conversion is needed. Because nl_langinfo_l and iconv_open both allocate memory, a naive implementation would perform multiple allocations and deallocations for every snippet of locale-specific text that needs to be converted to UTF-8. To avoid that, a new internal locale::facet is defined to store the text_encoding and an iconv_t descriptor, which are then cached in the formatting locale. This requires access to the internals of a std::locale object in src/c++20/format.cc, so that new file needs to be compiled with -fno-access-control, as well as -std=gnu++26 in order to use std::text_encoding. Because the new std::text_encoding and std::locale::encoding() symbols are only in the libstdc++exp.a archive, we need to include src/c++26/text_encoding.cc in the main library, but not export its symbols yet. This means they can be used by the two new functions which are exported from the main library. The encoding conversions are done for C++20, treating it as a DR that resolves LWG 3656. With this change we can increase the value of the __cpp_lib_format macro for C++23. The value should be 202207 for P2419R2, but we already implement P2510R3 (Formatting pointers) so can use the value 202304. libstdc++-v3/ChangeLog: PR libstdc++/109162 * acinclude.m4 (libtool_VERSION): Update to 6:34:0. * config/abi/pre/gnu.ver: Disambiguate old patters. Add new GLIBCXX_3.4.34 symbol version and new exports. * configure: Regenerate. * include/bits/chrono_io.h (_ChronoSpec::_M_locale_specific): Add new accessor functions to use a reserved bit in _Spec. (__formatter_chrono::_M_parse): Use _M_locale_specific(true) when chrono-specs contains locale-dependent conversion specifiers. (__formatter_chrono::_M_format): Open iconv descriptor if conversion to UTF-8 will be needed. (__formatter_chrono::_M_write): New function to write a localized string with possible character conversion. (__formatter_chrono::_M_a_A, __formatter_chrono::_M_b_B) (__formatter_chrono::_M_p, __formatter_chrono::_M_r) (__formatter_chrono::_M_x, __formatter_chrono::_M_X) (__formatter_chrono::_M_locale_fmt): Use _M_write. * include/bits/version.def (format): Update value. * include/bits/version.h: Regenerate. * include/std/format (_GLIBCXX_P2518R3): Check feature test macro instead of __cplusplus. (basic_format_context): Declare __formatter_chrono as friend. * src/c++20/Makefile.am: Add new file. * src/c++20/Makefile.in: Regenerate. * src/c++20/format.cc: New file. * testsuite/std/time/format_localized.cc: New test. * testsuite/util/testsuite_abi.cc: Add new symbol version.
2024-05-17libstdc++: detect DLLs on windows with <stacktrace>Björn Schäpers1-0/+5
libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_BACKTACE): Add check for tlhelp32.h, matching libbacktrace. * config.h.in: Regenerate. * configure: Regenerate. Signed-off-by: Björn Schäpers <bjoern@hazardy.de>
2024-04-02Fix up duplicated words mostly in comments, part 1Jakub Jelinek1-1/+1
Like in r12-7519-g027e30414492d50feb2854aff38227b14300dc4b, I've done git grep -v 'long long\|optab optab\|template template\|double double' | grep ' \([a-zA-Z]\+\) \1 ' This is just part of the changes, mostly for non-gcc directories. I'll try to get to the rest soon. Obviously, the above command also finds cases which are correct as is and shouldn't be changed, so one needs to manually inspect everything. I'd hope most of it is pretty obvious, but the config/ and libstdc++-v3/ hunks include a tweak in a license wording, though other copies of the similar license have the wording right. 2024-04-02 Jakub Jelinek <jakub@redhat.com> * Makefile.tpl: Fix duplicated words; returns returns -> returns. config/ * lcmessage.m4: Fix duplicated words; can can -> can, package package -> package. libdecnumber/ * decCommon.c (decFinalize): Fix duplicated words in comment; the the -> the. libgcc/ * unwind-dw2-fde.c (struct fde_accumulator): Fix duplicated words in comment; is is -> is. libgfortran/ * configure.host: Fix duplicated words; the the -> the. libgm2/ * configure.host: Fix duplicated words; the the -> the. libgomp/ * libgomp.texi (OpenMP 5.2): Fix duplicated words; with with -> with. (omp_target_associate_ptr): Fix duplicated words; either either -> either. (omp_init_allocator): Fix duplicated words; be be -> be. (omp_realloc): Fix duplicated words; is is -> is. (OMP_ALLOCATOR): Fix duplicated words; other other -> other. * priority_queue.h (priority_queue_multi_p): Fix duplicated words; to to -> to. libiberty/ * regex.c (byte_re_match_2_internal): Fix duplicated words in comment; next next -> next. * dyn-string.c (dyn_string_init): Fix duplicated words in comment; of of -> of. libitm/ * beginend.cc (GTM::gtm_thread::begin_transaction): Fix duplicated words in comment; not not -> not to. libobjc/ * init.c (duplicate_classes): Fix duplicated words in comment; in in -> in. * sendmsg.c (__objc_prepare_dtable_for_class): Fix duplicated words in comment; the the -> the. * encoding.c (objc_layout_structure): Likewise. libstdc++-v3/ * acinclude.m4: Fix duplicated words; file file -> file can. * configure.host: Fix duplicated words; the the -> the. libvtv/ * vtv_rts.cc (vtv_fail): Fix duplicated words; to to -> to. * vtv_fail.cc (vtv_fail): Likewise.
2024-01-31libstdc++: Enable std::text_encoding for darwin and FreeBSDJonathan Wakely1-0/+3
The <xlocale.h> header is needed for newlocale and locale_t on these targets. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_TEXT_ENCODING): Use <xlocale.h> if needed for newlocale. * configure: Regenerate. * src/c++26/text_encoding.cc: Use <xlocale.h>. Reviewed-by: Iain Sandoe <iain@sandoe.co.uk>
2024-01-17libstdc++: Implement C++26 std::text_encoding (P1885R12) [PR113318]Jonathan Wakely1-1/+29
This is another C++26 change, approved in Varna 2023. We require a new static array of data that is extracted from the IANA Character Sets database. A new Python script to generate a header from the IANA CSV file is added. The text_encoding class is basically just a pointer to an {ID,name} pair in the static array. The aliases view is also just the same pointer (or empty), and the view's iterator moves forwards and backwards in the array while the array elements have the same ID (or to one element further, for a past-the-end iterator). Because those iterators refer to a global array that never goes out of scope, there's no reason they should every produce undefined behaviour or indeterminate values. They should either have well-defined behaviour, or abort. The overhead of ensuring those properties is pretty low, so seems worth it. This means that an aliases_view iterator should never be able to access out-of-bounds. A non-value-initialized iterator always points to an element of the static array even when not dereferenceable (the array has unreachable entries at the start and end, which means that even a past-the-end iterator for the last encoding in the array still points to valid memory). Dereferencing an iterator can always return a valid array element, or "" for a non-dereferenceable iterator (but doing so will abort when assertions are enabled). In the language being proposed for C++26, dereferencing an invalid iterator erroneously returns "". Attempting to increment/decrement past the last/first element in the view is erroneously a no-op, so aborts when assertions are enabled, and doesn't change value otherwise. Similarly, constructing a std::text_encoding with an invalid id (one that doesn't have the value of an enumerator) erroneously behaves the same as constructing with id::unknown, or aborts with assertions enabled. libstdc++-v3/ChangeLog: PR libstdc++/113318 * acinclude.m4 (GLIBCXX_CONFIGURE): Add c++26 directory. (GLIBCXX_CHECK_TEXT_ENCODING): Define. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Use GLIBCXX_CHECK_TEXT_ENCODING. * include/Makefile.am: Add new headers. * include/Makefile.in: Regenerate. * include/bits/locale_classes.h (locale::encoding): Declare new member function. * include/bits/unicode.h (__charset_alias_match): New function. * include/bits/text_encoding-data.h: New file. * include/bits/version.def (text_encoding): Define. * include/bits/version.h: Regenerate. * include/std/text_encoding: New file. * src/Makefile.am: Add new subdirectory. * src/Makefile.in: Regenerate. * src/c++26/Makefile.am: New file. * src/c++26/Makefile.in: New file. * src/c++26/text_encoding.cc: New file. * src/experimental/Makefile.am: Include c++26 convenience library. * src/experimental/Makefile.in: Regenerate. * python/libstdcxx/v6/printers.py (StdTextEncodingPrinter): New printer. * scripts/gen_text_encoding_data.py: New file. * testsuite/22_locale/locale/encoding.cc: New test. * testsuite/ext/unicode/charset_alias_match.cc: New test. * testsuite/std/text_encoding/cons.cc: New test. * testsuite/std/text_encoding/members.cc: New test. * testsuite/std/text_encoding/requirements.cc: New test. Reviewed-by: Ulrich Drepper <drepper.fsp@gmail.com> Reviewed-by: Patrick Palka <ppalka@redhat.com>
2023-12-14libstdc++: Fix filebuf::native_handle() for WindowsJonathan Wakely1-1/+2
libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES): Add missing header to configure test. Check correct variable. * config/io/basic_file_stdio.cc (__basic_file<char>::native_handle): Fix typo. * configure: Regenerate. * testsuite/27_io/basic_filebuf/native_handle/char/1.cc: Do not call CloseHandle on the native handle. * testsuite/27_io/basic_filebuf/native_handle/wchar_t/1.cc: Likewise.
2023-11-06libstdc++: use -D_GNU_SOURCE when building libbacktraceIan Lance Taylor1-1/+4
PR libbacktrace/111315 PR libbacktrace/112263 * acinclude.m4: Set -D_GNU_SOURCE in BACKTRACE_CPPFLAGS and when grepping link.h for dl_iterate_phdr. * configure: Regenerate.
2023-11-02libstdc++: Fix warning during configureJonathan Wakely1-2/+2
The checks for snprintf give a -Wformat warning due to a missing argument. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_C99): Fix snprintf checks. * configure: Regenerate.
2023-09-15libstdc++: Implement C++26 native handles for file streams (P1759R6)Jonathan Wakely1-0/+31
The new __basic_file::native_handle() function can be added for C++11 and above, because the names "native_handle" and "native_handle_type" are already reserved since C++11. Exporting those symbols from the shared library does no harm, even if the feature gets dropped before the C++23 standard is final. The new member functions of std::fstream etc. are only declared for C++26 and so are not instantiated in src/c++11/fstream-inst.cc. Declare them with the always_inline attribute so that no symbol definitions are needed in the library (we can change this later when C++26 support is less experimental). libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES): New macro. * config.h.in: Regenerate. * config/abi/pre/gnu.ver (GLIBCXX_3.4.32): Export new basic_filebuf members. * config/io/basic_file_stdio.cc (__basic_file::native_handle): Define new function. * config/io/basic_file_stdio.h (__basic_file::native_handle): Declare new function. * configure: Regenerate. * configure.ac: Use GLIBCXX_CHECK_FILEBUF_NATIVE_HANDLES. * include/bits/version.def (fstream_native_handles): New macro. * include/bits/version.h: Regenerate. * include/std/fstream (basic_filebuf::native_handle) (basic_fstream::native_handle, basic_ifstream::native_handle) (basic_ofstream::native_handle): New functions. * src/c++11/Makefile.am: Move compilation of basic_file.cc, locale_init.cc and localename.cc to here. * src/c++11/Makefile.in: Regenerate. * src/c++98/locale_init.cc: Moved to... * src/c++11/locale_init.cc: ...here. * src/c++98/localename.cc: Moved to... * src/c++11/localename.cc: ...here. * src/c++98/Makefile.am: Remove basic_file.cc, locale_init.cc and localename.cc from here. * src/c++98/Makefile.in: Regenerate. * testsuite/27_io/basic_filebuf/native_handle/version.cc: New test. * testsuite/27_io/basic_fstream/native_handle/char/1.cc: New test. * testsuite/27_io/basic_fstream/native_handle/wchar_t/1.cc: New test. * testsuite/27_io/basic_ifstream/native_handle/char/1.cc: New test. * testsuite/27_io/basic_ifstream/native_handle/wchar_t/1.cc: New test. * testsuite/27_io/basic_ofstream/native_handle/char/1.cc: New test. * testsuite/27_io/basic_ofstream/native_handle/wchar_t/1.cc: New test.
2023-09-08libstdc++: Add Filesystem TS and std::stacktrace symbols to libstdc++exp.aJonathan Wakely1-1/+1
This consolidates the three static archives for extensions into one, so that -lstdc++exp can be used to provide the definitions of all unstable library features. The libstdc++_libbacktrace.a archive is now just a "noinst" convenience library that is only used during the build, not installed. Its contents are added to libstdc++exp.a, along with the new non-inline definitions of std::stacktrace symbols. The libstdc++fs.a archive is still installed, but its contents are duplicated in libstdc++exp.a now. This means -lstdc++exp can be used instead of -lstdc++fs. For targets using the GNU linker we should consider replacing libstdc++fs.a with a linker script that does INPUT(libstdc++exp.a). The tests for <experimental/filesystem> could be changed to use -lstdc++exp instead of -lstdc++fs, which would allow removing src/filesystem/.libs from the LDFLAGS in scripts/testsuite_flags.in, but that can be done at a later date. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CONFIGURE): Add c++23 directory. * configure: Regenerate. * doc/html/manual/*: Regenerate. * doc/xml/manual/using.xml: Update documentation on linking. * include/std/stacktrace: Remove declarations of libbacktrace APIs. (stacktrace_entry::_S_err_handler, stacktrace_entry::_S_init): Remove. (stacktrace_entry::_Info): New class. (stacktrace_entry::_M_get_info): Use _Info. (__stacktrace_impl): New class. (basic_stacktrace): Derive from __stacktrace_impl. (basic_stacktrace::current): Use __stacktrace_impl::_S_current. * scripts/testsuite_flags.in: Adjust LDFLAGS to find libstdc++exp instead of libstdc++_libbacktrace. * src/Makefile.am (SUBDIRS): Add c++23 directory. * src/Makefile.in: Regenerate. * src/c++20/Makefile.am: Fix comment. * src/c++20/Makefile.in: Regenerate. * src/c++23/Makefile.am: New file. * src/c++23/Makefile.in: New file. * src/c++23/stacktrace.cc: New file with definitions of stacktrace_entry::_Info and __stacktrace_impl members. * src/experimental/Makefile.am: Use LIBADD to include other libraries. * src/experimental/Makefile.in: Regenerate. * src/libbacktrace/Makefile.am: Use noinst_LTLIBRARIES. * src/libbacktrace/Makefile.in: Regenerate. * testsuite/19_diagnostics/stacktrace/current.cc: Adjust dg-options to use -lstdc++exp. * testsuite/19_diagnostics/stacktrace/entry.cc: Likewise. * testsuite/19_diagnostics/stacktrace/stacktrace.cc: Likewise. * testsuite/23_containers/vector/debug/assign4_backtrace_neg.cc: Likewise.
2023-09-07libstdc++: Update docbook xsl URIBruno Victal1-1/+1
The URI for namespaced docbook-xsl was updated to reflect the current DocBook upstream at <https://cdn.docbook.org/>. libstdc++-v3/Changelog: * acinclude.m4: Update docbook xsl URI. * configure: Regenerate.
2023-09-07libstdc++: Add autoconf checks for mkdir, chmod, chdir, and getcwdJonathan Wakely1-0/+60
The filesystem code was using these functions without checking for their existence, assuming that any UNIX-like libc with <unistd.h> would always provide them. That's not true for some newlib targets like arm-eabi. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for mkdir, chmod, chdir, and getcwd. * config.h.in: Regenerate. * configure: Regenerate. * src/c++17/fs_ops.cc (create_dir): Use USE_MKDIR macro. (fs::current_path): Use USE_GETCWD and USE_CHDIR macros. (fs::permissions): Use USE_CHMOD macro. * src/filesystem/ops-common.h [FILESYSTEM_IS_WINDOWS] (chmod, mkdir, getcwd, chdir): Define new macros. [FILESYSTEM_IS_WINDOWS] (chmod, mkdir, getcwd, chdir): Use new macros. * src/filesystem/ops.cc (create_dir): Use USE_MKDIR macro. (fs::current_path): Use USE_GETCWD and USE_CHDIR macros. (fs::permissions): Use USE_CHMOD macro.
2023-09-07libstdc++: Disable <stacktrace> support by default for avrJonathan Wakely1-1/+4
libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): Disable by default for avr. * configure: Regenerate.
2023-09-06libstdc++: Disable <stacktrace> support by default for freestandingJonathan Wakely1-1/+1
libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): Disable by default for freestanding. * configure: Regenerate.
2023-09-01libstdc++: Make --enable-libstdcxx-backtrace=auto default to yesJonathan Wakely1-1/+1
This causes libstdc++_libbacktrace.a to be built by default. This might fail on some targets, in which case we can make the 'auto' choice expand to either 'yes' or 'no' depending on the target. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): Default to yes. * configure: Regenerate.
2023-07-12libstdc++: Fix --enable-cstdio=stdio_pure [PR110574]Jonathan Wakely1-0/+16
When configured with --enable-cstdio=stdio_pure we need to consistently use fseek and not mix seeks on the file descriptor with reads and writes on the FILE stream. There are also a number of bugs related to error handling and return values, because fread and fwrite return 0 on error, not -1, and fseek returns 0 on success, not the file offset. libstdc++-v3/ChangeLog: PR libstdc++/110574 * acinclude.m4 (GLIBCXX_CHECK_LFS): Check for fseeko and ftello and define _GLIBCXX_USE_FSEEKO_FTELLO. * config.h.in: Regenerate. * configure: Regenerate. * config/io/basic_file_stdio.cc (xwrite) [_GLIBCXX_USE_STDIO_PURE]: Check for fwrite error correctly. (__basic_file<char>::xsgetn) [_GLIBCXX_USE_STDIO_PURE]: Check for fread error correctly. (get_file_offset): New function. (__basic_file<char>::seekoff) [_GLIBCXX_USE_STDIO_PURE]: Use fseeko if available. Use get_file_offset instead of return value of fseek. (__basic_file<char>::showmanyc): Use get_file_offset.
2023-06-30libstdc++: Fix iostream init for Clang on darwin [PR110432]Jonathan Wakely1-0/+27
The __has_attribute(init_priority) check in <iostream> is true for Clang on darwin, which means that user code including <iostream> thinks the library will initialize the global streams. However, when libstdc++ is built by GCC on darwin, the __has_attribute(init_priority) check is false, which means that the library thinks that user code will do the initialization when <iostream> is included. This means that the initialization is never done. Add an autoconf check so that the header and the library both make their decision based on the static properties of GCC at build time, with a consistent outcome. As a belt and braces check, also do the initialization in <iostream> if the compiler including that header doesn't support the attribute (even if the library also containers the initialization). This might result in redundant initialization done in <iostream>, but ensures the initialization happens somewhere if there's any doubt about the attribute working correctly due to missing linker support. libstdc++-v3/ChangeLog: PR libstdc++/110432 * acinclude.m4 (GLIBCXX_CHECK_INIT_PRIORITY): New. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Use GLIBCXX_CHECK_INIT_PRIORITY. * include/std/iostream: Use new autoconf macro as well as __has_attribute. * src/c++98/ios_base_init.h: Use new autoconf macro instead of __has_attribute. Reviewed-by: Patrick Palka <ppalka@redhat.com>
2023-06-29libstdc++: Do not use off64_t in calls to copy_file_range [PR110462]Jonathan Wakely1-1/+1
Although the copy_file_range(2) man page shows the arguments as off64_t* that is not portable. For musl there is no off64_t type, as off_t is always 64-bit. Use the loff_t type which is always 64-bit even if off_t isn't. We could just use off_t because the filesystem library is compiled with _FILE_OFFSET_BITS=64, but loff_t is the more correct type for this interface. libstdc++-v3/ChangeLog: PR libstdc++/110462 * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check that copy_file_range can be called with loff_t* arguments. * configure: Regenerate. * src/filesystem/ops-common.h (copy_file_copy_file_range): Use loff_t for offsets.
2023-06-09libstdc++: Bump library version to libstdc++.so.6.0.33Jonathan Wakely1-1/+1
The addition of __cxa_call_terminate@@CXXABI_1.3.15 on trunk means we need a new version. libstdc++-v3/ChangeLog: * acinclude.m4 (libtool_VERSION): Update to 6.0.33. * configure: Regenerate. * doc/xml/manual/abi.xml: Add libstdc++.so.6.0.33. * doc/html/manual/abi.html: Regenerate.
2023-06-06libstdc++: Use copy_file_range for filesystem::copy_fileJannik Glückert1-0/+20
copy_file_range is a recent-ish syscall for copying files. It is similar to sendfile but allows filesystem-specific optimizations. Common are: Reflinks: BTRFS, XFS, ZFS (does not implement the syscall yet) Server-side copy: NFS, SMB, Ceph If copy_file_range is not available for the given files, fall back to sendfile / userspace copy. libstdc++-v3/ChangeLog: * acinclude.m4 (_GLIBCXX_USE_COPY_FILE_RANGE): Define. * config.h.in: Regenerate. * configure: Regenerate. * src/filesystem/ops-common.h (copy_file_copy_file_range): Define new function. (do_copy_file): Use it. Signed-off-by: Jannik Glückert <jannik.glueckert@gmail.com>
2023-06-06libstdc++: Also use sendfile for big filesJannik Glückert1-19/+32
We were previously only using sendfile for files smaller than 2GB, as sendfile needs to be called repeatedly for files bigger than that. Some quick numbers, copying a 16GB file, average of 10 repetitions: old: real: 13.4s user: 0.14s sys : 7.43s new: real: 8.90s user: 0.00s sys : 3.68s libstdc++-v3/ChangeLog: * acinclude.m4 (_GLIBCXX_HAVE_LSEEK): Define. * config.h.in: Regenerate. * configure: Regenerate. * src/filesystem/ops-common.h (copy_file_sendfile): Define new function for sendfile logic. Loop to support large files. Skip zero-length files. (do_copy_file): Use it. Signed-off-by: Jannik Glückert <jannik.glueckert@gmail.com>
2023-05-31libstdc++: Add separate autoconf macro for std::float_t and std::double_t ↵Jonathan Wakely1-3/+18
[PR109818] This should make it possible to use openlibm with djgpp (and other targets with missing C99 <math.h> functions). The <math.h> from openlibm provides all the functions, but not the float_t and double_t typedefs. By separating the autoconf checks for the functionsand the typedefs, we don't disable support for all the functions just because those typedefs are not present. libstdc++-v3/ChangeLog: PR libstdc++/109818 * acinclude.m4 (GLIBCXX_ENABLE_C99): Add separate check for float_t and double_t and define HAVE_C99_FLT_EVAL_TYPES. * config.h.in: Regenerate. * configure: Regenerate. * include/c_global/cmath (float_t, double_t): Guard using new _GLIBCXX_HAVE_C99_FLT_EVAL_TYPES macro.
2023-05-31libstdc++: Stop using _GLIBCXX_USE_C99_MATH_TR1 in <cmath>Jonathan Wakely1-25/+158
Similar to the three commits r14-908, r14-909 and r14-910, the _GLIBCXX_USE_C99_MATH_TR1 macro is misleading when it is also used for <cmath>, not only for <tr1/cmath> headers. It is also wrong, because the configure checks for TR1 use -std=c++98 and a target might define the C99 features for C++11 but not for C++98. Add separate configure checks for the <math.h> functions using -std=c++11 for the checks. Use the new macro defined by those checks in the C++11-specific parts of <cmath>, and in <complex>, <random> etc. The check that defines _GLIBCXX_NO_C99_ROUNDING_FUNCS is only needed for the C++11 <cmath> checks, so remove that from GLIBCXX_CHECK_C99_TR1 and only do it for GLIBCXX_ENABLE_C99. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_C99): Add checks for C99 math functions and define _GLIBCXX_USE_C99_MATH_FUNCS. Move checks for C99 rounding functions to here. (GLIBCXX_CHECK_C99_TR1): Remove checks for C99 rounding functions from here. * config.h.in: Regenerate. * configure: Regenerate. * include/bits/random.h: Use _GLIBCXX_USE_C99_MATH_FUNCS instead of _GLIBCXX_USE_C99_MATH_TR1. * include/bits/random.tcc: Likewise. * include/c_compatibility/math.h: Likewise. * include/c_global/cmath: Likewise. * include/ext/random: Likewise. * include/ext/random.tcc: Likewise. * include/std/complex: Likewise. * testsuite/20_util/from_chars/4.cc: Likewise. * testsuite/20_util/from_chars/8.cc: Likewise. * testsuite/26_numerics/complex/proj.cc: Likewise. * testsuite/26_numerics/headers/cmath/60401.cc: Likewise. * testsuite/26_numerics/headers/cmath/types_std_c++0x.cc: Likewise. * testsuite/lib/libstdc++.exp (check_v3_target_cstdint): Likewise. * testsuite/util/testsuite_random.h: Likewise.
2023-05-31libstdc++: Fix configure test for 32-bit targetsJonathan Wakely1-1/+1
The -mlarge model for msp430-elf uses 20-bit pointers, which means that sizeof(void*) == 4 and so the r14-1432-g51cf0b3949b88b change gives the wrong answer. Check __INTPTR_WIDTH__ >= 32 instead. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ZONEINFO_DIR): Fix for 32-bit pointers to check __INT_PTR_WIDTH__ instead of sizeof(void*). * configure: Regenerate.
2023-05-31libstdc++: Disable embedded tzdata for all 16-bit targetsJonathan Wakely1-6/+9
libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ZONEINFO_DIR): Extend logic for avr and msp430 to all 16-bit targets. * configure: Regenerate.
2023-05-16libstdc++: Disable cacheline alignment for DJGPP [PR109741]Jonathan Wakely1-0/+25
DJGPP (and maybe other targets) uses MAX_OFILE_ALIGNMENT=16 which means that globals (and static objects) can't have alignment greater than 16. This causes an error for the locks defined in src/c++11/shared_ptr.cc because we try to align them to the cacheline size, to avoid false sharing. Add a configure check for the increased alignment, and live with false sharing where we can't increase the alignment. libstdc++-v3/ChangeLog: PR libstdc++/109741 * acinclude.m4 (GLIBCXX_CHECK_ALIGNAS_CACHELINE): Define. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Use GLIBCXX_CHECK_ALIGNAS_CACHELINE. * src/c++11/shared_ptr.cc (__gnu_internal::get_mutex): Do not align lock table if not supported. use __GCC_DESTRUCTIVE_SIZE instead of hardcoded 64.
2023-05-16libstdc++: Stop using TR1 macros in <cctype> and <cfenv>Jonathan Wakely1-0/+46
As with the two commits before this, the _GLIBCXX_USE_C99_CTYPE_TR1 and _GLIBCXX_USE_C99_FENV_TR1 macros are misleading when they are also used for <cctype> and <cfenv>, not only for TR1 headers. It is also wrong, because the configure checks for TR1 use -std=c++98 and a target might define the C99 features for C++11 but not for C++98. Add separate configure checks for the <ctype.h> and <fenv.h> features using -std=c++11 for the checks. Use the new macros defined by those checks in the C++11-specific parts of <cctype>, <cfenv>, and <fenv.h>. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_USE_C99): Check for isblank in C++11 mode and define _GLIBCXX_USE_C99_CTYPE. Check for <fenv.h> functions in C++11 mode and define _GLIBCXX_USE_C99_FENV. * config.h.in: Regenerate. * configure: Regenerate. * include/c_compatibility/fenv.h: Check _GLIBCXX_USE_C99_FENV instead of _GLIBCXX_USE_C99_FENV_TR1. * include/c_global/cfenv: Likewise. * include/c_global/cctype: Check _GLIBCXX_USE_C99_CTYPE instead of _GLIBCXX_USE_C99_CTYPE_TR1.
2023-05-16libstdc++: Stop using _GLIBCXX_USE_C99_STDINT_TR1 in <cstdint>Jonathan Wakely1-0/+142
The _GLIBCXX_USE_C99_STDINT_TR1 macro (and the comments about it in acinclude.m4 and config.h) are misleading when it is also used for <stdint>, not only <tr1/stdint>. It is also wrong, because the configure checks for TR1 use -std=c++98 and a target might define uint32_t etc. for C++11 but not for C++98. Add a separate configure check for the <stdint.h> types using -std=c++11 for the checks. Use the result of that separate check in <cstdint> and most other places that still depend on the macro (many uses of that macro have been removed already). The remaining uses of the STDINT_TR1 macro are really for TR1, or are in the src/c++11/compatibility-*.cc files, where we don't want/need to change the condition they depend on (if those symbols were only exported when <stdint.h> types were available for -std=c++98, then that's the condition we should continue to use for whether to export the compat symbols now). Make similar changes for the related _GLIBCXX_USE_C99_INTTYPES_TR1 and _GLIBCXX_USE_C99_INTTYPES_WCHAR_T_TR1 macros, adding new macros for non-TR1 uses. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_USE_C99): Check for <stdint.h> types in C++11 mode and define _GLIBCXX_USE_C99_STDINT. Check for <inttypes.h> features in C++11 mode and define _GLIBCXX_USE_C99_INTTYPES and _GLIBCXX_USE_C99_INTTYPES_WCHAR_T. * config.h.in: Regenerate. * configure: Regenerate. * doc/doxygen/user.cfg.in (PREDEFINED): Add new macros. * include/bits/chrono.h: Check _GLIBCXX_USE_C99_STDINT instead of _GLIBCXX_USE_C99_STDINT_TR1. * include/c_compatibility/inttypes.h: Check _GLIBCXX_USE_C99_INTTYPES and _GLIBCXX_USE_C99_INTTYPES_WCHAR_T instead of _GLIBCXX_USE_C99_INTTYPES_TR1 and _GLIBCXX_USE_C99_INTTYPES_WCHAR_T_TR1. * include/c_compatibility/stdatomic.h: Check _GLIBCXX_USE_C99_STDINT instead of _GLIBCXX_USE_C99_STDINT_TR1. * include/c_compatibility/stdint.h: Likewise. * include/c_global/cinttypes: Check _GLIBCXX_USE_C99_INTTYPES and _GLIBCXX_USE_C99_INTTYPES_WCHAR_T instead of _GLIBCXX_USE_C99_INTTYPES_TR1 and _GLIBCXX_USE_C99_INTTYPES_WCHAR_T_TR1. * include/c_global/cstdint: Check _GLIBCXX_USE_C99_STDINT instead of _GLIBCXX_USE_C99_STDINT_TR1. * include/std/atomic: Likewise. * src/c++11/cow-stdexcept.cc: Likewise. * testsuite/29_atomics/headers/stdatomic.h/c_compat.cc: Likewise. * testsuite/lib/libstdc++.exp (check_v3_target_cstdint): Likewise.
2023-05-16libstdc++: Stop using _GLIBCXX_USE_C99_COMPLEX_TR1 in <complex>Jonathan Wakely1-0/+37
The _GLIBCXX_USE_C99_COMPLEX_TR1 macro (and the comments about it in acinclude.m4 and config.h) are misleading when it is also used for <complex>, not only <tr1/complex>. It is also wrong, because the configure checks for TR1 use -std=c++98 and a target might define cacos etc. for C++11 but not for C++98. Add a separate configure check for the inverse trigonometric functions that are covered by _GLIBCXX_USE_C99_COMPLEX_TR1, but using -std=c++11 for the checks. Use the result of that separate check in <complex>. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_USE_C99): Check for complex inverse trig functions in C++11 mode and define _GLIBCXX_USE_C99_COMPLEX_ARC. * config.h.in: Regenerate. * configure: Regenerate. * doc/doxygen/user.cfg.in (PREDEFINED): Add new macro. * include/std/complex: Check _GLIBCXX_USE_C99_COMPLEX_ARC instead of _GLIBCXX_USE_C99_COMPLEX_TR1.
2023-05-16libstdc++: Do not use pthread_mutex_clocklock with ThreadSanitizerJonathan Wakely1-1/+1
As noted in https://github.com/llvm/llvm-project/issues/62623 there are no tsan interceptors for some of the new POSIX-1:202x APIs added by https://austingroupbugs.net/view.php?id=1216 so tsan gives false positive warnings for try_lock_for on timed mutexes. Disable the uses of the new pthread_mutex_clocklock API when tsan is active. This changes the semantics of the try_lock_for functions, because it can change which clock is used for the wait. This means those functions might be affected by system clock adjustments when tsan is used, when they would not be affected otherwise. Reviewed-by: Thomas Rodgers <trodgers@redhat.com> Reviewed-by: Mike Crowe <mac@mcrowe.com> libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK): Define _GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK in terms of _GLIBCXX_TSAN. * configure: Regenerate.
2023-05-12libstdc++: Fix -Wnonnull warnings during configureJonathan Wakely1-4/+4
We should not test for nan by passing it a null pointer, as this can trigger -Wnonnull warnings. Also fix an outdated comment about the default -std mode. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_C99_TR1): Use a non-null pointer to check for nan, nanf, and nanl. * configure: Regenerate.
2023-04-28libstdc++: Another attempt to ensure g++ 13+ compiled programs enforce gcc ↵Jakub Jelinek1-1/+1
13.2+ libstdc++.so.6 [PR108969] GCC used to emit an instance of an empty ios_base::Init class in every TU which included <iostream> to ensure it is std::cout etc. is initialized, but thanks to Patrick work on some targets (which have init_priority attribute support) it is now initialized only inside of libstdc++.so.6/libstdc++.a. This causes a problem if people do something that has never been supported, try to run GCC 13 compiled C++ code against GCC 12 or earlier libstdc++.so.6 - std::cout etc. are then never initialized because code including <iostream> expects the library to initialize it and the library expects code including <iostream> to do that. The following patch is second attempt to make this work cheaply as the earlier attempt of aliasing the std::cout etc. symbols with another symbol version didn't work out due to copy relocation breaking the aliases appart. The patch forces just a _ZSt21ios_base_library_initv undefined symbol into all *.o files which include <iostream> and while there is no runtime relocation against that, it seems to enforce the right version of libstdc++.so.6. /home/jakub/src/gcc/obj08i/usr/local/ is the install directory of trunk patched with this patch, /home/jakub/src/gcc/obj06/ is builddir of trunk without this patch, system g++ is GCC 12.1.1. $ cat /tmp/hw.C #include <iostream> int main () { std::cout << "Hello, world!" << std::endl; } $ cd /home/jakub/src/gcc/obj08i/usr/local/bin $ ./g++ -o /tmp/hw /tmp/hw.C $ readelf -Wa /tmp/hw 2>/dev/null | grep initv 4: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZSt21ios_base_library_initv@GLIBCXX_3.4.32 (4) 71: 0000000000000000 0 FUNC GLOBAL DEFAULT UND _ZSt21ios_base_library_initv@GLIBCXX_3.4.32 $ /tmp/hw /tmp/hw: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by /tmp/hw) $ LD_LIBRARY_PATH=/home/jakub/src/gcc/obj08i/usr/local/lib64/ /tmp/hw Hello, world! $ LD_LIBRARY_PATH=/home/jakub/src/gcc/obj06/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/ /tmp/hw /tmp/hw: /home/jakub/src/gcc/obj06/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/libstdc++.so.6: version `GLIBCXX_3.4.32' not found (required by /tmp/hw) $ g++ -o /tmp/hw /tmp/hw.C $ /tmp/hw Hello, world! $ LD_LIBRARY_PATH=/home/jakub/src/gcc/obj06/x86_64-pc-linux-gnu/libstdc++-v3/src/.libs/ /tmp/hw Hello, world! $ LD_LIBRARY_PATH=/home/jakub/src/gcc/obj08i/usr/local/lib64/ /tmp/hw Hello, world! On sparc-sun-solaris2.11 one I've actually checked a version which had defined(_GLIBCXX_SYMVER_SUN) next to defined(_GLIBCXX_SYMVER_GNU), but init_priority attribute doesn't seem to be supported there and so I couldn't actually test how this works there. Using gas and Sun ld, Rainer, does one need to use gas + gld for init_priority or something else? 2023-04-28 Jakub Jelinek <jakub@redhat.com> PR libstdc++/108969 * config/abi/pre/gnu.ver (GLIBCXX_3.4.32): Export _ZSt21ios_base_library_initv. * testsuite/util/testsuite_abi.cc (check_version): Add GLIBCXX_3.4.32 symver and make it the latestp. * src/c++98/ios_init.cc (ios_base_library_init): New alias. * acinclude.m4 (libtool_VERSION): Change to 6:32:0. * include/std/iostream: If init_priority attribute is supported and _GLIBCXX_SYMVER_GNU, force undefined _ZSt21ios_base_library_initv symbol into the object. * configure: Regenerated.
2023-02-01libstdc++: Do not embed tzdata.zi for 8-bit and 16-bit targetsJonathan Wakely1-2/+6
The string literal containing the static tzdata.zi information is too large for some targets, so do not enable it by default for avr-*-* and msp430-*-*. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ZONEINFO_DIR) [avr-*-*, msp430-*-*]: Set embed_zoneinfo=no * configure: Regenerate.
2023-01-17libstdc++: Fix configuration of default zoneinfo dir on linuxJonathan Wakely1-4/+4
The config for --with-libstdcxx-zoneinfo=yes was comparing the target triplet to "gnu* | linux* | kfreebsd*-gnu | knetbsd*-gnu" which is only the last component of the triplet, so failed to match and always used the zoneinfo_dir=none default. Check $target_os instead. There was also an error in the check for native builds that tzdata.zi is actually present in the configured directory. That meant a warning was printed even when the file was present: configure: zoneinfo data directory: /usr/share/zoneinfo configure: WARNING: "/usr/share/zoneinfo does not contain tzdata.zi file" configure: static tzdata.zi file will be compiled into the library libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ZONEINFO_DIR): Check $target_os instead of $host. Fix check for file being present during native build. * configure: Regenerate.
2023-01-14libstdc++: enable <stacktrace> on windowsBjörn Schäpers1-0/+2
libstdc++-v3/Changelog * acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): Add check for windows.h. Add pecoff as FORMAT_FILE. * config.h.in: Regenerate. * configure: Regenerate. * src/libbacktrace/Makefile.am: Regenerate. * src/libbacktrace/Makefile.in: Add pecoff.c as FORMAT_FILE. Signed-off-by: Björn Schäpers <bjoern@hazardy.de>
2023-01-14libstdc++: Embed a static copy of tzdata.ziJonathan Wakely1-14/+73
This adds a copy of the tzdata.zi file to the library, and allows configuring to use it instead of a copy read from disk at runtime. The content of the file is in the public domain, but will need to be updated to the latest upstream file before making GCC releases. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ZONEINFO_DIR): Replace the --with-libstdcxx-zoneinfo-dir configure option with --with-libstdcxx-zoneinfo with yes/no/static choices as well as a directory. * config.h.in: Regenerate. * configure: Regenerate. * doc/xml/manual/configure.xml: Document configure option. * doc/html/manual/configure.html: Regenerate. * src/c++20/Makefile.am: Generate tzdata.zi.h header. * src/c++20/Makefile.in: Regenerate. * src/c++20/tzdb.cc (__gnu_cxx::zoneinfo_dir_override): Return a null pointer if no directory is configured. (zoneinfo_dir): Replace with ... (zoneinfo_file): New function. (tzdata_stream): New istream class. (remote_version, reload_tzdb): Use tzdata_stream. * testsuite/lib/libstdc++.exp (check_effective_target_tzdb): Check new _GLIBCXX_STATIC_TZDATA macro and ignore presence of tzdata.zi file in default location. * src/c++20/tzdata.zi: New file.
2022-12-23Reimplement GNU threads library on native WindowsEric Botcazou1-14/+28
This reimplements the GNU threads library on native Windows (except for the Objective-C specific subset) using direct Win32 API calls, in lieu of the implementation based on semaphores. This base implementations requires Windows XP/Server 2003, which was the default minimal setting of MinGW-W64 until end of 2020. This also adds the support required for the C++11 threads, using again direct Win32 API calls; this additional layer requires Windows Vista/Server 2008 and is enabled only if _WIN32_WINNT >= 0x0600. This also changes libstdc++ to pass -D_WIN32_WINNT=0x0600 but only when the switch --enable-libstdcxx-threads is passed, which means that C++11 threads are still disabled by default *unless* MinGW-W64 itself is configured for Windows Vista/Server 2008 or later by default (this has been the case in the development version since end of 2020, for earlier versions you can configure it --with-default-win32-winnt=0x0600 to get the same effect). I only manually tested it on i686-w64-mingw32 and x86_64-w64-mingw32 but AdaCore has used it in their C/C++/Ada compilers for 3 years now and the 30_threads chapter of the libstdc++ testsuite was clean at the time. 2022-10-31 Eric Botcazou <ebotcazou@adacore.com> libgcc/ * config.host (i[34567]86-*-mingw*): Add thread fragment after EH one as well as new i386/t-slibgcc-mingw fragment. (x86_64-*-mingw*): Likewise. * config/i386/gthr-win32.h: If _WIN32_WINNT is at least 0x0600, define both __GTHREAD_HAS_COND and __GTHREADS_CXX0X to 1. Error out if _GTHREAD_USE_MUTEX_TIMEDLOCK is 1. Include stdlib.h instead of errno.h and do not include _mingw.h. (CONST_CAST2): Add specific definition for C++. (ATTRIBUTE_UNUSED): New macro. (__UNUSED_PARAM): Delete. Define WIN32_LEAN_AND_MEAN before including windows.h. (__gthread_objc_data_tls): Use TLS_OUT_OF_INDEXES instead of (DWORD)-1. (__gthread_objc_init_thread_system): Likewise. (__gthread_objc_thread_get_data): Minor tweak. (__gthread_objc_condition_allocate): Use ATTRIBUTE_UNUSED. (__gthread_objc_condition_deallocate): Likewise. (__gthread_objc_condition_wait): Likewise. (__gthread_objc_condition_broadcast): Likewise. (__gthread_objc_condition_signal): Likewise. Include sys/time.h. (__gthr_win32_DWORD): New typedef. (__gthr_win32_HANDLE): Likewise. (__gthr_win32_CRITICAL_SECTION): Likewise. (__gthr_win32_CONDITION_VARIABLE): Likewise. (__gthread_t): Adjust. (__gthread_key_t): Likewise. (__gthread_mutex_t): Likewise. (__gthread_recursive_mutex_t): Likewise. (__gthread_cond_t): New typedef. (__gthread_time_t): Likewise. (__GTHREAD_MUTEX_INIT_DEFAULT): Delete. (__GTHREAD_RECURSIVE_MUTEX_INIT_DEFAULT): Likewise. (__GTHREAD_COND_INIT_FUNCTION): Define. (__GTHREAD_TIME_INIT): Likewise. (__gthr_i486_lock_cmp_xchg): Delete. (__gthr_win32_create): Declare. (__gthr_win32_join): Likewise. (__gthr_win32_self): Likewise. (__gthr_win32_detach): Likewise. (__gthr_win32_equal): Likewise. (__gthr_win32_yield): Likewise. (__gthr_win32_mutex_destroy): Likewise. (__gthr_win32_cond_init_function): Likewise if __GTHREADS_HAS_COND is 1. (__gthr_win32_cond_broadcast): Likewise. (__gthr_win32_cond_signal): Likewise. (__gthr_win32_cond_wait): Likewise. (__gthr_win32_cond_timedwait): Likewise. (__gthr_win32_recursive_mutex_init_function): Delete. (__gthr_win32_recursive_mutex_lock): Likewise. (__gthr_win32_recursive_mutex_unlock): Likewise. (__gthr_win32_recursive_mutex_destroy): Likewise. (__gthread_create): New inline function. (__gthread_join): Likewise. (__gthread_self): Likewise. (__gthread_detach): Likewise. (__gthread_equal): Likewise. (__gthread_yield): Likewise. (__gthread_cond_init_function): Likewise if __GTHREADS_HAS_COND is 1. (__gthread_cond_broadcast): Likewise. (__gthread_cond_signal): Likewise. (__gthread_cond_wait): Likewise. (__gthread_cond_timedwait): Likewise. (__GTHREAD_WIN32_INLINE): New macro. (__GTHREAD_WIN32_COND_INLINE): Likewise. (__GTHREAD_WIN32_ACTIVE_P): Likewise. Define WIN32_LEAN_AND_MEAN before including windows.h. (__gthread_once): Minor tweaks. (__gthread_key_create): Use ATTRIBUTE_UNUSED and TLS_OUT_OF_INDEXES. (__gthread_key_delete): Minor tweak. (__gthread_getspecific): Likewise. (__gthread_setspecific): Likewise. (__gthread_mutex_init_function): Reimplement. (__gthread_mutex_destroy): Likewise. (__gthread_mutex_lock): Likewise. (__gthread_mutex_trylock): Likewise. (__gthread_mutex_unlock): Likewise. (__gthr_win32_abs_to_rel_time): Declare. (__gthread_recursive_mutex_init_function): Reimplement. (__gthread_recursive_mutex_destroy): Likewise. (__gthread_recursive_mutex_lock): Likewise. (__gthread_recursive_mutex_trylock): Likewise. (__gthread_recursive_mutex_unlock): Likewise. (__gthread_cond_destroy): New inline function. (__gthread_cond_wait_recursive): Likewise. * config/i386/gthr-win32.c: Delete everything. Include gthr-win32.h to get the out-of-line version of inline routines. Add compile-time checks for the local version of the Win32 types. * config/i386/gthr-win32-cond.c: New file. * config/i386/gthr-win32-thread.c: Likewise. * config/i386/t-gthr-win32: Add config/i386/gthr-win32-thread.c to the EH part, config/i386/gthr-win32-cond.c and config/i386/gthr-win32.c to the static version of libgcc. * config/i386/t-slibgcc-mingw: New file. * config/i386/libgcc-mingw.ver: Likewise. libstdc++-v3/ * acinclude.m4 (GLIBCXX_EXPORT_FLAGS): Substitute CPPFLAGS. (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Set ac_has_sched_yield and ac_has_win32_sleep to yes for MinGW. Change HAVE_WIN32_SLEEP into _GLIBCXX_USE_WIN32_SLEEP. (GLIBCXX_CHECK_GTHREADS): Add _WIN32_THREADS to compilation flags for Win32 threads and force _GTHREAD_USE_MUTEX_TIMEDLOCK to 0 for them. Add -D_WIN32_WINNT=0x0600 to compilation flags if yes was configured and add it to CPPFLAGS on success. * config.h.in: Regenerate. * configure: Likewise. * config/os/mingw32-w64/os_defines.h (_GLIBCXX_USE_GET_NPROCS_WIN32): Define to 1. * config/os/mingw32/os_defines.h (_GLIBCXX_USE_GET_NPROCS_WIN32): Ditto * src/c++11/thread.cc (get_nprocs): Provide Win32 implementation if _GLIBCXX_USE_GET_NPROCS_WIN32 is defined. Replace HAVE_WIN32_SLEEP with USE_WIN32_SLEEP. * testsuite/19_diagnostics/headers/system_error/errc_std_c++0x.cc: Add missing conditional compilation. * testsuite/lib/libstdc++.exp (check_v3_target_sleep): Add support for _GLIBCXX_USE_WIN32_SLEEP. (check_v3_target_nprocs): Likewise for _GLIBCXX_USE_GET_NPROCS_WIN32. Signed-off-by: Eric Botcazou <ebotcazou@adacore.com> Signed-off-by: Jonathan Yong <10walls@gmail.com>
2022-12-22libstdc++: Implement C++20 time zone support in <chrono>Jonathan Wakely1-0/+27
This is the largest missing piece of C++20 support. Only the cxx11 ABI is supported, due to the use of std::string in the API for time zones. For the old gcc4 ABI, utc_clock and leap seconds are supported, but only using a hardcoded list of leap seconds, no up-to-date tzdb::leap_seconds information is available, and no time zones or zoned_time conversions. The implementation currently depends on a tzdata.zi file being provided by the OS or the user. The expected location is /usr/share/zoneinfo but that can be changed using --with-libstdcxx-zoneinfo-dir=PATH. On targets that support it there is also a weak symbol that users can override in their own program (which also helps with testing): extern "C++" const char* __gnu_cxx::zoneinfo_dir_override(); If no file is found, a fallback tzdb object will be created which only contains the "Etc/UTC" and "Etc/GMT" time zones. A leapseconds file is also expected in the same directory, but if that isn't present then a hardcoded list of leapseconds is used, which is correct at least as far as 2023-06-28 (and it currently looks like no leap second will be inserted for a few years). The tzdata.zi and leapseconds files from https://www.iana.org/time-zones are in the public domain, so shipping copies of them with GCC would be an option. However, the tzdata.zi file will rapidly become outdated, so users should really provide it themselves (or convince their OS vendor to do so). It would also be possible to implement an alternative parser for the compiled tzdata files (one per time zone) under /usr/share/zoneinfo. Those files are present on more operating systems, but do not contain all the information present in tzdata.zi. Specifically, the "links" are not present, so that e.g. "UTC" and "Universal" are distinct time zones, rather than both being links to the canonical "Etc/UTC" zone. For some platforms those files are hard links to the same file, but there's no indication which zone is the canonical name and which is a link. Other platforms just store them in different inodes anyway. I do not plan to add such an alternative parser for the compiled files. That would need to be contributed by maintainers or users of targets that require it, if making tzdata.zi available is not an option. The library ABI would not need to change for a new tzdb implementation, because everything in tzdb_list, tzdb and time_zone is implemented as a pimpl (except for the shared_ptr links between nodes, described below). That means the new exported symbols added by this commit should be stable even if the implementation is completely rewritten. The information from tzdata.zi is parsed and stored in data structures that closely model the info in the file. This is a space-efficient representation that uses less memory that storing every transition for every time zone. It also avoids spending time expanding that information into time zone transitions that might never be needed by the program. When a conversion to/from a local time to UTC is requested the information will be processed to determine the time zone transitions close to the time being converted. There is a bug in some time zone transitions. When generating a sys_info object immediately after one that was previously generated, we need to find the previous rule that was in effect and note its offset and letters. This is so that the start time and abbreviation of the new sys_info will be correct. This only affects time zones that use a format like "C%sT" where the LETTERS replacing %s are non-empty for standard time, e.g. "Asia/Shanghai" which uses "CST" for standard time and "CDT" for daylight time. The tzdb_list structure maintains a linked list of tzdb nodes using shared_ptr links. This allows the iterators into the list to share ownership with the list itself. This offers a non-portable solution to a lifetime issue in the API. Because tzdb objects can be erased from the list using tzdb_list::erase_after, separate modules/libraries in a large program cannot guarantee that any const tzdb& or const time_zone* remains valid indefinitely. Holding onto a tzdb_list::const_iterator will extend the tzdb object's lifetime, even if it's erased from the list. An alternative design would be for the list iterator to hold a weak_ptr. This would allow users to test whether the tzdb still exists when the iterator is dereferenced, which is better than just having a dangling raw pointer. That doesn't actually extend the tzdb's lifetime though, and every use of it would need to be preceded by checking the weak_ptr. Using shared_ptr adds a little bit of overhead but allows users to solve the lifetime issue if they rely on the libstdc++-specific iterator property. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ZONEINFO_DIR): New macro. * config.h.in: Regenerate. * config/abi/pre/gnu.ver: Export new symbols. * configure: Regenerate. * configure.ac (GLIBCXX_ZONEINFO_DIR): Use new macro. * include/std/chrono (utc_clock::from_sys): Correct handling of leap seconds. (nonexistent_local_time::_M_make_what_str): Define. (ambiguous_local_time::_M_make_what_str): Define. (__throw_bad_local_time): Define new function. (time_zone, tzdb_list, tzdb): Implement all members. (remote_version, zoned_time, get_leap_second_info): Define. * include/std/version: Add comment for __cpp_lib_chrono. * src/c++20/Makefile.am: Add new file. * src/c++20/Makefile.in: Regenerate. * src/c++20/tzdb.cc: New file. * testsuite/lib/libstdc++.exp: Define effective target tzdb. * testsuite/std/time/clock/file/members.cc: Check file_time alias and file_clock::now() member. * testsuite/std/time/clock/gps/1.cc: Likewise for gps_clock. * testsuite/std/time/clock/tai/1.cc: Likewise for tai_clock. * testsuite/std/time/syn_c++20.cc: Uncomment everything except parse. * testsuite/std/time/clock/utc/leap_second_info.cc: New test. * testsuite/std/time/exceptions.cc: New test. * testsuite/std/time/time_zone/get_info_local.cc: New test. * testsuite/std/time/time_zone/get_info_sys.cc: New test. * testsuite/std/time/time_zone/requirements.cc: New test. * testsuite/std/time/tzdb/1.cc: New test. * testsuite/std/time/tzdb/leap_seconds.cc: New test. * testsuite/std/time/tzdb_list/1.cc: New test. * testsuite/std/time/tzdb_list/requirements.cc: New test. * testsuite/std/time/zoned_time/1.cc: New test. * testsuite/std/time/zoned_time/custom.cc: New test. * testsuite/std/time/zoned_time/deduction.cc: New test. * testsuite/std/time/zoned_time/req_neg.cc: New test. * testsuite/std/time/zoned_time/requirements.cc: New test. * testsuite/std/time/zoned_traits.cc: New test.
2022-11-25libstdc++: Fix orphaned/nested output of configure checksJonathan Wakely1-3/+3
This moves two AC_MSG_RESULT lines for <uchar.h> features so that they are only printed when the corresponding AC_MSG_CHECKING actually happened. This fixes configure output like: checking for uchar.h... no no checking for int64_t... yes Also move the AC_MSG_CHECKING for libbacktrace support so it doesn't come after AC_CHECK_HEADERS output. This fixes: checking whether to build libbacktrace support... checking for sys/mman.h... (cached) yes yes libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_UCHAR_H): Don't use AC_MSG_RESULT unless the AC_MSG_CHECKING happened. * configure: Regenerate.
2022-11-18libstdc++: add experimental Contracts supportJeff Chapman II1-1/+1
This patch adds the library support for the experimental C++ Contracts implementation. This now consists only of a default definition of the violation handler, which users can override through defining their own version. To avoid ABI stability problems with libstdc++.so this is added to a separate -lstdc++exp static library, which the driver knows to add when it sees -fcontracts. Co-authored-by: Andrew Marmaduke <amarmaduke@lock3software.com> Co-authored-by: Jason Merrill <jason@redhat.com> libstdc++-v3/ChangeLog: * acinclude.m4 (glibcxx_SUBDIRS): Add src/experimental. * include/Makefile.am (experimental_headers): Add contract. * include/Makefile.in: Regenerate. * src/Makefile.am (SUBDIRS): Add experimental. * src/Makefile.in: Regenerate. * configure: Regenerate. * src/experimental/contract.cc: New file. * src/experimental/Makefile.am: New file. * src/experimental/Makefile.in: New file. * include/experimental/contract: New file.
2022-10-21libstdc++: respect with-{headers, newlib} for default hosted valueArsen Arsenović1-1/+4
This saves us a build flag when building for freestanding targets. libstdc++-v3/ChangeLog: * acinclude.m4: Default hosted to off if building without headers and without newlib. * configure: Regenerate.
2022-10-11libstdc++: Allow emergency EH alloc pool size to be tuned [PR68606]Jonathan Wakely1-0/+45
Implement a long-standing request to support tuning the size of the emergency buffer for allocating exceptions after malloc fails, or to disable that buffer entirely. It's now possible to disable the dynamic allocation of the buffer and use a fixed-size static buffer, via --enable-libstdcxx-static-eh-pool. This is a built-time choice that is baked into libstdc++ and so affects all code linked against that build of libstdc++. The size of the pool can be set by --with-libstdcxx-eh-pool-obj-count=N which is measured in units of sizeof(void*) not bytes. A given exception type such as std::system_error depends on the target, so giving a size in bytes wouldn't be portable across 16/32/64-bit targets. When libstdc++ is configured to use a dynamic buffer, the size of that buffer can now be tuned at runtime by setting the GLIBCXX_TUNABLES environment variable (c.f. PR libstdc++/88264). The number of exceptions to reserve space for is controlled by the "glibcxx.eh_pool.obj_count" and "glibcxx.eh_pool.obj_size" tunables. The pool will be sized to be able to allocate obj_count exceptions of size obj_size*sizeof(void*) and obj_count "dependent" exceptions rethrown by std::rethrow_exception. With the ability to tune the buffer size, we can reduce the default pool size on 32-bit and 16-bit targets. Most users never need to throw 1kB exceptions in parallel from hundreds of threads after malloc is OOM. The users who do need that can use the tunables to select larger sizes. The old defaults can be chosen at runtime by setting GLIBCXX_TUNABLES to: 64-bit: glibcxx.eh_pool.obj_count=64:glibcxx.eh_pool.obj_size=112 32-bit: glibcxx.eh_pool.obj_count=32:glibcxx.eh_pool.obj_size=104 Or approximated by configuring with: 64-bit: --with-libstdcxx-eh-pool-obj-count=252 32-bit: --with-libstdcxx-eh-pool-obj-count=94 libstdc++-v3/ChangeLog: PR libstdc++/68606 * Makefile.in: Regenerate. * acinclude.m4 (GLIBCXX_EMERGENCY_EH_ALLOC): New macro. * configure: Regenerate. * configure.ac: Use GLIBCXX_EMERGENCY_EH_ALLOC. * crossconfig.m4: Check for secure_getenv. * doc/Makefile.in: Regenerate. * doc/xml/manual/configure.xml: Document new configure options. * doc/xml/manual/evolution.xml: Document addition of tunables. * doc/xml/manual/using_exceptions.xml: Document emergency buffer and tunables. * doc/html/*: Regenerate. * include/Makefile.in: Regenerate. * libsupc++/Makefile.am: Use EH_POOL_FLAGS. * libsupc++/Makefile.in: Regenerate. * libsupc++/eh_alloc.cc (EMERGENCY_OBJ_SIZE): Define in units of sizeof(void*) not including the ABI's exception header. (EMERGENCY_OBJ_COUNT): Define as target-independent calculation based on word size. (MAX_OBJ_COUNT): Define macro for upper limit on pool size. (pool) [_GLIBCXX_EH_POOL_STATIC]: Use fixed-size buffer. (pool::buffer_size_in_bytes): New static member function. (pool::pool): Parse GLIBCXX_TUNABLES environment variable to set pool size at runtime. (pool::in_pool): Use std::less<void*> for total order. (__freeres) [_GLIBCXX_EH_POOL_STATIC]: Do nothing. (__cxa_free_exception, __cxa_free_dependent_exception): Add [[unlikely]] attributes. * po/Makefile.in: Regenerate. * python/Makefile.in: Regenerate. * src/Makefile.in: Regenerate. * src/c++11/Makefile.in: Regenerate. * src/c++17/Makefile.in: Regenerate. * src/c++20/Makefile.in: Regenerate. * src/c++98/Makefile.in: Regenerate. * src/filesystem/Makefile.in: Regenerate. * src/libbacktrace/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate.
2022-10-07libstdc++: Add --disable-libstdcxx-hosted as an alias for hosted-libstdcxxJonathan Wakely1-1/+21
Most libstdc++ configure args are of the form --enable-libstdcxx-xxx but the option to build freestanding is --disable-hosted-libstdcxx. If you accidentally type --disable-libstdcxx-hosted then it will be ignored. This adds --disable-libstdcxx-hosted as an alias for the existing arg, so it works whichever way you say it. If both args are used explicitly and their values do not agree, configure fails with an error. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_HOSTED): Add libstdcxx-hosted enable arg as an alias for hosted-libstdcxx enable arg. * configure: Regenerate.
2022-10-03libstdc++: Make _GLIBCXX_HOSTED respect -ffreestanding [PR103626]Jonathan Wakely1-1/+1
This allows the library to switch to freestanding mode when compiling with the -ffreestanding flag. This means you don't need a separate libstdc++ build configured with --disable-hosted-libstdcxx in order to compile for a freestanding environment. The testsuite support files cannot be compiled for freestanding, so add -fno-freestanding to override any -ffreestanding in the test flags. libstdc++-v3/ChangeLog: PR libstdc++/103626 * acinclude.m4 (GLIBCXX_ENABLE_HOSTED): Define _GLIBCXX_HOSTED to __STDC_HOSTED__ for non-freestanding installations. * configure: Regenerate. * include/Makefile.am (${host_builddir}/c++config.h): Adjust grep pattern. * include/Makefile.in: Regenerate. * testsuite/lib/libstdc++.exp (v3-build_support): Use -fno-freestanding. * testsuite/libstdc++-abi/abi.exp: Likewise.
2022-09-12libstdc++: Outline the overlapping case of string _M_replace into a separate ↵Jakub Jelinek1-1/+1
function [PR105329] The following patch is partially a workaround for bogus warnings when the compiler isn't able to fold _M_disjunct call into constant false, but also an optimization attempt - assuming _M_disjunct (__s) is rare, the patch should shrink code size for the common case and use library or for non-standard instantiations an out of line function to handle the rare case. 2022-09-12 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/105329 * acinclude.m4 (libtool_VERSION): Change to 6:31:0. * config/abi/pre/gnu.ver (GLIBCXX_3.4.21): Don't export std::basic_string methods with name length of 15. (GLIBCXX_3.4.31): Export std::basic_string::_M_replace_cold. * testsuite/util/testsuite_abi.cc (check_version): Handle GLIBCXX_3.4.31. * include/bits/basic_string.h (std::basic_string::_M_replace_cold): Declare. * include/bits/basic_string.tcc (std::basic_string::_M_replace_cold): Define and export even for C++20. (std::basic_string::_M_replace): Use __builtin_expect, outline the overlapping case to _M_replace_cold. * configure: Regenerated.
2022-06-23libstdc++: check for openatAlexandre Oliva1-0/+12
rtems6.0 has fdopendir, and fcntl.h defines AT_FDCWD and declares openat, but there's no openat in libc. Adjust dir-common.h to not assume ::openat just because of AT_FDCWD. for libstdc++-v3/ChangeLog * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for openat. * configure, config.h.in: Rebuilt. * src/filesystem/dir-common.h (openat): Use ::openat if _GLIBCXX_HAVE_OPENAT. * src/filesystem/dir.cc (dir_and_pathname): Use dirfd if _GLIBCXX_HAVE_OPENAT.
2022-04-19libstdc++: Fix syntax error in libbacktrace configurationJonathan Wakely1-3/+3
Using == instead of = causes a configuration error with dash as the shell: checking whether to build libbacktrace support... /home/devel/building/work/src/gcc-12-20220417/libstdc++-v3/configure: 77471: test: auto: unexpected operator /home/devel/building/work/src/gcc-12-20220417/libstdc++-v3/configure: 77474: test: auto: unexpected operator auto This means we fail to change the value from "auto" to "no" and so this test passes: GLIBCXX_CONDITIONAL(ENABLE_BACKTRACE, [test "$enable_libstdcxx_backtrace" != no]) This leads to the libbacktrace directory being included in the build without being configured properly, and bootstrap fails. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): Fix shell operators. * configure: Regenerate.
2022-04-14libstdc++: Default to mutex-based atomics on RISC-VPalmer Dabbelt1-0/+3
The RISC-V port requires libatomic to be linked in order to resolve various atomic functions, which results in builds that have "--with-libstdcxx-lock-policy=auto" defaulting to mutex-based locks. Changing this to direct atomics breaks the ABI, this forces the auto detection mutex-based atomics on RISC-V in order to avoid a silent ABI break for users. See Bug 84568 for more discussion. In the long run there may be a way to get the higher-performance atomics without an ABI flag day, but that's going to be a much more complicated operation. We don't even have support for the inline atomics yet, but given that some folks have been discussing hacks to make these libatomic routines appear implicitly it seems prudent to just turn off the automatic detection for RISC-V. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_LOCK_POLICY): Force auto to mutex for RISC-V. * configure: Regenerate.
2022-04-12libstdc++: Prefer to use mmap instead of malloc in libbacktraceJonathan Wakely1-6/+29
As reported in PR libbacktrace/105240, libbacktrace leaks memory when using malloc for allocations. I originally thought it would be simpler to just use malloc unconditionally (because it's supported on all targets) but the leaks make that problematic. This adds libbacktrace's detection for mmap to the libstdc++ configury, so that we use mmap.c and mmapio.c when possible. This avoids the leaks seen previously, at least on linux. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): Check for mmap. * config.h.in: Regenerate. * configure: Regenerate.
2022-02-08libstdc++: Add comment to acinclude.m4Jonathan Wakely1-0/+2
libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_LOCK_POLICY): Add comment about checking for CAS on correct word size.