mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-23 19:03:59 +08:00
7d736ecbc0
265 Commits
Author | SHA1 | Message | Date | |
---|---|---|---|---|
Jonathan Wakely
|
b68561dd79
|
libstdc++: Fix autoconf check for O_NONBLOCK in <fcntl.h>
I misused the AC_CHECK_DECL macro, assuming that it behaved like AC_CHECK_DECLS and always defined a HAVE_xxx macro if the decl was found. Instead, the [action-if-found] shell commands are needed to defined HAVE_O_NONBLOCK explicitly. libstdc++-v3/ChangeLog: * configure.ac: Fix check for O_NONBLOCK. * config.h.in: Regenerate. * configure: Regenerate. |
||
Björn Schäpers
|
d4635b504c
|
libstdc++: detect DLLs on windows with <stacktrace>
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> |
||
Jonathan Wakely
|
df0a668b78 |
libstdc++: Implement C++26 std::text_encoding (P1885R12) [PR113318]
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> |
||
Jonathan Wakely
|
bc274b8d67 |
libstdc++: Regenerate config.h.in
libstdc++-v3/ChangeLog: * config.h.in: Regenerate. |
||
Jonathan Wakely
|
898fd81b83 |
libstdc++: Remove handling for underscore-prefixed libm functions [PR111638]
The checks in linkage.m4 try to support math functions prefixed with underscores, like _acosf and _isinf. However, that doesn't work because they're renamed to the standard names using a macro, but then <cmath> undefines that macro again. This simply removes everything related to those underscored functions. libstdc++-v3/ChangeLog: PR libstdc++/111638 * config.h.in: Regenerate. * configure: Regenerate. * linkage.m4 (GLIBCXX_MAYBE_UNDERSCORED_FUNCS): Remove. (GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_1): Do not check for _foo. (GLIBCXX_CHECK_MATH_DECLS_AND_LINKAGES_1): Likewise. (GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_2): Likewise. (GLIBCXX_CHECK_MATH_DECL_AND_LINKAGE_3): Likewise. (GLIBCXX_CHECK_STDLIB_DECL_AND_LINKAGE_2): Do not use GLIBCXX_MAYBE_UNDERSCORED_FUNCS. |
||
Jonathan Wakely
|
c4baeaecbb |
libstdc++: Implement C++26 native handles for file streams (P1759R6)
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. |
||
Jonathan Wakely
|
5435449be0 |
libstdc++: Add autoconf checks for mkdir, chmod, chdir, and getcwd
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. |
||
Jonathan Wakely
|
2f6bbc9a7d |
libstdc++: Fix --enable-cstdio=stdio_pure [PR110574]
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. |
||
Jonathan Wakely
|
fe2651affa |
libstdc++: Fix iostream init for Clang on darwin [PR110432]
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> |
||
Jannik Glückert
|
d87caacf8e |
libstdc++: Use copy_file_range for filesystem::copy_file
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> |
||
Jannik Glückert
|
f80a8b4229 |
libstdc++: Also use sendfile for big files
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> |
||
Jonathan Wakely
|
49f59826c6 |
libstdc++: Add separate autoconf macro for std::float_t and std::double_t [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. |
||
Jonathan Wakely
|
1f378f6dd3 |
libstdc++: Stop using _GLIBCXX_USE_C99_MATH_TR1 in <cmath>
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. |
||
Jonathan Wakely
|
94a311abf7 |
libstdc++: Disable cacheline alignment for DJGPP [PR109741]
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. |
||
Jonathan Wakely
|
ac3a5bbc62 |
libstdc++: Stop using TR1 macros in <cctype> and <cfenv>
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. |
||
Jonathan Wakely
|
5baabdb15d |
libstdc++: Stop using _GLIBCXX_USE_C99_STDINT_TR1 in <cstdint>
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. |
||
Jonathan Wakely
|
0d76fb1582 |
libstdc++: Stop using _GLIBCXX_USE_C99_COMPLEX_TR1 in <complex>
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. |
||
Björn Schäpers
|
523e8716a4 |
libstdc++: enable <stacktrace> on windows
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> |
||
Jonathan Wakely
|
559993b857 |
libstdc++: Embed a static copy of tzdata.zi
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. |
||
Eric Botcazou
|
9149a5b7e0 |
Reimplement GNU threads library on native Windows
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> |
||
Jonathan Wakely
|
9fc61d45fa |
libstdc++: Implement C++20 time zone support in <chrono>
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. |
||
Arsen Arsenović
|
655271e47f |
libstdc++: Don't use gstdint.h anymore
libstdc++-v3/ChangeLog: * configure.ac: Stop generating gstdint.h. * src/c++11/compatibility-atomic-c++0x.cc: Stop using gstdint.h. * Makefile.in: Regenerate. * aclocal.m4: Regenerate. * config.h.in: Regenerate. * configure: Regenerate. * doc/Makefile.in: Regenerate. * include/Makefile.in: Regenerate. * libsupc++/Makefile.in: Regenerate. * 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. |
||
Alexandre Oliva
|
93070671ea |
libstdc++: check for openat
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. |
||
Jonathan Wakely
|
3c742621ed |
libstdc++: Prefer to use mmap instead of malloc in libbacktrace
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. |
||
Jonathan Wakely
|
ebf6175464 |
libstdc++: Fix filesystem::remove_all races [PR104161]
This fixes the remaining filesystem::remove_all race condition by using POSIX openat to recurse into sub-directories and using POSIX unlinkat to remove files. This avoids the remaining race where the directory being removed is replaced with a symlink after the directory has been opened, so that the filesystem::remove("subdir/file") resolves to "target/file" instead, because "subdir" has been removed and replaced with a symlink. The previous patch only fixed the case where the directory was replaced with a symlink before we tried to open it, but it still used the full (potentially compromised) path as an argument to filesystem::remove. The first part of the fix is to use openat when recursing into a sub-directory with recursive_directory_iterator. This means that opening "dir/subdir" uses the file descriptor for "dir", and so is sure to open "dir/subdir" and not "symlink/subdir". (The previous patch to use O_NOFOLLOW already ensured we won't open "dir/symlink/" here.) The second part of the fix is to use unlinkat for the remove_all operation. Previously we used a directory_iterator to get the name of each file in a directory and then used filesystem::remove(iter->path()) on that name. This meant that any checks (e.g. O_NOFOLLOW) done by the iterator could be invalidated before the remove operation on that pathname. The directory iterator contains an open DIR stream, which we can use to obtain a file descriptor to pass to unlinkat. This ensures that the file being deleted really is contained within the directory we're iterating over, rather than using a pathname that could resolve to some other file. The filesystem::remove_all function previously used a (non-recursive) filesystem::directory_iterator for each directory, and called itself recursively for sub-directories. The new implementation uses a single filesystem::recursive_directory_iterator object, and calls a new __erase member function on that iterator. That new __erase member function does the actual work of removing a file (or a directory after its contents have been iterated over and removed) using unlinkat. That means we don't need to expose the DIR stream or its file descriptor to the remove_all function, it's still encapuslated by the iterator class. It would be possible to add a __rewind member to directory iterators too, to call rewinddir after each modification to the directory. That would make it more likely for filesystem::remove_all to successfully remove everything even if files are being written to the directory tree while removing it. It's unclear if that is actually prefereable, or if it's better to fail and report an error at the first opportunity. The necessary APIs (openat, unlinkat, fdopendir, dirfd) are defined in POSIX.1-2008, and in Glibc since 2.10. But if the target doesn't provide them, the original code (with race conditions) is still used. This also reduces the number of small memory allocations needed for std::filesystem::remove_all, because we do not store the full path to every directory entry that is iterated over. The new filename_only option means we only store the filename in the directory entry, as that is all we need in order to use openat or unlinkat. Finally, rather than duplicating everything for the Filesystem TS, the std::experimental::filesystem::remove_all implementation now just calls std::filesystem::remove_all to do the work. libstdc++-v3/ChangeLog: PR libstdc++/104161 * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for dirfd and unlinkat. * config.h.in: Regenerate. * configure: Regenerate. * include/bits/fs_dir.h (recursive_directory_iterator): Declare remove_all overloads as friends. (recursive_directory_iterator::__erase): Declare new member function. * include/bits/fs_fwd.h (remove, remove_all): Declare. * src/c++17/fs_dir.cc (_Dir): Add filename_only parameter to constructor. Pass file descriptor argument to base constructor. (_Dir::dir_and_pathname, _Dir::open_subdir, _Dir::do_unlink) (_Dir::unlink, _Dir::rmdir): Define new member functions. (directory_iterator): Pass filename_only argument to _Dir constructor. (recursive_directory_iterator::_Dir_stack): Adjust constructor parameters to take a _Dir rvalue instead of creating one. (_Dir_stack::orig): Add data member for storing original path. (_Dir_stack::report_error): Define new member function. (__directory_iterator_nofollow): Move here from dir-common.h and fix value to be a power of two. (__directory_iterator_filename_only): Define new constant. (recursive_directory_iterator): Construct _Dir object and move into _M_dirs stack. Pass skip_permission_denied argument to first advance call. (recursive_directory_iterator::increment): Use _Dir::open_subdir. (recursive_directory_iterator::__erase): Define new member function. * src/c++17/fs_ops.cc (ErrorReporter, do_remove_all): Remove. (fs::remove_all): Use new recursive_directory_iterator::__erase member function. * src/filesystem/dir-common.h (_Dir_base): Add int parameter to constructor and use openat to implement nofollow semantics. (_Dir_base::fdcwd, _Dir_base::set_close_on_exec, _Dir_base::openat): Define new member functions. (__directory_iterator_nofollow): Move to fs_dir.cc. * src/filesystem/dir.cc (_Dir): Pass file descriptor argument to base constructor. (_Dir::dir_and_pathname, _Dir::open_subdir): Define new member functions. (recursive_directory_iterator::_Dir_stack): Adjust constructor parameters to take a _Dir rvalue instead of creating one. (recursive_directory_iterator): Check for new nofollow option. Construct _Dir object and move into _M_dirs stack. Pass skip_permission_denied argument to first advance call. (recursive_directory_iterator::increment): Use _Dir::open_subdir. * src/filesystem/ops.cc (fs::remove_all): Use C++17 remove_all. |
||
Jonathan Wakely
|
c8bd4dc821 |
libstdc++: Avoid symlink race in filesystem::remove_all [PR104161]
This adds a new internal flag to the filesystem::directory_iterator constructor that makes it fail if the path is a symlink that resolves to a directory. This prevents filesystem::remove_all from following a symlink to a directory, rather than deleting the symlink itself. We can also use that new flag in recursive_directory_iterator to ensure that we don't follow symlinks if the follow_directory_symlink option is not set. This also moves an error check in filesystem::remove_all after the while loop, so that errors from the directory_iterator constructor are reproted, instead of continuing to the filesystem::remove call below. libstdc++-v3/ChangeLog: PR libstdc++/104161 * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for fdopendir. * config.h.in: Regenerate. * configure: Regenerate. * src/c++17/fs_dir.cc (_Dir): Add nofollow flag to constructor and pass it to base class constructor. (directory_iterator): Pass nofollow flag to _Dir constructor. (fs::recursive_directory_iterator::increment): Likewise. * src/c++17/fs_ops.cc (do_remove_all): Use nofollow option for directory_iterator constructor. Move error check outside loop. * src/filesystem/dir-common.h (_Dir_base): Add nofollow flag to constructor and when it's set use ::open with O_NOFOLLOW and O_DIRECTORY. * src/filesystem/dir.cc (_Dir): Add nofollow flag to constructor and pass it to base class constructor. (directory_iterator): Pass nofollow flag to _Dir constructor. (fs::recursive_directory_iterator::increment): Likewise. * src/filesystem/ops.cc (remove_all): Use nofollow option for directory_iterator constructor. Move error check outside loop. |
||
Tom Honermann
|
0e4e4b37d9 |
libstdc++: Declare std::c8rtomb and std::mbrtoc8 if provided by the C library
This patch completes implementation of the C++20 proposal P0482R6 [1] by adding declarations of std::c8rtomb() and std::mbrtoc8() in <cuchar> if provided by the C library in <uchar.h>. This patch addresses feedback provided in response to a previous patch submission [2]. Autoconf changes determine if the C library declares c8rtomb and mbrtoc8 at global scope when uchar.h is included and compiled with either -fchar8_t or -std=c++20. New _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_FCHAR8_T and _GLIBCXX_USE_UCHAR_C8RTOMB_MBRTOC8_CXX20 configuration macros reflect the probe results. The <cuchar> header declares these functions in the std namespace only if available and the _GLIBCXX_USE_CHAR8_T configuration macro is defined (by default it is defined if the C++20 __cpp_char8_t feature test macro is defined) Patches to glibc to implement c8rtomb and mbrtoc8 have been submitted [3]. New tests validate the presence of these declarations. The tests pass trivially if the C library does not provide these functions. Otherwise they ensure that the functions are declared when <cuchar> is included and either -fchar8_t or -std=c++20 is enabled. 1]: WG21 P0482R6 "char8_t: A type for UTF-8 characters and strings (Revision 6)" https://wg21.link/p0482r6 [2]: [PATCH] C++ P0482R6 char8_t: declare std::c8rtomb and std::mbrtoc8 if provided by the C library https://gcc.gnu.org/pipermail/libstdc++/2021-June/052685.html [3]: "C++20 P0482R6 and C2X N2653" [Patch 0/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135061.html [Patch 1/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135062.html [Patch 2/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135063.html [Patch 3/3]: https://sourceware.org/pipermail/libc-alpha/2022-January/135064.html libstdc++-v3/ChangeLog: * acinclude.m4: Define config macros if uchar.h provides c8rtomb() and mbrtoc8(). * config.h.in: Regenerate. * configure: Regenerate. * include/c_compatibility/uchar.h (c8rtomb, mbrtoc8): Define. * include/c_global/cuchar (c8rtomb, mbrtoc8): Likewise. * include/c_std/cuchar (c8rtomb, mbrtoc8): Likewise. * testsuite/21_strings/headers/cuchar/functions_std_cxx20.cc: New test. * testsuite/21_strings/headers/cuchar/functions_std_fchar8_t.cc: New test. |
||
Jonathan Wakely
|
3acb929cc0 |
libstdc++: Define <stacktrace> header for C++23
Add the <stacktrace> header and a new libstdc++_libbacktrace.a library that provides the implementation. For now, the new library is only built if --enable-libstdcxx-backtrace=yes is used. As with the Filesystem TS, the new library is only provided as a static archive. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_BACKTRACE): New macro. * configure.ac: Use GLIBCXX_ENABLE_BACKTRACE. * include/Makefile.am: Add new header. * include/Makefile.in: Regenerate. * include/std/stacktrace: New header. * include/std/version (__cpp_lib_stacktrace): Define. * Makefile.in: Regenerate. * config.h.in: Regenerate. * configure: Regenerate. * doc/Makefile.in: Regenerate. * libsupc++/Makefile.in: Regenerate. * po/Makefile.in: Regenerate. * python/Makefile.in: Regenerate. * src/Makefile.am: 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. * testsuite/Makefile.in: Regenerate. * src/libbacktrace/Makefile.am: New file. * src/libbacktrace/Makefile.in: New file. * src/libbacktrace/backtrace-rename.h: New file. * src/libbacktrace/backtrace-supported.h.in: New file. * src/libbacktrace/config.h.in: New file. * testsuite/lib/libstdc++.exp (check_effective_target_stacktrace): New proc. * testsuite/20_util/stacktrace/entry.cc: New test. * testsuite/20_util/stacktrace/synopsis.cc: New test. * testsuite/20_util/stacktrace/version.cc: New test. |
||
Jonathan Wakely
|
ca1c7065e9 |
libstdc++: Fix definition of _GLIBCXX_NO_SLEEP config macro
If no OS function to sleep (e.g. nanosleep, usleep, Win32 Sleep etc.) is available then configure defines the macro NO_SLEEP. But this will not get prefixed with "_GLIBCXX_" because include/Makefile.am only does that for macros beginning with "HAVE_". The configure script should define _GLIBCXX_NO_SLEEP instead (which is what the code actually checks for). libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Add _GLIBCXX_ prefix to NO_SLEEP macro. * config.h.in: Regenerate. * configure: Regenerate. |
||
Jonathan Wakely
|
3439657b02 |
libstdc++: Support getentropy and arc4random in std::random_device
This adds additional "getentropy" and "arc4random" tokens to std::random_device. The former is supported on Glibc and OpenBSD (and apparently wasm), and the latter is supported on various BSDs. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_GETENTROPY, GLIBCXX_CHECK_ARC4RANDOM): Define. * configure.ac (GLIBCXX_CHECK_GETENTROPY, GLIBCXX_CHECK_ARC4RANDOM): Use them. * config.h.in: Regenerate. * configure: Regenerate. * src/c++11/random.cc (random_device): Add getentropy and arc4random as sources. * testsuite/26_numerics/random/random_device/cons/token.cc: Check new tokens. * testsuite/26_numerics/random/random_device/entropy.cc: Likewise. |
||
Jonathan Wakely
|
3dbd4d94bf |
libstdc++: Use secure_getenv for filesystem::temp_directory_path() [PR65018]
This adds a configure check for the GNU extension secure_getenv and then uses it for looking up TMPDIR and similar variables. Signed-off-by: Jonathan Wakely <jwakely@redhat.com> libstdc++-v3/ChangeLog: PR libstdc++/65018 * configure.ac: Check for secure_getenv. * config.h.in: Regenerate. * configure: Regenerate. * src/filesystem/ops-common.h (get_temp_directory_from_env): New helper function to obtain path from the environment. * src/c++17/fs_ops.cc (fs::temp_directory_path): Use new helper. * src/filesystem/ops.cc (fs::temp_directory_path): Likewise. * testsuite/27_io/filesystem/operations/temp_directory_path.cc: Print messages if test cannot be run. * testsuite/experimental/filesystem/operations/temp_directory_path.cc: Likewise. Fix incorrect condition. Use "TMP" to work with Windows as well as POSIX. |
||
Jonathan Wakely
|
ad0a3be4df |
libstdc++: Remove _GLIBCXX_USE_INT128 autoconf macro
We don't need to decide whether to use __int128 when running configure, we can do so at compilation time by seeing if __SIZEOF_INT128__ is defined and if it's greater than __SIZEOF_LONG_LONG__. This removes another unnecessary architecture-specific config macro in <bits/c++config.h>, so the same header can work for 32-bit or 64-bit compilation on AIX. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_INT128_FLOAT128): Remove checks for __int128 and rename to GLIBCXX_ENABLE_FLOAT128. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Adjust to use GLIBCXX_ENABLE_FLOAT128. * include/bits/random.h (_Select_uint_least_t<s, 1>): Use __SIZEOF_INT128__ to decide whether to use __int128. * include/std/charconv (__to_chars_unsigned_type): Likewise. |
||
Jonathan Wakely
|
7ddcd26ebb |
libstdc++: Remove GLIBCXX_CHECK_INT64_T checks
This simplifies the definition of std::streamoff by using the predefined __INT64_TYPE__ macro, instead of the _GLIBCXX_HAVE_INT64_T_LONG, _GLIBCXX_HAVE_INT64_T_LONG_LONG and _GLIBCXX_HAVE_INT64_T macros defined by configure. By using the __INT64_TYPE__ macro (which all of GCC, Clang and Intel define) we do not need to determine the type of int64_t in configure, we can just use that type directly. The background for the change was explained by David Edelsohn: Currently the type of streamoff is determined at libstdc++ configure time, chosen by the definitions of _GLIBCXX_HAVE_INT64_T_LONG and _GLIBCXX_HAVE_INT64_T_LONG_LONG. For a multilib configuration, the difference is encoded in the different multilib header file paths. For "FAT" library targets that package 32 bit and 64 bit libraries together, G++ also expects a single header file directory hierarchy, causing an incorrect value for streamoff in some situations. And in a subsequent mail: Most of the libstdc++ headers are architecture-neutral, OS neutral and ABI neutral. The differences are localized in bits/c++config.h. And most of c++config.h is identical for 32 bit AIX and 64 bit AIX. The only differences that matter are __int128 and __int64_t. This change removes some of those differences. With the only uses of the INT64_T configure macros removed, the configure checks themselves can also be removed. Co-authored-by: David Edelsohn <dje.gcc@gmail.com> libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_INT64_T): Delete. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Do not use GLIBCXX_CHECK_INT64_T. * include/bits/postypes.h: Remove include of <stdint.h> and definition/undefinition of the __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS macros. (streamoff): Use __INT64_TYPE__ if defined. |
||
Jakub Jelinek
|
2d4c3af94f |
Fix AIX libstdc++ semaphore support [PR100164]
> > The #error would not be hit if _GLIBCXX_HAVE_POSIX_SEMAPHORE were defined, > > but it shows up in your error report. > You now have pinpointed the problem. > It's not that AIX doesn't have semaphore, but that the code previously > had a fallback that hid a bug in the macros: // Use futex if available and didn't force use of POSIX using __fast_semaphore = __atomic_semaphore<__detail::__platform_wait_t>; using __fast_semaphore = __platform_semaphore; using __fast_semaphore = __atomic_semaphore<ptrdiff_t>; > The problem is that libstdc++ configure defines > _GLIBCXX_HAVE_POSIX_SEMAPHORE in config.h. libstdc++ uses sed to > rewrite config.h to c++config.h and prepends _GLIBCXX_, so c++config.h > contains > And bits/semaphore_base.h is not testing that corrupted macro. Either > semaphore_base.h needs to test for the corrupted macro, or libtsdc++ > configure needs to define HAVE_POSIX_SEMAPHORE without itself > prepending _GLIBCXX_ so that the c++config.h rewriting works > correctly and defines the correct macro for semaphore_base.h. The include/Makefile.am sed is: sed -e 's/HAVE_/_GLIBCXX_HAVE_/g' \ -e 's/PACKAGE/_GLIBCXX_PACKAGE/g' \ -e 's/VERSION/_GLIBCXX_VERSION/g' \ -e 's/WORDS_/_GLIBCXX_WORDS_/g' \ -e 's/_DARWIN_USE_64_BIT_INODE/_GLIBCXX_DARWIN_USE_64_BIT_INODE/g' \ -e 's/_FILE_OFFSET_BITS/_GLIBCXX_FILE_OFFSET_BITS/g' \ -e 's/_LARGE_FILES/_GLIBCXX_LARGE_FILES/g' \ -e 's/ICONV_CONST/_GLIBCXX_ICONV_CONST/g' \ -e '/[ ]_GLIBCXX_LONG_DOUBLE_COMPAT[ ]/d' \ -e '/[ ]_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT[ ]/d' \ < ${CONFIG_HEADER} >> $@ ;\ so for many macros one needs _GLIBCXX_ prefixes already in configure, as can be seen in grep AC_DEFINE.*_GLIBCXX configure.ac acinclude.m4 But _GLIBCXX_HAVE_POSIX_SEMAPHORE is the only one that shouldn't have that prefix because the sed is adding that. E.g. on i686-linux, I see grep _GLIBCXX__GLIBCXX c++config.h that proves it is the only broken one. So this change fixes the acinclude.m4 side. 2021-04-21 Jakub Jelinek <jakub@redhat.com> PR libstdc++/100164 * acinclude.m4: For POSIX semaphores AC_DEFINE HAVE_POSIX_SEMAPHORE rather than _GLIBCXX_HAVE_POSIX_SEMAPHORE. * configure: Regenerated. * config.h.in: Regenerated. |
||
Jonathan Wakely
|
f5feee6adc |
libstdc++: Regenerate autoconf files
I forgot to regenerate these files in r11-6137. libstdc++-v3/ChangeLog: * config.h.in: Regenerate. * configure: Regenerate. |
||
Jonathan Wakely
|
7c1e7eed89 |
libstdc++: Add C++ runtime support for new 128-bit long double format
This adds support for the new __ieee128 long double format on powerpc64le targets. Most of the complexity comes from wanting a single libstdc++.so library that contains the symbols needed by code compiled with both -mabi=ibmlongdouble and -mabi=ieeelongdouble (and not forgetting -mlong-double-64 as well!) In a few places this just requires an extra overload, for example std::from_chars has to be overloaded for both forms of long double. That can be done in a single translation unit that defines overloads for 'long double' and also '__ieee128', so that user code including <charconv> will be able to link to a definition for either type of long double. Those are the easy cases. The difficult parts are (as for the std::string ABI transition) the I/O and locale facets. In order to be able to write either form of long double to an ostream such as std::cout we need the locale to contain a std::num_put facet that can handle both forms. The same approach is taken as was already done for supporting 64-bit long double and 128-bit long double: adding extra overloads of do_put to the facet class. On targets where the new long double code is enabled, the facets that are registered in the locale at program startup have additional overloads so that they can work with any long double type. Where this fails to work is if user code installs its own facet, which will probably not have the additional overloads and so will only be able to output one or the other type. In practice the number of users expecting to be able to use their own locale facets in code using a mix of -mabi=ibmlongdouble and -mabi=ieeelongdouble is probably close to zero. libstdc++-v3/ChangeLog: * Makefile.in: Regenerate. * config.h.in: Regenerate. * config/abi/pre/gnu.ver: Make patterns less greedy. * config/os/gnu-linux/ldbl-ieee128-extra.ver: New file with patterns for IEEE128 long double symbols. * configure: Regenerate. * configure.ac: Enable alternative 128-bit long double format on powerpc64*-*-linux*. * doc/Makefile.in: Regenerate. * fragment.am: Regenerate. * include/Makefile.am: Set _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT. * include/Makefile.in: Regenerate. * include/bits/c++config: Define inline namespace for new long double symbols. Don't define _GLIBCXX_USE_FLOAT128 when it's the same type as long double. * include/bits/locale_classes.h [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT] (locale::_Impl::_M_init_extra_ldbl128): Declare new member function. * include/bits/locale_facets.h (_GLIBCXX_NUM_FACETS): Simplify by only counting narrow character facets. (_GLIBCXX_NUM_CXX11_FACETS): Likewise. (_GLIBCXX_NUM_LBDL_ALT128_FACETS): New. [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT] (num_get::__do_get): Define vtable placeholder for __ibm128 long double type. [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__] (num_get::__do_get): Declare vtable placeholder for __ibm128 long double type. [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__] (num_put::__do_put): Likewise. * include/bits/locale_facets.tcc [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__] (num_get::__do_get, num_put::__do_put): Define. * include/bits/locale_facets_nonio.h [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__] (money_get::__do_get): Declare vtable placeholder for __ibm128 long double type. [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__] (money_put::__do_put): Likewise. * include/bits/locale_facets_nonio.tcc [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT && __LONG_DOUBLE_IEEE128__] (money_get::__do_get, money_put::__do_put): Define. * include/ext/numeric_traits.h [_GLIBCXX_LONG_DOUBLE_ALT128_COMPAT] (__numeric_traits<__ibm128>, __numeric_traits<__ieee128>): Define. * libsupc++/Makefile.in: Regenerate. * po/Makefile.in: Regenerate. * python/Makefile.in: Regenerate. * src/Makefile.am: Add compatibility-ldbl-alt128.cc and compatibility-ldbl-alt128-cxx11.cc sources and recipes for objects. * src/Makefile.in: Regenerate. * src/c++11/Makefile.in: Regenerate. * src/c++11/compatibility-ldbl-alt128-cxx11.cc: New file defining symbols using the old 128-bit long double format, for the cxx11 ABI. * src/c++11/compatibility-ldbl-alt128.cc: Likewise, for the gcc4-compatible ABI. * src/c++11/compatibility-ldbl-facets-aliases.h: New header for long double compat aliases. * src/c++11/cow-locale_init.cc: Add comment. * src/c++11/cxx11-locale-inst.cc: Define C and C_is_char unconditionally. * src/c++11/cxx11-wlocale-inst.cc: Add sanity check. Include locale-inst.cc directly, not via cxx11-locale-inst.cc. * src/c++11/locale-inst-monetary.h: New header for monetary category instantiations. * src/c++11/locale-inst-numeric.h: New header for numeric category instantiations. * src/c++11/locale-inst.cc: Include new headers for monetary, numeric, and long double definitions. * src/c++11/wlocale-inst.cc: Remove long double compat aliases that are defined in new header now. * src/c++17/Makefile.am: Use -mabi=ibmlongdouble for floating_from_chars.cc. * src/c++17/Makefile.in: Regenerate. * src/c++17/floating_from_chars.cc (from_chars_impl): Add if-constexpr branch for __ieee128. (from_chars): Overload for __ieee128. * src/c++20/Makefile.in: Regenerate. * src/c++98/Makefile.in: Regenerate. * src/c++98/locale_init.cc (num_facets): Adjust calculation. (locale::_Impl::_Impl(size_t)): Call _M_init_extra_ldbl128. * src/c++98/localename.cc (num_facets): Adjust calculation. (locale::_Impl::_Impl(const char*, size_t)): Call _M_init_extra_ldbl128. * src/filesystem/Makefile.in: Regenerate. * testsuite/Makefile.in: Regenerate. * testsuite/util/testsuite_abi.cc: Add new symbol versions. Allow new symbols to be added to GLIBCXX_IEEE128_3.4.29 and CXXABI_IEEE128_1.3.13 too. * testsuite/26_numerics/complex/abi_tag.cc: Add u9__ieee128 to regex matching expected symbols. |
||
Keith Packard
|
75aee07269 |
libstdc++: Support libc with stdio-only I/O in libstdc++
The current libstdc++ basic_file_stdio.cc code assumes a POSIX API underneath the stdio implementation provided by the host libc. This means that the host must provide a fairly broad POSIX file API, including read, write, open, close, lseek and ioctl. This patch changes basic_file_stdio.cc to only use basic ANSI-C stdio functions, allowing it to be used with libc implementations like picolibc which may not have a POSIX operating system underneath. This is enabled by a new --enable-cstdio=stdio_pure configure option. Aided-by: Jonathan Wakely <jwakely@redhat.com> Signed-off-by: Keith Packard <keithp@keithp.com> libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_CSTDIO): Allow "stdio_pure" option and define _GLIBCXX_USE_PURE_STDIO when it is used. Also add "stdio_posix" option as an alias for "stdio". * config/io/basic_file_stdio.cc [_GLIBCXX_USE_PURE_STDIO]: Only use defined stdio entry points for all I/O operations, without direct calls to underlying POSIX functions. * config.h.in: Regenerate. * configure: Regenerate. |
||
Jonathan Wakely
|
0aa1786d34 |
libstdc++: Fix build failure for target with no way to sleep
In previous releases the std::this_thread::sleep_for function was only declared if the target supports multiple threads. I changed that recently in r11-2649-g5bbb1f3000c57fd4d95969b30fa0e35be6d54ffb so that sleep_for could be used single-threaded. But that means that targets using --disable-threads are now required to provide some way to sleep. This breaks the build for (at least) AVR when trying to build a hosted library. This patch adds a new autoconf macro that is defined when no way to sleep is available, and uses that to suppress the sleeping functions in std::this_thread. The #error in src/c++11/thread.cc is retained for the case where there is no sleep function available but multiple threads are supported. This is consistent with previous releases, but that #error could probably be removed without any consequences. libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_ENABLE_LIBSTDCXX_TIME): Define NO_SLEEP if none of nanosleep, sleep and Sleep is available. * config.h.in: Regenerate. * configure: Regenerate. * include/std/thread [_GLIBCXX_NO_SLEEP] (__sleep_for): Do not declare. [_GLIBCXX_NO_SLEEP] (sleep_for, sleep_until): Do not define. * src/c++11/thread.cc [_GLIBCXX_NO_SLEEP] (__sleep_for): Do not define. |
||
Jonathan Wakely
|
92b47a321e |
libstdc++: Add configure checks for semaphores
This moves the checks for POSIX semaphores to configure time. As well as requiring <semaphore.h> and SEM_VALUE_MAX, we also require the sem_timedwait function. That was only optional in POSIX 2001 (and is absent on Darwin). libstdc++-v3/ChangeLog: * acinclude.m4 (GLIBCXX_CHECK_GTHREADS): Check for * config.h.in: Regenerate. * configure: Regenerate. * include/bits/semaphore_base.h (_GLIBCXX_HAVE_POSIX_SEMAPHORE): Check autoconf macro instead of defining it here. |
||
Jonathan Wakely
|
932fbc868a |
libstdc++: Add std::from_chars for floating-point types
This adds the missing std::from_chars overloads for floating-point types, as required for C++17 conformance. The implementation is a hack and not intended to be used in the long term. Rather than parsing the string directly, this determines the initial portion of the string that matches the pattern determined by the chars_format parameter, then creates a NTBS to be parsed by strtod (or strtold or strtof). Because creating a NTBS requires allocating memory, but std::from_chars is noexcept, we need to be careful to minimise allocation. Even after being careful, allocation failure is still possible, and so a non-conforming std::no_more_memory error code might be returned. Because strtod et al depend on the current locale, but std::from_chars does not, we change the current thread's locale to "C" using newlocale and uselocale before calling strtod, and restore it afterwards. Because strtod doesn't have the equivalent of a std::chars_format parameter, it has to examine the input to determine the format in use, even though the std::from_chars code has already parsed it once (or twice for large input strings!) By replacing the use of strtod we could avoid allocation, avoid changing locale, and use optimised code paths specific to each std::chars_format case. We would also get more portable behaviour, rather than depending on the presence of uselocale, and on any bugs or quirks of the target libc's strtod. Replacing strtod is a project for a later date. libstdc++-v3/ChangeLog: * acinclude.m4 (libtool_VERSION): Bump version. * config.h.in: Regenerate. * config/abi/pre/gnu.ver: Add GLIBCXX_3.4.29 version and new exports. * config/os/gnu-linux/ldbl-extra.ver: Add _GLIBCXX_LDBL_3.4.29 version and new export. * configure: Regenerate. * configure.ac: Check for <xlocale.h> and uselocale. * crossconfig.m4: Add macro or checks for uselocale. * include/std/charconv (from_chars): Declare overloads for float, double, and long double. * src/c++17/Makefile.am: Add new file. * src/c++17/Makefile.in: Regenerate. * src/c++17/floating_from_chars.cc: New file. (from_chars): Define for float, double, and long double. * testsuite/20_util/from_chars/1_c++20_neg.cc: Prune extra diagnostics caused by new overloads. * testsuite/20_util/from_chars/1_neg.cc: Likewise. * testsuite/20_util/from_chars/2.cc: Check leading '+'. * testsuite/20_util/from_chars/4.cc: New test. * testsuite/20_util/from_chars/5.cc: New test. * testsuite/util/testsuite_abi.cc: Add new symbol versions. |
||
Mike Crowe
|
ab40695a46 |
libstdc++: Add full steady_clock support to shared_timed_mutex
The pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock functions were added to glibc in v2.30. They have also been added to Android Bionic. If these functions are available in the C library then they can be used to implement shared_timed_mutex::try_lock_until, shared_timed_mutex::try_lock_for, shared_timed_mutex::try_lock_shared_until and shared_timed_mutex::try_lock_shared_for so that they are no longer unaffected by the system clock being warped. (This is the shared_mutex equivalent of PR libstdc++/78237 for mutex.) If the new functions are available then steady_clock is deemed to be the "best" clock available which means that it is used for the relative try_lock_for calls and absolute try_lock_until calls using steady_clock and user-defined clocks. It's not possible to have _GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK defined without _GLIBCXX_USE_PTHREAD_RWLOCK_T, so the requirement that the clock be the same as condition_variable is maintained. Calls explicitly using system_clock (aka high_resolution_clock) continue to use CLOCK_REALTIME via the old pthread_rwlock_timedrdlock and pthread_rwlock_timedwrlock functions. If the new functions are not available then system_clock is deemed to be the "best" clock available which means that the previous suboptimal behaviour remains. Additionally, the user-defined clock used with shared_timed_mutex::try_lock_for and shared_mutex::try_lock_shared_for may have higher precision than __clock_t. We may need to round the duration up to ensure that the timeout is long enough. (See __timed_mutex_impl::_M_try_lock_for) 2019-12-02 Mike Crowe <mac@mcrowe.com> Add full steady_clock support to shared_timed_mutex * acinclude.m4 (GLIBCXX_CHECK_PTHREAD_RWLOCK_CLOCKLOCK): Define to check for the presence of both pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock. * config.h.in: Regenerate. * configure.ac: Call GLIBCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK. * configure: Regenerate. * include/std/shared_mutex (shared_timed_mutex): Define __clock_t as the best clock to use for relative waits. (shared_timed_mutex::try_lock_for) Round up wait duration if necessary. (shared_timed_mutex::try_lock_shared_for): Likewise. (shared_timed_mutex::try_lock_until): Use existing try_lock_until implementation for system_clock (which matches __clock_t when _GLIBCCXX_USE_PTHREAD_RWLOCK_CLOCKLOCK is not defined). Add new overload for steady_clock that uses pthread_rwlock_clockwrlock if it is available. Simplify overload for non-standard clock to just call try_lock_for with a relative timeout. (shared_timed_mutex::try_lock_shared_until): Likewise. From-SVN: r278903 |
||
Mike Crowe
|
3b2fb54353 |
libstdc++: PR 78237 Add full steady_clock support to timed_mutex
The pthread_mutex_clocklock function is available in glibc since the 2.30 release. If this function is available in the C library it can be used to fix PR libstdc++/78237 by supporting steady_clock properly with timed_mutex. This means that code using timed_mutex::try_lock_for or timed_mutex::wait_until with steady_clock is no longer subject to timing out early or potentially waiting for much longer if the system clock is warped at an inopportune moment. If pthread_mutex_clocklock is available then steady_clock is deemed to be the "best" clock available which means that it is used for the relative try_lock_for calls and absolute try_lock_until calls using steady_clock and user-defined clocks. Calls explicitly using system_clock (aka high_resolution_clock) continue to use CLOCK_REALTIME via __gthread_cond_timedwait. If pthread_mutex_clocklock is not available then system_clock is deemed to be the "best" clock available which means that the previous suboptimal behaviour remains. 2019-12-02 Mike Crowe <mac@mcrowe.com> PR libstdc++/78237 Add full steady_clock support to timed_mutex * acinclude.m4 (GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK): Define to detect presence of pthread_mutex_clocklock function. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Call GLIBCXX_CHECK_PTHREAD_MUTEX_CLOCKLOCK. * include/std/mutex (__timed_mutex_impl): Remove unnecessary __clock_t. (__timed_mutex_impl::_M_try_lock_for): Use best clock to turn relative timeout into absolute timeout. (__timed_mutex_impl::_M_try_lock_until): Keep existing implementation for system_clock. Add new implementation for steady_clock that calls _M_clocklock. Modify overload for user-defined clock to use a relative wait so that it automatically uses the best clock. [_GLIBCXX_USE_PTHREAD_MUTEX_CLOCKLOCK] (timed_mutex::_M_clocklock): New member function. (recursive_timed_mutex::_M_clocklock): Likewise. From-SVN: r278901 |
||
Jonathan Wakely
|
2fc115875e |
Build filesystem library with large file support
Enable AC_SYS_LARGEFILE to set the macros needed for large file APIs to be used by default. We do not want to define those macros in the public headers that users include. The values of the macros are copied to a separate file that is only included by the filesystem sources during the build, and then the macros in <bits/c++config.h> are renamed so that they don't have any effect in user code including our headers. Also use larger type for result of filesystem::file_size to avoid truncation of large values on 32-bit systems (PR 91947). PR libstdc++/81091 PR libstdc++/91947 * configure.ac: Use AC_SYS_LARGEFILE to enable 64-bit file APIs. * config.h.in: Regenerate: * configure: Regenerate: * include/Makefile.am (${host_builddir}/largefile-config.h): New target to generate config header for filesystem library. (${host_builddir}/c++config.h): Rename macros for large file support. * include/Makefile.in: Regenerate. * src/c++17/fs_dir.cc: Include new config header. * src/c++17/fs_ops.cc: Likewise. (filesystem::file_size): Use uintmax_t for size. * src/filesystem/dir.cc: Include new config header. * src/filesystem/ops.cc: Likewise. (experimental::filesystem::file_size): Use uintmax_t for size. From-SVN: r276585 |
||
Mike Crowe
|
ad4d1d21ad |
PR libstdc++/41861 Add full steady_clock support to condition_variable
The pthread_cond_clockwait function is available in glibc since the 2.30 release. If this function is available in the C library it can be used to fix PR libstdc++/41861 by supporting std::chrono::steady_clock properly with std::condition_variable. This means that code using std::condition_variable::wait_for or std::condition_variable::wait_until with std::chrono::steady_clock is no longer subject to timing out early or potentially waiting for much longer if the system clock is warped at an inopportune moment. If pthread_cond_clockwait is available then std::chrono::steady_clock is deemed to be the "best" clock available which means that it is used for the relative wait_for calls and absolute wait_until calls using user-defined clocks. Calls explicitly using std::chrono::system_clock continue to use CLOCK_REALTIME via __gthread_cond_timedwait. If pthread_cond_clockwait is not available then std::chrono::system_clock is deemed to be the "best" clock available which means that the previous suboptimal behaviour remains. 2019-09-04 Mike Crowe <mac@mcrowe.com> PR libstdc++/41861 * acinclude.m4 (GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT): Check for new pthread_cond_clockwait function. * configure.ac: Use GLIBCXX_CHECK_PTHREAD_COND_CLOCKWAIT. * configure: Regenerate. * config.h.in: Regenerate. * include/std/condition_variable: (condition_variable): Rename __steady_clock_t typedef and add system_clock. Change __clock_t to be a typedef for the preferred clock to convert arbitrary other clocks to. [_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT] (wait_until): Add a steady_clock overload. (wait_until): Change __clock_t overload to use system_clock. [_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT] (__wait_until_impl): Add steady_clock overload that calls pthread_cond_clockwait. (__wait_until_impl): Change __clock_t overload to use system_clock. (condition_variable_any) [_GLIBCXX_USE_PTHREAD_COND_CLOCKWAIT]: Use steady_clock for __clock_t if pthread_cond_clockwait is available. From-SVN: r275390 |
||
Jonathan Wakely
|
b0c0d878a8 |
PR libstdc++/85494 use rdseed and rand_s in std::random_device
Add support for additional sources of randomness to std::random_device, to allow using RDSEED for Intel CPUs and rand_s for Windows. When supported these can be selected using the tokens "rdseed" and "rand_s". For *-w64-mingw32 targets the "default" token will now use rand_s, and for other i?86-*-* and x86_64-*-* targets it will try to use "rdseed" first, then "rdrand", and finally "/dev/urandom". To simplify the declaration of std::random_device in <bits/random.h> the constructors now unconditionally call _M_init instead of _M_init_pretr1, and the function call operator now unconditionally calls _M_getval. The library code now decides whether _M_init and _M_getval should use a real source of randomness or the mt19937 engine. Existing code compiled against old libstdc++ headers will still call _M_init_pretr1 and _M_getval_pretr1, but those functions now forward to _M_init and _M_getval if a real source of randomness is available. This means existing code compiled for mingw-w64 will start to use rand_s just by linking to a new libstdc++.dll. * acinclude.m4 (GLIBCXX_CHECK_X86_RDSEED): Define macro to check if the assembler supports rdseed. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Use GLIBCXX_CHECK_X86_RDSEED. * config/os/mingw32-w64/os_defines.h (_GLIBCXX_USE_CRT_RAND_S): Define. * doc/html/*: Regenerate. * doc/xml/manual/status_cxx2011.xml: Document new tokens. * include/bits/random.h (random_device::random_device()): Always call _M_init rather than _M_init_pretr1. (random_device::random_device(const string&)): Likewise. (random_device::operator()()): Always call _M_getval(). (random_device::_M_file): Replace first member of union with an anonymous struct, with _M_file as its first member. * src/c++11/random.cc [_GLIBCXX_X86_RDRAND] (USE_RDRAND): Define. [_GLIBCXX_X86_RDSEED] (USE_RDSEED): Define. (USE_MT19937): Define if none of the above are defined. (USE_POSIX_FILE_IO): Define. (_M_strtoul): Remove. [USE_RDSEED] (__x86_rdseed): Define new function. [_GLIBCXX_USE_CRT_RAND_S] (__winxp_rand_s): Define new function. (random_device::_M_init(const string&)): Initialize new union members. Add support for "rdseed" and "rand_s" tokens. Decide what the "default" token does according to which USE_* macros are defined. [USE_POSIX_FILE_IO]: Store a file descriptor. [USE_MT19937]: Forward to _M_init_pretr1 instead. (random_device::_M_init_pretr1(const string&)) [USE_MT19937]: Inline code from _M_strtoul. [!USE_MT19937]: Call _M_init, transforming the old default token or numeric tokens to "default". (random_device::_M_fini()) [USE_POSIX_FILE_IO]: Use close not fclose. (random_device::_M_getval()): Use new union members to obtain a random number from the stored function pointer or file descriptor. [USE_MT19937]: Obtain a value from the mt19937 engine. (random_device::_M_getval_pretr1()): Call _M_getval(). (random_device::_M_getentropy()) [USE_POSIX_FILE_IO]: Use _M_fd instead of fileno. [!USE_MT19937] (mersenne_twister): Do not instantiate when not needed. * testsuite/26_numerics/random/random_device/85494.cc: New test. From-SVN: r271740 |
||
Jonathan Wakely
|
187fdaea67 |
PR libstdc++/89460 Fix Networking TS test failures on HP-UX
Check for availability of POSIX sockatmark before using it. Rename _S_ntoh overloads that are ambiguous when passed an integral type that is neither uint16_t nor uint32_t. PR libstdc++/89460 * configure.ac: Check for sockatmark. * crossconfig.m4: Check for sockatmark. * config.h.in: Regenerate. * configure: Regenerate. * include/experimental/internet (address_v4::_S_hton): Rename overloaded functions to _S_hton_16 and _S_ntoh_16. (address_v4::_S_ntoh): Rename to _S_ntoh_16 and _S_ntoh_32. (basic_endpoint): Adjust calls to _S_hton and _S_ntoh. * include/experimental/socket (basic_socket::at_mark): Check _GLIBCXX_HAVE_SOCKATMARK. From-SVN: r269588 |
||
Jonathan Wakely
|
a61ae535c3 |
Add std::timespec and std::timespec_get for C++17
* configure.ac: Check for C11 timespec_get function. * crossconfig.m4 (freebsd, linux, gnu, cygwin, solaris, netbsd) (openbsd): Likewise * config.h.in: Regenerate. * configure: Regenerate. * include/c_global/ctime (timespec, timespec_get): Add to namespace std for C++17 and up. From-SVN: r268879 |
||
Jonathan Wakely
|
cf4b581f2e |
Fix build for systems without POSIX truncate
Older versions of newlib do not provide truncate so add a configure check for it, and provide a fallback definition. There were also some missing exports in the linker script, which went unnoticed because there are no tests for some functions. A new link-only test checks that every filesystem operation function is defined by the library. * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for truncate. * config.h.in: Regenerate. * config/abi/pre/gnu.ver: Order patterns for filesystem operations alphabetically and add missing entries for copy_symlink, hard_link_count, rename, and resize_file. * configure: Regenerate. * src/c++17/fs_ops.cc (resize_file): Remove #if so posix::truncate is used unconditionally. * src/filesystem/ops-common.h (__gnu_posix::truncate) [!_GLIBCXX_HAVE_TRUNCATE]: Provide fallback definition that only supports truncating to zero length. * testsuite/27_io/filesystem/operations/all.cc: New test. * testsuite/27_io/filesystem/operations/resize_file.cc: New test. From-SVN: r267647 |
||
Jonathan Wakely
|
de4db54fd9 |
PR libstdc++/86756 Move rest of std::filesystem to libstdc++.so
Move std::filesystem directory iterators and operations from libstdc++fs.a to main libstdc++ library. These components have many dependencies on OS support, which is not available on all targets. Some additional autoconf checks and conditional compilation is needed to ensure the files will build for all targets. Previously this code was not compiled without --enable-libstdcxx-filesystem-ts but the C++17 components should be available for all hosted builds. The tests for these components no longer need to link to libstdc++fs.a, but are not expected to pass on all targets. To avoid numerous failures on targets which are not expected to pass the tests (due to missing OS functionality) leave the dg-require-filesystem-ts directives in place for now. This will ensure the tests only run for builds where the filesystem-ts library is built, which presumably means some level of OS support is present. PR libstdc++/86756 * acinclude.m4 (GLIBCXX_CHECK_FILESYSTEM_DEPS): Check for utime and lstat and define _GLIBCXX_USE_UTIME and _GLIBCXX_USE_LSTAT. * config.h.in: Regenerate. * config/abi/pre/gnu.ver (GLIBCXX_3.4.26): Export symbols for remaining std::filesystem types and functions. * configure: Regenerate. * src/c++17/Makefile.am: Add C++17 filesystem sources. * src/c++17/Makefile.in: Regenerate. * src/c++17/cow-fs_dir.cc: Move src/filesystem/cow-std-dir.cc to here, and change name of included file. * src/c++17/cow-fs_ops.cc: Move src/filesystem/cow-std-ops.cc to here, and change name of included file. * src/c++17/fs_dir.cc: Move src/filesystem/std-dir.cc to here. Change path to dir-common.h. * src/c++17/fs_ops.cc: Move src/filesystem/std-ops.cc to here. Change path to ops-common.h. Disable -Wunused-parameter warnings. (internal_file_clock): Define unconditionally. [!_GLIBCXX_HAVE_SYS_STAT_H] (internal_file_clock::from_stat): Do not define. (do_copy_file, do_space): Move definitions to ops.common.h. (copy, file_size, hard_link_count, last_write_time, space): Only perform operation when _GLIBCXX_HAVE_SYS_STAT_H is defined, otherwise report an error. (last_write_time, read_symlink): Remove unused attributes from parameters. * src/filesystem/Makefile.am: Remove C++17 filesystem sources. * src/filesystem/Makefile.in: Regenerate. * src/filesystem/cow-std-dir.cc: Move to src/c++17/cow-fs_dir.cc. * src/filesystem/cow-std-ops.cc: Move to src/c++17/cow-fs_ops.cc. * src/filesystem/std-dir.cc: Move to src/c++17/fs_dir.cc. * src/filesystem/std-ops.cc: Move to src/c++17/fs_ops.cc. * src/filesystem/dir-common.h [!_GLIBCXX_HAVE_DIRENT_H]: Define dummy types and functions instead of using #error. * src/filesystem/dir.cc [!_GLIBCXX_HAVE_DIRENT_H]: Use #error. * src/filesystem/ops-common.h [!_GLIBCXX_USE_LSTAT] (lstat): Define in terms of stat. [!_GLIBCXX_HAVE_UNISTD_H]: Define dummy types and functions. (do_copy_file, do_space): Move definitions here from std-ops.cc. * src/filesystem/ops.cc: Adjust calls to do_copy_file and do_space to account for new namespace. * testsuite/27_io/filesystem/directory_entry/86597.cc: Remove -lstdc++fs from dg-options. * testsuite/27_io/filesystem/directory_entry/lwg3171.cc: Likewise. * testsuite/27_io/filesystem/file_status/1.cc: Likewise. * testsuite/27_io/filesystem/filesystem_error/cons.cc: Likewise. * testsuite/27_io/filesystem/filesystem_error/copy.cc: Likewise. * testsuite/27_io/filesystem/iterators/directory_iterator.cc: Likewise. * testsuite/27_io/filesystem/iterators/pop.cc: Likewise. * testsuite/27_io/filesystem/iterators/recursive_directory_iterator.cc: Likewise. * testsuite/27_io/filesystem/operations/absolute.cc: Likewise. * testsuite/27_io/filesystem/operations/canonical.cc: Likewise. * testsuite/27_io/filesystem/operations/copy.cc: Likewise. * testsuite/27_io/filesystem/operations/copy_file.cc: Likewise. * testsuite/27_io/filesystem/operations/create_directories.cc: Likewise. * testsuite/27_io/filesystem/operations/create_directory.cc: Likewise. * testsuite/27_io/filesystem/operations/create_symlink.cc: Likewise. * testsuite/27_io/filesystem/operations/current_path.cc: Likewise. * testsuite/27_io/filesystem/operations/equivalent.cc: Likewise. * testsuite/27_io/filesystem/operations/exists.cc: Likewise. * testsuite/27_io/filesystem/operations/file_size.cc: Likewise. * testsuite/27_io/filesystem/operations/is_empty.cc: Likewise. * testsuite/27_io/filesystem/operations/last_write_time.cc: Likewise. * testsuite/27_io/filesystem/operations/permissions.cc: Likewise. * testsuite/27_io/filesystem/operations/proximate.cc: Likewise. * testsuite/27_io/filesystem/operations/read_symlink.cc: Likewise. * testsuite/27_io/filesystem/operations/relative.cc: Likewise. * testsuite/27_io/filesystem/operations/remove.cc: Likewise. * testsuite/27_io/filesystem/operations/remove_all.cc: Likewise. * testsuite/27_io/filesystem/operations/space.cc: Likewise. * testsuite/27_io/filesystem/operations/status.cc: Likewise. * testsuite/27_io/filesystem/operations/symlink_status.cc: Likewise. * testsuite/27_io/filesystem/operations/temp_directory_path.cc: Likewise. * testsuite/27_io/filesystem/operations/weakly_canonical.cc: Likewise. From-SVN: r267616 |
||
Jonathan Wakely
|
da29d2a36e |
PR libstdc++/67843 set shared_ptr lock policy at build-time
This resolves a longstanding issue where the lock policy for shared_ptr reference counting depends on compilation options when the header is included, so that different -march options can cause ABI changes. For example, objects compiled with -march=armv7 will use atomics to synchronize reference counts, and objects compiled with -march=armv5t will use a mutex. That means the shared_ptr control block will have a different layout in different objects, causing ODR violations and undefined behaviour. This was the root cause of PR libstdc++/42734 as well as PR libstdc++/67843. The solution is to decide on the lock policy at build time, when libstdc++ is configured. The configure script checks for the availability of the necessary atomic built-ins for the target and fixes that choice permanently. Different -march flags used to compile user code will not cause changes to the lock policy. This results in an ABI change for certain compilations, but only where there was already an ABI incompatibility between the libstdc++.so library and objects built with an incompatible -march option. In general, this means a more stable ABI that isn't silently altered when -march flags make addition atomic ops available. To force a target to use "atomic" or "mutex" the new configure option --with-libstdcxx-lock-policy can be used. In order to turn ODR violations into linker errors, the uses of shared_ptr in filesystem directory iterators have been replaced with __shared_ptr, and explicit instantiations are declared. This ensures that object files using those types cannot link to libstdc++ libs unless they use the same lock policy. PR libstdc++/67843 * acinclude.m4 (GLIBCXX_ENABLE_LOCK_POLICY): Add new macro that defines _GLIBCXX_HAVE_ATOMIC_LOCK_POLICY. * config.h.in: Regenerate. * configure: Regenerate. * configure.ac: Use GLIBCXX_ENABLE_LOCK_POLICY. * doc/xml/manual/configure.xml: Document new configure option. * include/bits/fs_dir.h (directory_iterator): Use __shared_ptr instead of shared_ptr. (recursive_directory_iterator): Likewise. (__shared_ptr<_Dir>): Add explicit instantiation declaration. (__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise. * include/bits/shared_ptr_base.h (__allocate_shared, __make_shared): Add default template argument for _Lock_policy template parameter. * include/ext/concurrence.h (__default_lock_policy): Check macro _GLIBCXX_HAVE_ATOMIC_LOCK_POLICY instead of checking if the current target supports the builtins for compare-and-swap. * src/filesystem/std-dir.cc (__shared_ptr<_Dir>): Add explicit instantiation definition. (__shared_ptr<recursive_directory_iterator::_Dir_stack>): Likewise. (directory_iterator, recursive_directory_iterator): Use __make_shared instead of make_shared. From-SVN: r266533 |