[libcxx-commits] [libcxx] [libc++] Fix the locale base API on Linux with musl (PR #128936)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 26 14:20:04 PST 2025


https://github.com/ldionne updated https://github.com/llvm/llvm-project/pull/128936

>From 2fbb3b02d450ace244fceaec0e1321ca551ea714 Mon Sep 17 00:00:00 2001
From: Pirama Arumuga Nainar <pirama at google.com>
Date: Wed, 26 Feb 2025 11:17:26 -0800
Subject: [PATCH 1/2] [libcxx] avoid the "_l" calls on musl platforms

Since 363bfd6090b0 ([libc++] Use the new locale base API on Linux (#128007), 2025-02-24),
musl targets will fail to build with errors like the below:

    In file included from /[b/f/w/src/git/out/stage2/include/c++/v1/__locale:14](https://cs.corp.google.com/piper///depot/google3/b/f/w/src/git/out/stage2/include/c%2B%2B/v1/__locale?l=14):
    In file included from /[b/f/w/src/git/out/stage2/include/c++/v1/__locale_dir/locale_base_api.h:123](https://cs.corp.google.com/piper///depot/google3/b/f/w/src/git/out/stage2/include/c%2B%2B/v1/__locale_dir/locale_base_api.h?l=123):
    /[b/f/w/src/git/out/stage2/include/c++/v1/__locale_dir/support/linux.h:98](https://cs.corp.google.com/piper///depot/google3/b/f/w/src/git/out/stage2/include/c%2B%2B/v1/__locale_dir/support/linux.h?l=98):12: error: no member named 'strtoll_l' in the global namespace
       98 |   return ::strtoll_l(__nptr, __endptr, __base, __loc);
          |          ~~^
    /[b/f/w/src/git/out/stage2/include/c++/v1/__locale_dir/support/linux.h:103](https://cs.corp.google.com/piper///depot/google3/b/f/w/src/git/out/stage2/include/c%2B%2B/v1/__locale_dir/support/linux.h?l=103):10: error: no member named 'strtoull_l' in the global namespace; did you mean '__strtoull'?
      103 |   return ::strtoull_l(__nptr, __endptr, __base, __loc);
          |          ^~~~~~~~~~~~
          |          __strtoull
    /[b/f/w/src/git/out/stage2/include/c++/v1/__locale_dir/support/linux.h:102](https://cs.corp.google.com/piper///depot/google3/b/f/w/src/git/out/stage2/include/c%2B%2B/v1/__locale_dir/support/linux.h?l=102):1: note: '__strtoull' declared here
      102 | __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
          | ^
    2 errors generated.
---
 libcxx/include/__locale_dir/support/linux.h | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index f1662c0112603..00c99eb5ea351 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -95,12 +95,20 @@ inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __
 }
 
 inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
+#if !defined(_LIBCPP_HAS_MUSL_LIBC)
   return ::strtoll_l(__nptr, __endptr, __base, __loc);
+#else
+  return ::strtoll(__nptr, __endptr, __base);
+#endif
 }
 
 inline _LIBCPP_HIDE_FROM_ABI unsigned long long
 __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
+#if !defined(_LIBCPP_HAS_MUSL_LIBC)
   return ::strtoull_l(__nptr, __endptr, __base, __loc);
+#else
+  return ::strtoull(__nptr, __endptr, __base);
+#endif
 }
 
 //

>From 98f7dc5c9357b1cad8c1cd75157578d1d62f8d83 Mon Sep 17 00:00:00 2001
From: Louis Dionne <ldionne.2 at gmail.com>
Date: Wed, 26 Feb 2025 17:19:57 -0500
Subject: [PATCH 2/2] Apply suggestions from code review

---
 libcxx/include/__locale_dir/support/linux.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index 00c99eb5ea351..f25f4218a48ba 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -98,6 +98,7 @@ inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __en
 #if !defined(_LIBCPP_HAS_MUSL_LIBC)
   return ::strtoll_l(__nptr, __endptr, __base, __loc);
 #else
+  (void)__loc;
   return ::strtoll(__nptr, __endptr, __base);
 #endif
 }
@@ -107,6 +108,7 @@ __strtoull(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
 #if !defined(_LIBCPP_HAS_MUSL_LIBC)
   return ::strtoull_l(__nptr, __endptr, __base, __loc);
 #else
+  (void)__loc;
   return ::strtoull(__nptr, __endptr, __base);
 #endif
 }



More information about the libcxx-commits mailing list