From patchwork Thu Jan 8 18:14:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 127656 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 7F29A4BA2E07 for ; Thu, 8 Jan 2026 18:16:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F29A4BA2E07 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (2048-bit key, unprotected) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=XWTxNUm3; dkim=fail reason="signature verification failed" (2048-bit key) header.d=keithp.com header.i=@keithp.com header.a=rsa-sha256 header.s=mail header.b=qMHuC6Yd X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id B4DBB4BA2E30; Thu, 8 Jan 2026 18:14:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4DBB4BA2E30 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=keithp.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=keithp.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B4DBB4BA2E30 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=63.227.221.253 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1767896055; cv=none; b=gG4lJ/popi4JzHSJfBKlmhWXdYo52+TQsA+gwqZyElPWuPjCTU3p9rgWVLlqdyrzer0h2qzdwX7JKKINJsDwMRIPTvvKZepLl64O3gQs8nzWjjdNgqSUcV9nYdR+wcudZI1b4krro7r6z2NEm/Qaq0HsDeZxEaXXtuWZA+m5FAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1767896055; c=relaxed/simple; bh=jdrQ7LofACV5wzVXShRUKeb9hVIxz2wSWtHCLkHiE80=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-ID: MIME-Version; b=ofKm+CO41GBYZEJN8ccyuFvlGDsouO7Axd26LY0gQoZSXTEfE6HSzF9OiY+Y8Raejouol+ZxFN0ilh42EYcZS7nvK6+xW1d5zcvPffeMXbT4zwLqN2BWgHxASdjEWwXgpdGIV8JiBNkecDjYXfa8KSoYYoSbAwGTUp3T1aeLMPA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4DBB4BA2E30 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1767896054; bh=jdrQ7LofACV5wzVXShRUKeb9hVIxz2wSWtHCLkHiE80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XWTxNUm3kna8tD1lwMAb7omAafkiWzyungKBkbcswfp8WGZws4y0KY1B+h+FPSFQr Ao9MklxOfuXLIxtEm0a4QAkKHwCMhxaP3VSt/6oBCgSwgOf1cjz2Y+Siwu3LjhhUHr LV17KZYa8eQjpCO/+T1sNXg4c0TKsm8LCqtC7NeCxGZvB6c20eaCyw3ZxhlPVq0KGa yaPhF8nGLUv0m45SyL0iLDjj/Rj39VQ/BBVh2aKSKczVl1YC+A3L4LDgA2jsBa1KKi tx92IlbeErAhlQxPjSPBOV8W2uwYJhgxCeYTLQJQPOs3LZjsXmC2Br+xo1hVcGEnx6 D2gNsrw8NFGDw== Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 979F53F28792; Thu, 8 Jan 2026 10:14:14 -0800 (PST) X-Virus-Scanned: Debian amavis at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavis, port 10024) with LMTP id MzgZG_gVB1X4; Thu, 8 Jan 2026 10:14:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1767896052; bh=jdrQ7LofACV5wzVXShRUKeb9hVIxz2wSWtHCLkHiE80=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qMHuC6YdhutSAUxxncu8Bi31A7HJME0fhNf7FdhISNnoHotc8tHZ8lQ+4/i74tNri 49DSU3LXJV9uKW0jVO1gA2OSvhwkMqcn9uQHGgp1oJCTohDFDyfPnpNGN0nQS4tLsi 0Y0UA5CNgF6yEKOAqx7svJfUyJyM5WyKG7Zea8853OcylNtAfdNIno1tMPlEtURRo8 LLgsXOHYvM/jwFSqKFaagSL4xIqDqz8RVFWmFCOxYoD7TahnBIxrpUn6jDHdYPAeov XcfU1veGUnaN8OnxrAqxG6QuKbD0+IVLqseIGGmx75cUckYFeS+T9FFDJOwqKS4COd XQnAVxob1oKFg== Received: from koto.keithp.com (koto.keithp.com [192.168.11.2]) by elaine.keithp.com (Postfix) with ESMTPSA id E2AAC3F28775; Thu, 8 Jan 2026 10:14:12 -0800 (PST) Received: by koto.keithp.com (Postfix, from userid 1000) id 09D593409F86; Thu, 08 Jan 2026 10:14:13 -0800 (PST) From: Keith Packard To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Cc: Keith Packard , Jonathan Wakely Subject: [PATCH] libstdc++: Fix C++ 11 ctype when using picolibc (blank vs space) Date: Thu, 8 Jan 2026 10:14:07 -0800 Message-ID: <20260108181407.1298841-1-keithp@keithp.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20260106024622.1062385-1-keithp@keithp.com> References: <20260106024622.1062385-1-keithp@keithp.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Existing toolchain builds rely on the similarity between picolibc and newlib when building libstdc++ and use --with-newlib. Switch to the picolibc 16-bit _ctype_wide array which provides separate values for ctype_base::blank and ctype_base::space. This fixes a bug where libstdc++ was including '\f', '\n', '\r' and '\v' in the set of 'blank' chars. Afterwards, only ' ' and '\t' are in this set, as specified by C++ 11. Signed-off-by: Keith Packard --- libstdc++-v3/acinclude.m4 | 4 + libstdc++-v3/config/os/picolibc/ctype_base.h | 61 ++++++++++ .../os/picolibc/ctype_configure_char.cc | 105 ++++++++++++++++++ .../config/os/picolibc/ctype_inline.h | 74 ++++++++++++ libstdc++-v3/config/os/picolibc/os_defines.h | 36 ++++++ libstdc++-v3/configure.ac | 62 +++++++++++ 6 files changed, 342 insertions(+) create mode 100644 libstdc++-v3/config/os/picolibc/ctype_base.h create mode 100644 libstdc++-v3/config/os/picolibc/ctype_configure_char.cc create mode 100644 libstdc++-v3/config/os/picolibc/ctype_inline.h create mode 100644 libstdc++-v3/config/os/picolibc/os_defines.h diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 index 103515c000f..1eb575d3202 100644 --- a/libstdc++-v3/acinclude.m4 +++ b/libstdc++-v3/acinclude.m4 @@ -81,6 +81,10 @@ AC_DEFUN([GLIBCXX_CONFIGURE], [ AC_HELP_STRING([--with-newlib], [assume newlib as a system C library])) + AC_ARG_WITH([picolibc], + AC_HELP_STRING([--with-picolibc], + [assume picolibc as a system C library])) + # Will set LN_S to either 'ln -s', 'ln', or 'cp -p' (if linking isn't # available). Uncomment the next line to force a particular method. AC_PROG_LN_S diff --git a/libstdc++-v3/config/os/picolibc/ctype_base.h b/libstdc++-v3/config/os/picolibc/ctype_base.h new file mode 100644 index 00000000000..bcc9e8df4a3 --- /dev/null +++ b/libstdc++-v3/config/os/picolibc/ctype_base.h @@ -0,0 +1,61 @@ +// Locale support for picolibc -*- C++ -*- + +// Copyright (C) 2000-2026 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +// +// ISO C++ 14882: 22.1 Locales +// + +// Information as gleaned from /usr/include/ctype.h + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + /// @brief Base class for ctype. + struct ctype_base + { + // Non-standard typedefs. + typedef const int* __to_type; + + // NB: Offsets into ctype::_M_table force a particular size + // on the mask type. Because of this, we don't use an enum. + typedef short mask; + static const mask upper = mask (__CTYPE_UPPER); + static const mask lower = mask (__CTYPE_LOWER); + static const mask alpha = mask (__CTYPE_UPPER | __CTYPE_LOWER); + static const mask digit = mask (__CTYPE_DIGIT); + static const mask xdigit = mask (__CTYPE_HEX | __CTYPE_DIGIT); + static const mask space = mask (__CTYPE_SPACE); + static const mask print = mask (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT | __CTYPE_BLANK); + static const mask graph = mask (__CTYPE_PUNCT | __CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT); + static const mask cntrl = mask (__CTYPE_CNTRL); + static const mask punct = mask (__CTYPE_PUNCT); + static const mask alnum = mask (__CTYPE_UPPER | __CTYPE_LOWER | __CTYPE_DIGIT); +#if __cplusplus >= 201103L + static const mask blank = mask (__CTYPE_BLANK | __CTYPE_TAB); +#endif + }; + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/config/os/picolibc/ctype_configure_char.cc b/libstdc++-v3/config/os/picolibc/ctype_configure_char.cc new file mode 100644 index 00000000000..7b38fac2422 --- /dev/null +++ b/libstdc++-v3/config/os/picolibc/ctype_configure_char.cc @@ -0,0 +1,105 @@ +// Locale support for picolibc -*- C++ -*- + +// Copyright (C) 2011-2026 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file ctype_configure_char.cc */ + +// +// ISO C++ 14882: 22.1 Locales +// + +#include +#include +#include + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + +// Information as gleaned from /usr/include/ctype.h + + const ctype_base::mask* + ctype::classic_table() throw() + { return _ctype_wide + 1; } + + ctype::ctype(__c_locale, const mask* __table, bool __del, + size_t __refs) + : facet(__refs), _M_del(__table != 0 && __del), + _M_toupper(NULL), _M_tolower(NULL), + _M_table(__table ? __table : classic_table()) + { + memset(_M_widen, 0, sizeof(_M_widen)); + _M_widen_ok = 0; + memset(_M_narrow, 0, sizeof(_M_narrow)); + _M_narrow_ok = 0; + } + + ctype::ctype(const mask* __table, bool __del, size_t __refs) + : facet(__refs), _M_del(__table != 0 && __del), + _M_toupper(NULL), _M_tolower(NULL), + _M_table(__table ? __table : classic_table()) + { + memset(_M_widen, 0, sizeof(_M_widen)); + _M_widen_ok = 0; + memset(_M_narrow, 0, sizeof(_M_narrow)); + _M_narrow_ok = 0; + } + + char + ctype::do_toupper(char __c) const + { + int __x = __c; + return (this->is(ctype_base::lower, __c) ? (__x - 'a' + 'A') : __x); + } + + const char* + ctype::do_toupper(char* __low, const char* __high) const + { + while (__low < __high) + { + *__low = this->do_toupper(*__low); + ++__low; + } + return __high; + } + + char + ctype::do_tolower(char __c) const + { + int __x = __c; + return (this->is(ctype_base::upper, __c) ? (__x - 'A' + 'a') : __x); + } + + const char* + ctype::do_tolower(char* __low, const char* __high) const + { + while (__low < __high) + { + *__low = this->do_tolower(*__low); + ++__low; + } + return __high; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/config/os/picolibc/ctype_inline.h b/libstdc++-v3/config/os/picolibc/ctype_inline.h new file mode 100644 index 00000000000..7903214883b --- /dev/null +++ b/libstdc++-v3/config/os/picolibc/ctype_inline.h @@ -0,0 +1,74 @@ +// Locale support for picolibc -*- C++ -*- + +// Copyright (C) 2000-2026 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file bits/ctype_inline.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{locale} + */ + +// +// ISO C++ 14882: 22.1 Locales +// + +// ctype bits to be inlined go here. Non-inlinable (ie virtual do_*) +// functions go in ctype.cc + +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + + bool + ctype:: + is(mask __m, char __c) const + { return _M_table[static_cast(__c)] & __m; } + + const char* + ctype:: + is(const char* __low, const char* __high, mask* __vec) const + { + while (__low < __high) + *__vec++ = _M_table[static_cast(*__low++)]; + return __high; + } + + const char* + ctype:: + scan_is(mask __m, const char* __low, const char* __high) const + { + while (__low < __high && !this->is(__m, *__low)) + ++__low; + return __low; + } + + const char* + ctype:: + scan_not(mask __m, const char* __low, const char* __high) const + { + while (__low < __high && this->is(__m, *__low) != 0) + ++__low; + return __low; + } + +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace diff --git a/libstdc++-v3/config/os/picolibc/os_defines.h b/libstdc++-v3/config/os/picolibc/os_defines.h new file mode 100644 index 00000000000..e9c611b4fb5 --- /dev/null +++ b/libstdc++-v3/config/os/picolibc/os_defines.h @@ -0,0 +1,36 @@ +// Specific definitions for picolibc -*- C++ -*- + +// Copyright (C) 2026 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file bits/os_defines.h + * This is an internal header file, included by other library headers. + * Do not attempt to use it directly. @headername{iosfwd} + */ + +#ifndef _GLIBCXX_OS_DEFINES +#define _GLIBCXX_OS_DEFINES 1 + +// System-specific #define, typedefs, corrections, etc, go here. This +// file will come before all others. + +#endif diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac index 339e7bb17a4..cd038ee85ac 100644 --- a/libstdc++-v3/configure.ac +++ b/libstdc++-v3/configure.ac @@ -100,6 +100,7 @@ GLIBCXX_CONFIGURE # Libtool setup. if test "x${with_newlib}" != "xyes" && + test "x${with_picolibc}" != "xyes" && test "x${with_avrlibc}" != "xyes" && test "x$with_headers" != "xno"; then AC_LIBTOOL_DLOPEN @@ -428,6 +429,67 @@ dnl # rather than hardcoding that information. glibcxx_cv_mkdir=yes ;; esac + elif test "x${with_picolibc}" = "xyes"; then + os_include_dir="os/picolibc" + AC_DEFINE(HAVE_HYPOT) + + # GLIBCXX_CHECK_STDLIB_SUPPORT + AC_DEFINE(HAVE_STRTOF) + + AC_DEFINE(HAVE_ACOSF) + AC_DEFINE(HAVE_ASINF) + AC_DEFINE(HAVE_ATAN2F) + AC_DEFINE(HAVE_ATANF) + AC_DEFINE(HAVE_CEILF) + AC_DEFINE(HAVE_COSF) + AC_DEFINE(HAVE_COSHF) + AC_DEFINE(HAVE_EXPF) + AC_DEFINE(HAVE_FABSF) + AC_DEFINE(HAVE_FLOORF) + AC_DEFINE(HAVE_FMODF) + AC_DEFINE(HAVE_FREXPF) + AC_DEFINE(HAVE_HYPOTF) + AC_DEFINE(HAVE_LDEXPF) + AC_DEFINE(HAVE_LOG10F) + AC_DEFINE(HAVE_LOGF) + AC_DEFINE(HAVE_MODFF) + AC_DEFINE(HAVE_POWF) + AC_DEFINE(HAVE_SINF) + AC_DEFINE(HAVE_SINHF) + AC_DEFINE(HAVE_SQRTF) + AC_DEFINE(HAVE_TANF) + AC_DEFINE(HAVE_TANHF) + + # Support for iconv in picolibc is configurable. + AC_TRY_COMPILE([#include ], [ + #ifndef _ICONV_ENABLED + #error + #endif], [ac_picolibc_iconv_enabled=yes], [ac_picolibc_iconv_enabled=no]) + if test "$ac_picolibc_iconv_enabled" = yes; then + AC_DEFINE(HAVE_ICONV) + fi + + AC_DEFINE(HAVE_MEMALIGN) + + # Check for TLS + AC_TRY_COMPILE([#include ], [ + #ifndef __THREAD_LOCAL_STORAGE + #error + #endif], [ac_picolibc_tls_enabled=yes], [ac_picolibc_tls_enabled=no]) + if test "$ac_picolibc_tls_enabled" = yes; then + AC_DEFINE(HAVE_TLS) + fi + + AC_DEFINE(HAVE_ALIGNED_ALLOC) + AC_DEFINE(HAVE_AT_QUICK_EXIT) + AC_DEFINE(HAVE_LINK) + AC_DEFINE(HAVE_SYS_STAT_H) + AC_DEFINE(HAVE_SYS_TYPES_H) + AC_DEFINE(HAVE_SETENV) + AC_DEFINE(HAVE_STRERROR_L) + AC_DEFINE(HAVE_S_ISREG) + AC_DEFINE(HAVE_UNISTD_H) + elif test "x$with_headers" != "xno"; then GLIBCXX_CROSSCONFIG fi