Skip to content

[libc++] Fix the locale base API on Linux with musl #128936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2025

Conversation

androm3da
Copy link
Member

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.

Copy link

github-actions bot commented Feb 26, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Since 363bfd6 ([libc++] Use the new locale base API on Linux (llvm#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.
@ldionne ldionne marked this pull request as ready for review February 26, 2025 22:14
@ldionne ldionne requested a review from a team as a code owner February 26, 2025 22:14
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 26, 2025
@ldionne ldionne changed the title draft: [libcxx] avoid the "_l" calls on musl platforms [libc++] Fix the locale base API on Linux with musl Feb 26, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 26, 2025

@llvm/pr-subscribers-libcxx

Author: Brian Cain (androm3da)

Changes

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.

Full diff: https://github.com/llvm/llvm-project/pull/128936.diff

1 Files Affected:

  • (modified) libcxx/include/__locale_dir/support/linux.h (+8)
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
 }
 
 //

Copy link
Member

@ldionne ldionne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fix and sorry for the slow reaction time.

Do you know if this means we can actually get rid of this code path in locale_base_api.h?

#  elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
#    include <__locale_dir/locale_base_api/musl.h>

@ldionne ldionne added the pending-ci Merging the PR is only pending completion of CI label Feb 26, 2025
@ldionne
Copy link
Member

ldionne commented Feb 26, 2025

This can be landed as soon as the CI is green. If someone lands this before I do, please edit the commit message to avoid butchering git log.

Thanks for the fix @androm3da

Instead of `#if defined(_LIBCPP_HAS_MUSL_LIBC)`, we can rely on
`#if _LIBCPP_HAS_MUSL_LIBC` directly.

This should address these failures:

	  # .---command stdout------------
	  # | /__w/llvm-project/llvm-project/build/frozen-cxx03-headers/libcxx/test-suite-install/include/c++/v1/__locale_dir/support/linux.h:98:6: error: '_LIBCPP_HAS_MUSL_LIBC' is always defined to 1 or 0. [libcpp-internal-ftms,-warnings-as-errors]
	  # |    98 | #if !defined(_LIBCPP_HAS_MUSL_LIBC)
	  # |       |      ^
	  # | /__w/llvm-project/llvm-project/build/frozen-cxx03-headers/libcxx/test-suite-install/include/c++/v1/__locale_dir/support/linux.h:108:6: error: '_LIBCPP_HAS_MUSL_LIBC' is always defined to 1 or 0. [libcpp-internal-ftms,-warnings-as-errors]
	  # |   108 | #if !defined(_LIBCPP_HAS_MUSL_LIBC)
	  # |       |      ^
	  # `-----------------------------
@androm3da
Copy link
Member Author

This can be landed as soon as the CI is green. If someone lands this before I do, please edit the commit message to avoid butchering git log.

Thanks for the fix @androm3da

Note that this fix was actually proposed by @pirama-arumuga-nainar.

Even though @pirama-arumuga-nainar is the author of the first commit in this PR I think GH will take my name as the author when it's merged. So I'll add a Co-authored-by to the message if that's satisfactory @pirama-arumuga-nainar

@androm3da
Copy link
Member Author

please edit the commit message to avoid butchering git log.

Will GH catenate the commit messages in the squash-and-merge? In which case I'm happy to edit it so that it reflects the original commit message in the first commit. Is that what you meant, or what butchering specifically should I try to avoid?

@androm3da
Copy link
Member Author

LGTM, thanks for the fix and sorry for the slow reaction time.

Do you know if this means we can actually get rid of this code path in locale_base_api.h?

#  elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
#    include <__locale_dir/locale_base_api/musl.h>

This change shouldn't impact __wasi__ targets. Should we include __wasi__ in these changes to __strtoll(), __strtoull()?

@pirama-arumuga-nainar
Copy link
Collaborator

LGTM, thanks for the fix and sorry for the slow reaction time.
Do you know if this means we can actually get rid of this code path in locale_base_api.h?

#  elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC
#    include <__locale_dir/locale_base_api/musl.h>

This change shouldn't impact __wasi__ targets. Should we include __wasi__ in these changes to __strtoll(), __strtoull()?

The separate definitions are still needed for wasi - it's not a Linux environment. . We could rename the file to wasi.h to make this explicit.

So I'll add a Co-authored-by to the message if that's satisfactory @pirama-arumuga-nainar

Thanks for the credit, but no need to go out of the way for this. I'm happy to just have the breakage fixed.

@androm3da
Copy link
Member Author

I'll rebase this after #128950 lands to see if that addresses the CI issues.

@philnik777
Copy link
Contributor

Ironically, #121795 will get rid of this code anyways...

@ldionne
Copy link
Member

ldionne commented Feb 28, 2025

Let's not wait to merge this. The FreeBSD failure is a fluke that will be fixed by #128950.

As for #121795, it can remove that code when it lands, but let's get main out of a broken state.

@ldionne ldionne merged commit 39c6c8b into llvm:main Feb 28, 2025
81 of 85 checks passed
@philnik777
Copy link
Contributor

Let's not wait to merge this. The FreeBSD failure is a fluke that will be fixed by #128950.

As for #121795, it can remove that code when it lands, but let's get main out of a broken state.

Just to be clear: I didn't mean that #121795 should block this. I found it just ironic that if I landed the patch a bit earlier this never would have happened.

cheezeburglar pushed a commit to cheezeburglar/llvm-project that referenced this pull request Feb 28, 2025
Since `363bfd6090b0 ([libc++] Use the new locale base API on Linux
(llvm#128007), 2025-02-24)`, musl targets will fail to build with errors
due to missing strtoll_l functions.

Co-authored-by: Pirama Arumuga Nainar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. pending-ci Merging the PR is only pending completion of CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants